Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.turtledove.necropolisofnostalgia.server.ai;
- import com.google.common.base.Predicates;
- import net.minecraft.entity.EntityLiving;
- import net.minecraft.entity.ai.EntityAIBase;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityCreature;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.pathfinding.Path;
- import net.minecraft.util.EntitySelectors;
- import net.minecraft.util.math.MathHelper;
- public class Spiral_DracoChargeTargetAI extends EntityAIBase
- {
- protected EntityLiving entity;
- protected Class <? extends Entity > targetEntity;
- protected Entity closestEntity;
- private Path path;
- public boolean isCharging;
- protected float maxDistanceForPlayer;
- protected final double speed;
- protected double x;
- protected double y;
- protected double z;
- protected double overshoot = 2;
- protected int charge_ticks;
- protected int turn_tick;
- public Spiral_DracoChargeTargetAI(EntityCreature entity, Class<? extends Entity> targetClass, float maxDistance, float speed)
- {
- this.isCharging = false;
- this.entity = entity;
- this.targetEntity = targetClass;
- this.maxDistanceForPlayer = maxDistance;
- this.speed = speed;
- charge_ticks = 0;
- turn_tick = 0;
- this.setMutexBits(1);
- }
- @Override
- public boolean shouldExecute()
- {
- System.out.printf("%d\n",charge_ticks);
- if (this.targetEntity == EntityPlayer.class && this.charge_ticks >=100)
- {
- this.closestEntity = this.entity.world.getClosestPlayer(this.entity.posX, this.entity.posY, this.entity.posZ, (double)this.maxDistanceForPlayer, Predicates.and(EntitySelectors.CAN_AI_TARGET, EntitySelectors.notRiding(this.entity)));
- if (this.closestEntity != null)
- {
- x = this.closestEntity.posX;
- y = this.closestEntity.posY;
- z = this.closestEntity.posZ;
- double f = (double)MathHelper.sqrt(x * x + z * z);
- double unit_x = x / f;
- double unit_z = z / f;
- x += unit_x * overshoot;
- z += unit_z * overshoot;
- this.entity.getNavigator().tryMoveToXYZ(this.x, this.y, this.z, this.speed);
- }
- }
- ++charge_ticks;
- return this.closestEntity != null;
- }
- public boolean shouldContinueExecuting()
- {
- ++charge_ticks;
- if ((int)this.entity.posX == (int)this.x && (int)this.entity.posZ == (int)this.z)
- {
- charge_ticks = 0;
- turn_tick = 0;
- return false;
- }
- else
- {
- return true;
- }
- }
- public void resetTask()
- {
- this.closestEntity = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment