Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 344 lines 14 kB view raw
1package net.minecraft.server; 2 3import org.bukkit.entity.CreatureType; 4import org.bukkit.entity.Projectile; 5import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; 6import org.bukkit.event.entity.EntityDamageByEntityEvent; 7import org.bukkit.event.entity.EntityDamageEvent; 8import org.bukkit.event.entity.ProjectileHitEvent; 9import org.bukkit.event.player.PlayerEggThrowEvent; 10 11import java.util.List; 12 13// CraftBukkit start 14// CraftBukkit end 15 16public class EntityEgg extends Entity { 17 18 private int b = -1; 19 private int c = -1; 20 private int d = -1; 21 private int e = 0; 22 private boolean f = false; 23 public int a = 0; 24 public EntityLiving thrower; // CraftBukkit - private -> public 25 private int h; 26 private int i = 0; 27 28 public EntityEgg(World world) { 29 super(world); 30 this.b(0.25F, 0.25F); 31 } 32 33 protected void b() { 34 } 35 36 public EntityEgg(World world, EntityLiving entityliving) { 37 super(world); 38 this.thrower = entityliving; 39 this.b(0.25F, 0.25F); 40 this.setPositionRotation(entityliving.locX, entityliving.locY + (double) entityliving.t(), entityliving.locZ, entityliving.yaw, entityliving.pitch); 41 this.locX -= (double) (MathHelper.cos(this.yaw / 180.0F * 3.1415927F) * 0.16F); 42 this.locY -= 0.10000000149011612D; 43 this.locZ -= (double) (MathHelper.sin(this.yaw / 180.0F * 3.1415927F) * 0.16F); 44 this.setPosition(this.locX, this.locY, this.locZ); 45 this.height = 0.0F; 46 float f = 0.4F; 47 48 this.motX = (double) (-MathHelper.sin(this.yaw / 180.0F * 3.1415927F) * MathHelper.cos(this.pitch / 180.0F * 3.1415927F) * f); 49 this.motZ = (double) (MathHelper.cos(this.yaw / 180.0F * 3.1415927F) * MathHelper.cos(this.pitch / 180.0F * 3.1415927F) * f); 50 this.motY = (double) (-MathHelper.sin(this.pitch / 180.0F * 3.1415927F) * f); 51 this.a(this.motX, this.motY, this.motZ, 1.5F, 1.0F); 52 } 53 54 public EntityEgg(World world, double d0, double d1, double d2) { 55 super(world); 56 this.h = 0; 57 this.b(0.25F, 0.25F); 58 this.setPosition(d0, d1, d2); 59 this.height = 0.0F; 60 } 61 62 public void a(double d0, double d1, double d2, float f, float f1) { 63 float f2 = MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2); 64 65 d0 /= (double) f2; 66 d1 /= (double) f2; 67 d2 /= (double) f2; 68 d0 += this.random.nextGaussian() * 0.007499999832361937D * (double) f1; 69 d1 += this.random.nextGaussian() * 0.007499999832361937D * (double) f1; 70 d2 += this.random.nextGaussian() * 0.007499999832361937D * (double) f1; 71 d0 *= (double) f; 72 d1 *= (double) f; 73 d2 *= (double) f; 74 this.motX = d0; 75 this.motY = d1; 76 this.motZ = d2; 77 float f3 = MathHelper.a(d0 * d0 + d2 * d2); 78 79 this.lastYaw = this.yaw = (float) (Math.atan2(d0, d2) * 180.0D / 3.1415927410125732D); 80 this.lastPitch = this.pitch = (float) (Math.atan2(d1, (double) f3) * 180.0D / 3.1415927410125732D); 81 this.h = 0; 82 } 83 84 public void m_() { 85 this.bo = this.locX; 86 this.bp = this.locY; 87 this.bq = this.locZ; 88 super.m_(); 89 if (this.a > 0) { 90 --this.a; 91 } 92 93 if (this.f) { 94 int i = this.world.getTypeId(this.b, this.c, this.d); 95 96 if (i == this.e) { 97 ++this.h; 98 if (this.h == 1200) { 99 this.die(); 100 } 101 102 return; 103 } 104 105 this.f = false; 106 this.motX *= (double) (this.random.nextFloat() * 0.2F); 107 this.motY *= (double) (this.random.nextFloat() * 0.2F); 108 this.motZ *= (double) (this.random.nextFloat() * 0.2F); 109 this.h = 0; 110 this.i = 0; 111 } else { 112 ++this.i; 113 } 114 115 Vec3D vec3d = Vec3D.create(this.locX, this.locY, this.locZ); 116 Vec3D vec3d1 = Vec3D.create(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ); 117 MovingObjectPosition movingobjectposition = this.world.a(vec3d, vec3d1); 118 119 vec3d = Vec3D.create(this.locX, this.locY, this.locZ); 120 vec3d1 = Vec3D.create(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ); 121 if (movingobjectposition != null) { 122 vec3d1 = Vec3D.create(movingobjectposition.f.a, movingobjectposition.f.b, movingobjectposition.f.c); 123 } 124 125 if (!this.world.isStatic) { 126 Entity entity = null; 127 List list = this.world.b((Entity) this, this.boundingBox.a(this.motX, this.motY, this.motZ).b(1.0D, 1.0D, 1.0D)); 128 double d0 = 0.0D; 129 130 for (int j = 0; j < list.size(); ++j) { 131 Entity entity1 = (Entity) list.get(j); 132 133 if (entity1.l_() && (entity1 != this.thrower || this.i >= 5)) { 134 float f = 0.3F; 135 AxisAlignedBB axisalignedbb = entity1.boundingBox.b((double) f, (double) f, (double) f); 136 MovingObjectPosition movingobjectposition1 = axisalignedbb.a(vec3d, vec3d1); 137 138 if (movingobjectposition1 != null) { 139 double d1 = vec3d.a(movingobjectposition1.f); 140 141 if (d1 < d0 || d0 == 0.0D) { 142 entity = entity1; 143 d0 = d1; 144 } 145 } 146 } 147 } 148 149 if (entity != null) { 150 movingobjectposition = new MovingObjectPosition(entity); 151 } 152 } 153 154 if (movingobjectposition != null) { 155 // CraftBukkit start 156 ProjectileHitEvent phe = new ProjectileHitEvent((Projectile) this.getBukkitEntity()); 157 this.world.getServer().getPluginManager().callEvent(phe); 158 159 if (movingobjectposition.entity != null) { 160 boolean stick; 161 if (movingobjectposition.entity instanceof EntityLiving) { 162 org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity(); 163 Projectile projectile = (Projectile) this.getBukkitEntity(); 164 165 // TODO @see EntityArrow#162 166 EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 0); 167 this.world.getServer().getPluginManager().callEvent(event); 168 169 if (event.isCancelled()) { 170 stick = !projectile.doesBounce(); 171 } else { 172 // this function returns if the egg should stick in or not, i.e. !bounce 173 stick = movingobjectposition.entity.damageEntity(this, event.getDamage()); 174 } 175 } else { 176 stick = movingobjectposition.entity.damageEntity(this.thrower, 0); 177 } 178 179 if (stick) { 180 ; // Original code does nothing *yet* 181 } 182 } 183 184 boolean hatching = !this.world.isStatic && this.random.nextInt(8) == 0; 185 int numHatching = (this.random.nextInt(32) == 0) ? 4 : 1; 186 if (!hatching) { 187 numHatching = 0; 188 } 189 190 CreatureType hatchingType = CreatureType.CHICKEN; 191 192 if (this.thrower instanceof EntityPlayer) { 193 org.bukkit.entity.Player player = (this.thrower == null) ? null : (org.bukkit.entity.Player) this.thrower.getBukkitEntity(); 194 195 PlayerEggThrowEvent event = new PlayerEggThrowEvent(player, (org.bukkit.entity.Egg) this.getBukkitEntity(), hatching, (byte) numHatching, hatchingType); 196 this.world.getServer().getPluginManager().callEvent(event); 197 198 hatching = event.isHatching(); 199 numHatching = event.getNumHatches(); 200 hatchingType = event.getHatchType(); 201 } 202 203 if (hatching) { 204 for (int k = 0; k < numHatching; k++) { 205 Entity entity = null; 206 switch (hatchingType) { 207 case CHICKEN: 208 entity = new EntityChicken(this.world); 209 break; 210 case COW: 211 entity = new EntityCow(this.world); 212 break; 213 case CREEPER: 214 entity = new EntityCreeper(this.world); 215 break; 216 case GHAST: 217 entity = new EntityGhast(this.world); 218 break; 219 case GIANT: 220 entity = new EntityGiantZombie(this.world); 221 break; 222 case PIG: 223 entity = new EntityPig(this.world); 224 break; 225 case PIG_ZOMBIE: 226 entity = new EntityPigZombie(this.world); 227 break; 228 case SHEEP: 229 entity = new EntitySheep(this.world); 230 break; 231 case SKELETON: 232 entity = new EntitySkeleton(this.world); 233 break; 234 case SPIDER: 235 entity = new EntitySpider(this.world); 236 break; 237 case ZOMBIE: 238 entity = new EntityZombie(this.world); 239 break; 240 case SQUID: 241 entity = new EntitySquid(this.world); 242 break; 243 case SLIME: 244 entity = new EntitySlime(this.world); 245 break; 246 case WOLF: 247 entity = new EntityWolf(this.world); 248 break; 249 case MONSTER: 250 entity = new EntityMonster(this.world); 251 break; 252 default: 253 entity = new EntityChicken(this.world); 254 break; 255 } 256 257 // The world we're spawning in accepts this creature 258 boolean isAnimal = entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal; 259 if ((isAnimal && this.world.allowAnimals) || (!isAnimal && this.world.allowMonsters)) { 260 entity.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, 0.0F); 261 this.world.addEntity(entity, SpawnReason.EGG); 262 } 263 // CraftBukkit end 264 } 265 } 266 267 for (int l = 0; l < 8; ++l) { 268 this.world.a("snowballpoof", this.locX, this.locY, this.locZ, 0.0D, 0.0D, 0.0D); 269 } 270 271 this.die(); 272 } 273 274 this.locX += this.motX; 275 this.locY += this.motY; 276 this.locZ += this.motZ; 277 float f1 = MathHelper.a(this.motX * this.motX + this.motZ * this.motZ); 278 279 this.yaw = (float) (Math.atan2(this.motX, this.motZ) * 180.0D / 3.1415927410125732D); 280 281 for (this.pitch = (float) (Math.atan2(this.motY, (double) f1) * 180.0D / 3.1415927410125732D); this.pitch - this.lastPitch < -180.0F; this.lastPitch -= 360.0F) { 282 ; 283 } 284 285 while (this.pitch - this.lastPitch >= 180.0F) { 286 this.lastPitch += 360.0F; 287 } 288 289 while (this.yaw - this.lastYaw < -180.0F) { 290 this.lastYaw -= 360.0F; 291 } 292 293 while (this.yaw - this.lastYaw >= 180.0F) { 294 this.lastYaw += 360.0F; 295 } 296 297 this.pitch = this.lastPitch + (this.pitch - this.lastPitch) * 0.2F; 298 this.yaw = this.lastYaw + (this.yaw - this.lastYaw) * 0.2F; 299 float f2 = 0.99F; 300 float f3 = 0.03F; 301 302 if (this.ad()) { 303 for (int i1 = 0; i1 < 4; ++i1) { 304 float f4 = 0.25F; 305 306 this.world.a("bubble", this.locX - this.motX * (double) f4, this.locY - this.motY * (double) f4, this.locZ - this.motZ * (double) f4, this.motX, this.motY, this.motZ); 307 } 308 309 f2 = 0.8F; 310 } 311 312 this.motX *= (double) f2; 313 this.motY *= (double) f2; 314 this.motZ *= (double) f2; 315 this.motY -= (double) f3; 316 this.setPosition(this.locX, this.locY, this.locZ); 317 } 318 319 public void b(NBTTagCompound nbttagcompound) { 320 nbttagcompound.a("xTile", (short) this.b); 321 nbttagcompound.a("yTile", (short) this.c); 322 nbttagcompound.a("zTile", (short) this.d); 323 nbttagcompound.a("inTile", (byte) this.e); 324 nbttagcompound.a("shake", (byte) this.a); 325 nbttagcompound.a("inGround", (byte) (this.f ? 1 : 0)); 326 } 327 328 public void a(NBTTagCompound nbttagcompound) { 329 this.b = nbttagcompound.d("xTile"); 330 this.c = nbttagcompound.d("yTile"); 331 this.d = nbttagcompound.d("zTile"); 332 this.e = nbttagcompound.c("inTile") & 255; 333 this.a = nbttagcompound.c("shake") & 255; 334 this.f = nbttagcompound.c("inGround") == 1; 335 } 336 337 public void b(EntityHuman entityhuman) { 338 if (this.f && this.thrower == entityhuman && this.a <= 0 && entityhuman.inventory.pickup(new ItemStack(Item.ARROW, 1))) { 339 this.world.makeSound(this, "random.pop", 0.2F, ((this.random.nextFloat() - this.random.nextFloat()) * 0.7F + 1.0F) * 2.0F); 340 entityhuman.receive(this, 1); 341 this.die(); 342 } 343 } 344}