| 1 | package net.minecraft.entity.ai;
|
| 2 |
|
| 3 | import net.minecraft.entity.EntityCreature;
|
| 4 | import net.minecraft.entity.EntityLivingBase;
|
| 5 | import net.minecraft.util.AxisAlignedBB;
|
| 6 |
|
| 7 | public class EntityAIHurtByTarget extends EntityAITarget
|
| 8 | {
|
| 9 | private boolean entityCallsForHelp;
|
| 10 |
|
| 11 | /** Store the previous revengeTimer value */
|
| 12 | private int revengeTimerOld;
|
| 13 | private final Class[] targetClasses;
|
| 14 |
|
| 15 | public EntityAIHurtByTarget(EntityCreature creatureIn, boolean entityCallsForHelpIn, Class... targetClassesIn)
|
| 16 | {
|
| 17 | super(creatureIn, false);
|
| 18 | this.entityCallsForHelp = entityCallsForHelpIn;
|
| 19 | this.targetClasses = targetClassesIn;
|
| 20 | this.setMutexBits(1);
|
| 21 | }
|
| 22 |
|
| 23 | /**
|
| 24 | * Returns whether the EntityAIBase should begin execution.
|
| 25 | */
|
| 26 | public boolean shouldExecute()
|
| 27 | {
|
| 28 | int i = this.taskOwner.getRevengeTimer();
|
| 29 | return i != this.revengeTimerOld && this.isSuitableTarget(this.taskOwner.getAITarget(), false);
|
| 30 | }
|
| 31 |
|
| 32 | /**
|
| 33 | * Execute a one shot task or start executing a continuous task
|
| 34 | */
|
| 35 | public void startExecuting()
|
| 36 | {
|
| 37 | this.taskOwner.setAttackTarget(this.taskOwner.getAITarget());
|
| 38 | this.revengeTimerOld = this.taskOwner.getRevengeTimer();
|
| 39 |
|
| 40 | if (this.entityCallsForHelp)
|
| 41 | {
|
| 42 | double d0 = this.getTargetDistance();
|
| 43 |
|
| 44 | for (EntityCreature entitycreature : this.taskOwner.worldObj.getEntitiesWithinAABB(this.taskOwner.getClass(), (new AxisAlignedBB(this.taskOwner.posX, this.taskOwner.posY, this.taskOwner.posZ, this.taskOwner.posX + 1.0D, this.taskOwner.posY + 1.0D, this.taskOwner.posZ + 1.0D)).expand(d0, 10.0D, d0)))
|
| 45 | {
|
| 46 | if (this.taskOwner != entitycreature && entitycreature.getAttackTarget() == null && !entitycreature.isOnSameTeam(this.taskOwner.getAITarget()))
|
| 47 | {
|
| 48 | boolean flag = false;
|
| 49 |
|
| 50 | for (Class oclass : this.targetClasses)
|
| 51 | {
|
| 52 | if (entitycreature.getClass() == oclass)
|
| 53 | {
|
| 54 | flag = true;
|
| 55 | break;
|
| 56 | }
|
| 57 | }
|
| 58 |
|
| 59 | if (!flag)
|
| 60 | {
|
| 61 | this.setEntityAttackTarget(entitycreature, this.taskOwner.getAITarget());
|
| 62 | }
|
| 63 | }
|
| 64 | }
|
| 65 | }
|
| 66 |
|
| 67 | super.startExecuting();
|
| 68 | }
|
| 69 |
|
| 70 | protected void setEntityAttackTarget(EntityCreature creatureIn, EntityLivingBase entityLivingBaseIn)
|
| 71 | {
|
| 72 | creatureIn.setAttackTarget(entityLivingBaseIn);
|
| 73 | }
|
| 74 | }
|
| 75 |
|