Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 219 lines 6.7 kB view raw
1package net.minecraft.server; 2 3// CraftBukkit start 4 5import org.bukkit.craftbukkit.TrigMath; 6import org.bukkit.craftbukkit.entity.CraftEntity; 7import org.bukkit.event.entity.EntityTargetEvent; 8// CraftBukkit end 9 10public class EntityCreature extends EntityLiving { 11 12 public PathEntity pathEntity; // CraftBukkit - public 13 public Entity target; // CraftBukkit - public 14 protected boolean e = false; 15 16 public EntityCreature(World world) { 17 super(world); 18 } 19 20 protected boolean w() { 21 return false; 22 } 23 24 protected void c_() { 25 this.e = this.w(); 26 float f = 16.0F; 27 28 if (this.target == null) { 29 // CraftBukkit start 30 Entity target = this.findTarget(); 31 if (target != null) { 32 EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), target.getBukkitEntity(), EntityTargetEvent.TargetReason.CLOSEST_PLAYER); 33 this.world.getServer().getPluginManager().callEvent(event); 34 35 if (!event.isCancelled()) { 36 if (event.getTarget() == null) { 37 this.target = null; 38 } else { 39 this.target = ((CraftEntity) event.getTarget()).getHandle(); 40 } 41 } 42 } 43 // CraftBukkit end 44 45 if (this.target != null) { 46 this.pathEntity = this.world.findPath(this, this.target, f); 47 } 48 } else if (!this.target.T()) { 49 // CraftBukkit start 50 EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), null, EntityTargetEvent.TargetReason.TARGET_DIED); 51 this.world.getServer().getPluginManager().callEvent(event); 52 53 if (!event.isCancelled()) { 54 if (event.getTarget() == null) { 55 this.target = null; 56 } else { 57 this.target = ((CraftEntity) event.getTarget()).getHandle(); 58 } 59 } 60 // CraftBukkit end 61 } else { 62 float f1 = this.target.f(this); 63 64 if (this.e(this.target)) { 65 this.a(this.target, f1); 66 } else { 67 this.b(this.target, f1); 68 } 69 } 70 71 if (!this.e && this.target != null && (this.pathEntity == null || this.random.nextInt(20) == 0)) { 72 this.pathEntity = this.world.findPath(this, this.target, f); 73 } else if (!this.e && (this.pathEntity == null && this.random.nextInt(80) == 0 || this.random.nextInt(80) == 0)) { 74 this.B(); 75 } 76 77 int i = MathHelper.floor(this.boundingBox.b + 0.5D); 78 boolean flag = this.ad(); 79 boolean flag1 = this.ae(); 80 81 this.pitch = 0.0F; 82 if (this.pathEntity != null && this.random.nextInt(100) != 0) { 83 Vec3D vec3d = this.pathEntity.a(this); 84 double d0 = (double) (this.length * 2.0F); 85 86 while (vec3d != null && vec3d.d(this.locX, vec3d.b, this.locZ) < d0 * d0) { 87 this.pathEntity.a(); 88 if (this.pathEntity.b()) { 89 vec3d = null; 90 this.pathEntity = null; 91 } else { 92 vec3d = this.pathEntity.a(this); 93 } 94 } 95 96 this.aC = false; 97 if (vec3d != null) { 98 double d1 = vec3d.a - this.locX; 99 double d2 = vec3d.c - this.locZ; 100 double d3 = vec3d.b - (double) i; 101 // CraftBukkit - Math -> TrigMath 102 float f2 = (float) (TrigMath.atan2(d2, d1) * 180.0D / 3.1415927410125732D) - 90.0F; 103 float f3 = f2 - this.yaw; 104 105 for (this.aA = this.aE; f3 < -180.0F; f3 += 360.0F) { 106 ; 107 } 108 109 while (f3 >= 180.0F) { 110 f3 -= 360.0F; 111 } 112 113 if (f3 > 30.0F) { 114 f3 = 30.0F; 115 } 116 117 if (f3 < -30.0F) { 118 f3 = -30.0F; 119 } 120 121 this.yaw += f3; 122 if (this.e && this.target != null) { 123 double d4 = this.target.locX - this.locX; 124 double d5 = this.target.locZ - this.locZ; 125 float f4 = this.yaw; 126 127 this.yaw = (float) (Math.atan2(d5, d4) * 180.0D / 3.1415927410125732D) - 90.0F; 128 f3 = (f4 - this.yaw + 90.0F) * 3.1415927F / 180.0F; 129 this.az = -MathHelper.sin(f3) * this.aA * 1.0F; 130 this.aA = MathHelper.cos(f3) * this.aA * 1.0F; 131 } 132 133 if (d3 > 0.0D) { 134 this.aC = true; 135 } 136 } 137 138 if (this.target != null) { 139 this.a(this.target, 30.0F, 30.0F); 140 } 141 142 if (this.positionChanged && !this.C()) { 143 this.aC = true; 144 } 145 146 if (this.random.nextFloat() < 0.8F && (flag || flag1)) { 147 this.aC = true; 148 } 149 } else { 150 super.c_(); 151 this.pathEntity = null; 152 } 153 } 154 155 protected void B() { 156 boolean flag = false; 157 int i = -1; 158 int j = -1; 159 int k = -1; 160 float f = -99999.0F; 161 162 for (int l = 0; l < 10; ++l) { 163 int i1 = MathHelper.floor(this.locX + (double) this.random.nextInt(13) - 6.0D); 164 int j1 = MathHelper.floor(this.locY + (double) this.random.nextInt(7) - 3.0D); 165 int k1 = MathHelper.floor(this.locZ + (double) this.random.nextInt(13) - 6.0D); 166 float f1 = this.a(i1, j1, k1); 167 168 if (f1 > f) { 169 f = f1; 170 i = i1; 171 j = j1; 172 k = k1; 173 flag = true; 174 } 175 } 176 177 if (flag) { 178 this.pathEntity = this.world.a(this, i, j, k, 10.0F); 179 } 180 } 181 182 protected void a(Entity entity, float f) { 183 } 184 185 protected void b(Entity entity, float f) { 186 } 187 188 protected float a(int i, int j, int k) { 189 return 0.0F; 190 } 191 192 protected Entity findTarget() { 193 return null; 194 } 195 196 public boolean d() { 197 int i = MathHelper.floor(this.locX); 198 int j = MathHelper.floor(this.boundingBox.b); 199 int k = MathHelper.floor(this.locZ); 200 201 return super.d() && this.a(i, j, k) >= 0.0F; 202 } 203 204 public boolean C() { 205 return this.pathEntity != null; 206 } 207 208 public void setPathEntity(PathEntity pathentity) { 209 this.pathEntity = pathentity; 210 } 211 212 public Entity F() { 213 return this.target; 214 } 215 216 public void setTarget(Entity entity) { 217 this.target = entity; 218 } 219}