001 package net.minecraft.src; 002 003 public class EntityAIAttackOnCollide extends EntityAIBase 004 { 005 World worldObj; 006 EntityLiving attacker; 007 EntityLiving entityTarget; 008 009 /** 010 * An amount of decrementing ticks that allows the entity to attack once the tick reaches 0. 011 */ 012 int attackTick; 013 float field_75440_e; 014 boolean field_75437_f; 015 PathEntity field_75438_g; 016 Class classTarget; 017 private int field_75445_i; 018 019 public EntityAIAttackOnCollide(EntityLiving par1EntityLiving, Class par2Class, float par3, boolean par4) 020 { 021 this(par1EntityLiving, par3, par4); 022 this.classTarget = par2Class; 023 } 024 025 public EntityAIAttackOnCollide(EntityLiving par1EntityLiving, float par2, boolean par3) 026 { 027 this.attackTick = 0; 028 this.attacker = par1EntityLiving; 029 this.worldObj = par1EntityLiving.worldObj; 030 this.field_75440_e = par2; 031 this.field_75437_f = par3; 032 this.setMutexBits(3); 033 } 034 035 /** 036 * Returns whether the EntityAIBase should begin execution. 037 */ 038 public boolean shouldExecute() 039 { 040 EntityLiving var1 = this.attacker.getAttackTarget(); 041 042 if (var1 == null) 043 { 044 return false; 045 } 046 else if (this.classTarget != null && !this.classTarget.isAssignableFrom(var1.getClass())) 047 { 048 return false; 049 } 050 else 051 { 052 this.entityTarget = var1; 053 this.field_75438_g = this.attacker.getNavigator().getPathToEntityLiving(this.entityTarget); 054 return this.field_75438_g != null; 055 } 056 } 057 058 /** 059 * Returns whether an in-progress EntityAIBase should continue executing 060 */ 061 public boolean continueExecuting() 062 { 063 EntityLiving var1 = this.attacker.getAttackTarget(); 064 return var1 == null ? false : (!this.entityTarget.isEntityAlive() ? false : (!this.field_75437_f ? !this.attacker.getNavigator().noPath() : this.attacker.isWithinHomeDistance(MathHelper.floor_double(this.entityTarget.posX), MathHelper.floor_double(this.entityTarget.posY), MathHelper.floor_double(this.entityTarget.posZ)))); 065 } 066 067 /** 068 * Execute a one shot task or start executing a continuous task 069 */ 070 public void startExecuting() 071 { 072 this.attacker.getNavigator().setPath(this.field_75438_g, this.field_75440_e); 073 this.field_75445_i = 0; 074 } 075 076 /** 077 * Resets the task 078 */ 079 public void resetTask() 080 { 081 this.entityTarget = null; 082 this.attacker.getNavigator().clearPathEntity(); 083 } 084 085 /** 086 * Updates the task 087 */ 088 public void updateTask() 089 { 090 this.attacker.getLookHelper().setLookPositionWithEntity(this.entityTarget, 30.0F, 30.0F); 091 092 if ((this.field_75437_f || this.attacker.getEntitySenses().canSee(this.entityTarget)) && --this.field_75445_i <= 0) 093 { 094 this.field_75445_i = 4 + this.attacker.getRNG().nextInt(7); 095 this.attacker.getNavigator().tryMoveToEntityLiving(this.entityTarget, this.field_75440_e); 096 } 097 098 this.attackTick = Math.max(this.attackTick - 1, 0); 099 double var1 = (double)(this.attacker.width * 2.0F * this.attacker.width * 2.0F); 100 101 if (this.attacker.getDistanceSq(this.entityTarget.posX, this.entityTarget.boundingBox.minY, this.entityTarget.posZ) <= var1) 102 { 103 if (this.attackTick <= 0) 104 { 105 this.attackTick = 20; 106 this.attacker.attackEntityAsMob(this.entityTarget); 107 } 108 } 109 } 110 }