| 1 | package net.minecraft.entity.ai;
|
| 2 |
|
| 3 | import net.minecraft.entity.EntityLiving;
|
| 4 | import net.minecraft.entity.EntityLivingBase;
|
| 5 | import net.minecraft.world.World;
|
| 6 |
|
| 7 | public class EntityAIOcelotAttack extends EntityAIBase
|
| 8 | {
|
| 9 | World theWorld;
|
| 10 | EntityLiving theEntity;
|
| 11 | EntityLivingBase theVictim;
|
| 12 | int attackCountdown;
|
| 13 |
|
| 14 | public EntityAIOcelotAttack(EntityLiving theEntityIn)
|
| 15 | {
|
| 16 | this.theEntity = theEntityIn;
|
| 17 | this.theWorld = theEntityIn.worldObj;
|
| 18 | this.setMutexBits(3);
|
| 19 | }
|
| 20 |
|
| 21 | /**
|
| 22 | * Returns whether the EntityAIBase should begin execution.
|
| 23 | */
|
| 24 | public boolean shouldExecute()
|
| 25 | {
|
| 26 | EntityLivingBase entitylivingbase = this.theEntity.getAttackTarget();
|
| 27 |
|
| 28 | if (entitylivingbase == null)
|
| 29 | {
|
| 30 | return false;
|
| 31 | }
|
| 32 | else
|
| 33 | {
|
| 34 | this.theVictim = entitylivingbase;
|
| 35 | return true;
|
| 36 | }
|
| 37 | }
|
| 38 |
|
| 39 | /**
|
| 40 | * Returns whether an in-progress EntityAIBase should continue executing
|
| 41 | */
|
| 42 | public boolean continueExecuting()
|
| 43 | {
|
| 44 | return !this.theVictim.isEntityAlive() ? false : (this.theEntity.getDistanceSqToEntity(this.theVictim) > 225.0D ? false : !this.theEntity.getNavigator().noPath() || this.shouldExecute());
|
| 45 | }
|
| 46 |
|
| 47 | /**
|
| 48 | * Resets the task
|
| 49 | */
|
| 50 | public void resetTask()
|
| 51 | {
|
| 52 | this.theVictim = null;
|
| 53 | this.theEntity.getNavigator().clearPathEntity();
|
| 54 | }
|
| 55 |
|
| 56 | /**
|
| 57 | * Updates the task
|
| 58 | */
|
| 59 | public void updateTask()
|
| 60 | {
|
| 61 | this.theEntity.getLookHelper().setLookPositionWithEntity(this.theVictim, 30.0F, 30.0F);
|
| 62 | double d0 = (double)(this.theEntity.width * 2.0F * this.theEntity.width * 2.0F);
|
| 63 | double d1 = this.theEntity.getDistanceSq(this.theVictim.posX, this.theVictim.getEntityBoundingBox().minY, this.theVictim.posZ);
|
| 64 | double d2 = 0.8D;
|
| 65 |
|
| 66 | if (d1 > d0 && d1 < 16.0D)
|
| 67 | {
|
| 68 | d2 = 1.33D;
|
| 69 | }
|
| 70 | else if (d1 < 225.0D)
|
| 71 | {
|
| 72 | d2 = 0.6D;
|
| 73 | }
|
| 74 |
|
| 75 | this.theEntity.getNavigator().tryMoveToEntityLiving(this.theVictim, d2);
|
| 76 | this.attackCountdown = Math.max(this.attackCountdown - 1, 0);
|
| 77 |
|
| 78 | if (d1 <= d0)
|
| 79 | {
|
| 80 | if (this.attackCountdown <= 0)
|
| 81 | {
|
| 82 | this.attackCountdown = 20;
|
| 83 | this.theEntity.attackEntityAsMob(this.theVictim);
|
| 84 | }
|
| 85 | }
|
| 86 | }
|
| 87 | }
|
| 88 |
|