| 1 | package net.minecraft.entity.ai;
|
| 2 |
|
| 3 | import net.minecraft.entity.EntityLiving;
|
| 4 | import net.minecraft.entity.EntityLivingBase;
|
| 5 | import net.minecraft.entity.IRangedAttackMob;
|
| 6 | import net.minecraft.util.MathHelper;
|
| 7 |
|
| 8 | public class EntityAIArrowAttack extends EntityAIBase
|
| 9 | {
|
| 10 | /** The entity the AI instance has been applied to */
|
| 11 | private final EntityLiving entityHost;
|
| 12 |
|
| 13 | /**
|
| 14 | * The entity (as a RangedAttackMob) the AI instance has been applied to.
|
| 15 | */
|
| 16 | private final IRangedAttackMob rangedAttackEntityHost;
|
| 17 | private EntityLivingBase attackTarget;
|
| 18 |
|
| 19 | /**
|
| 20 | * A decrementing tick that spawns a ranged attack once this value reaches 0. It is then set back to the
|
| 21 | * maxRangedAttackTime.
|
| 22 | */
|
| 23 | private int rangedAttackTime;
|
| 24 | private double entityMoveSpeed;
|
| 25 | private int field_75318_f;
|
| 26 | private int field_96561_g;
|
| 27 |
|
| 28 | /**
|
| 29 | * The maximum time the AI has to wait before peforming another ranged attack.
|
| 30 | */
|
| 31 | private int maxRangedAttackTime;
|
| 32 | private float field_96562_i;
|
| 33 | private float maxAttackDistance;
|
| 34 |
|
| 35 | public EntityAIArrowAttack(IRangedAttackMob attacker, double movespeed, int p_i1649_4_, float p_i1649_5_)
|
| 36 | {
|
| 37 | this(attacker, movespeed, p_i1649_4_, p_i1649_4_, p_i1649_5_);
|
| 38 | }
|
| 39 |
|
| 40 | public EntityAIArrowAttack(IRangedAttackMob attacker, double movespeed, int p_i1650_4_, int maxAttackTime, float maxAttackDistanceIn)
|
| 41 | {
|
| 42 | this.rangedAttackTime = -1;
|
| 43 |
|
| 44 | if (!(attacker instanceof EntityLivingBase))
|
| 45 | {
|
| 46 | throw new IllegalArgumentException("ArrowAttackGoal requires Mob implements RangedAttackMob");
|
| 47 | }
|
| 48 | else
|
| 49 | {
|
| 50 | this.rangedAttackEntityHost = attacker;
|
| 51 | this.entityHost = (EntityLiving)attacker;
|
| 52 | this.entityMoveSpeed = movespeed;
|
| 53 | this.field_96561_g = p_i1650_4_;
|
| 54 | this.maxRangedAttackTime = maxAttackTime;
|
| 55 | this.field_96562_i = maxAttackDistanceIn;
|
| 56 | this.maxAttackDistance = maxAttackDistanceIn * maxAttackDistanceIn;
|
| 57 | this.setMutexBits(3);
|
| 58 | }
|
| 59 | }
|
| 60 |
|
| 61 | /**
|
| 62 | * Returns whether the EntityAIBase should begin execution.
|
| 63 | */
|
| 64 | public boolean shouldExecute()
|
| 65 | {
|
| 66 | EntityLivingBase entitylivingbase = this.entityHost.getAttackTarget();
|
| 67 |
|
| 68 | if (entitylivingbase == null)
|
| 69 | {
|
| 70 | return false;
|
| 71 | }
|
| 72 | else
|
| 73 | {
|
| 74 | this.attackTarget = entitylivingbase;
|
| 75 | return true;
|
| 76 | }
|
| 77 | }
|
| 78 |
|
| 79 | /**
|
| 80 | * Returns whether an in-progress EntityAIBase should continue executing
|
| 81 | */
|
| 82 | public boolean continueExecuting()
|
| 83 | {
|
| 84 | return this.shouldExecute() || !this.entityHost.getNavigator().noPath();
|
| 85 | }
|
| 86 |
|
| 87 | /**
|
| 88 | * Resets the task
|
| 89 | */
|
| 90 | public void resetTask()
|
| 91 | {
|
| 92 | this.attackTarget = null;
|
| 93 | this.field_75318_f = 0;
|
| 94 | this.rangedAttackTime = -1;
|
| 95 | }
|
| 96 |
|
| 97 | /**
|
| 98 | * Updates the task
|
| 99 | */
|
| 100 | public void updateTask()
|
| 101 | {
|
| 102 | double d0 = this.entityHost.getDistanceSq(this.attackTarget.posX, this.attackTarget.getEntityBoundingBox().minY, this.attackTarget.posZ);
|
| 103 | boolean flag = this.entityHost.getEntitySenses().canSee(this.attackTarget);
|
| 104 |
|
| 105 | if (flag)
|
| 106 | {
|
| 107 | ++this.field_75318_f;
|
| 108 | }
|
| 109 | else
|
| 110 | {
|
| 111 | this.field_75318_f = 0;
|
| 112 | }
|
| 113 |
|
| 114 | if (d0 <= (double)this.maxAttackDistance && this.field_75318_f >= 20)
|
| 115 | {
|
| 116 | this.entityHost.getNavigator().clearPathEntity();
|
| 117 | }
|
| 118 | else
|
| 119 | {
|
| 120 | this.entityHost.getNavigator().tryMoveToEntityLiving(this.attackTarget, this.entityMoveSpeed);
|
| 121 | }
|
| 122 |
|
| 123 | this.entityHost.getLookHelper().setLookPositionWithEntity(this.attackTarget, 30.0F, 30.0F);
|
| 124 |
|
| 125 | if (--this.rangedAttackTime == 0)
|
| 126 | {
|
| 127 | if (d0 > (double)this.maxAttackDistance || !flag)
|
| 128 | {
|
| 129 | return;
|
| 130 | }
|
| 131 |
|
| 132 | float f = MathHelper.sqrt_double(d0) / this.field_96562_i;
|
| 133 | float lvt_5_1_ = MathHelper.clamp_float(f, 0.1F, 1.0F);
|
| 134 | this.rangedAttackEntityHost.attackEntityWithRangedAttack(this.attackTarget, lvt_5_1_);
|
| 135 | this.rangedAttackTime = MathHelper.floor_float(f * (float)(this.maxRangedAttackTime - this.field_96561_g) + (float)this.field_96561_g);
|
| 136 | }
|
| 137 | else if (this.rangedAttackTime < 0)
|
| 138 | {
|
| 139 | float f2 = MathHelper.sqrt_double(d0) / this.field_96562_i;
|
| 140 | this.rangedAttackTime = MathHelper.floor_float(f2 * (float)(this.maxRangedAttackTime - this.field_96561_g) + (float)this.field_96561_g);
|
| 141 | }
|
| 142 | }
|
| 143 | }
|
| 144 |
|