From 3f04f04be64f1724b1952e3b874697a104ec9094 Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Tue, 20 Sep 2011 20:40:22 -0400 Subject: [PATCH] Added/updated EntityDeathEvents to reflect changes to the Vanilla spec. --- .../net/minecraft/server/EntityChicken.java | 105 ++++++++++++++++++ .../java/net/minecraft/server/EntityCow.java | 34 ++++-- .../net/minecraft/server/EntityEnderman.java | 28 +++-- 3 files changed, 148 insertions(+), 19 deletions(-) create mode 100644 src/main/java/net/minecraft/server/EntityChicken.java diff --git a/src/main/java/net/minecraft/server/EntityChicken.java b/src/main/java/net/minecraft/server/EntityChicken.java new file mode 100644 index 0000000000..e8797157ea --- /dev/null +++ b/src/main/java/net/minecraft/server/EntityChicken.java @@ -0,0 +1,105 @@ +package net.minecraft.server; + +// CraftBukkit start +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.craftbukkit.entity.CraftEntity; +import org.bukkit.event.entity.EntityDeathEvent; +// CraftBukkit end + +public class EntityChicken extends EntityAnimal { + + public boolean a = false; + public float b = 0.0F; + public float c = 0.0F; + public float g; + public float h; + public float i = 1.0F; + public int j; + + public EntityChicken(World world) { + super(world); + this.texture = "/mob/chicken.png"; + this.b(0.3F, 0.7F); + this.health = 4; + this.j = this.random.nextInt(6000) + 6000; + } + + public void s() { + super.s(); + this.h = this.b; + this.g = this.c; + this.c = (float) ((double) this.c + (double) (this.onGround ? -1 : 4) * 0.3D); + if (this.c < 0.0F) { + this.c = 0.0F; + } + + if (this.c > 1.0F) { + this.c = 1.0F; + } + + if (!this.onGround && this.i < 1.0F) { + this.i = 1.0F; + } + + this.i = (float) ((double) this.i * 0.9D); + if (!this.onGround && this.motY < 0.0D) { + this.motY *= 0.6D; + } + + this.b += this.i * 2.0F; + if (!this.world.isStatic && --this.j <= 0) { + this.world.makeSound(this, "mob.chickenplop", 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); + this.b(Item.EGG.id, 1); + this.j = this.random.nextInt(6000) + 6000; + } + } + + protected void a(float f) {} + + public void b(NBTTagCompound nbttagcompound) { + super.b(nbttagcompound); + } + + public void a(NBTTagCompound nbttagcompound) { + super.a(nbttagcompound); + } + + protected String h() { + return "mob.chicken"; + } + + protected String i() { + return "mob.chickenhurt"; + } + + protected String j() { + return "mob.chickenhurt"; + } + + protected int k() { + return Item.FEATHER.id; + } + + protected void a(boolean flag) { + // CraftBukkit start - whole method + List loot = new java.util.ArrayList(); + int count = this.random.nextInt(3); + + if (count > 0) { + loot.add(new org.bukkit.inventory.ItemStack(Item.FEATHER.id, count)); + loot.add(new org.bukkit.inventory.ItemStack(this.fireTicks > 0 ? Item.COOKED_CHICKEN.id : Item.RAW_CHICKEN.id, 1)); + } + + CraftEntity entity = (CraftEntity) this.getBukkitEntity(); + EntityDeathEvent event = new EntityDeathEvent(entity, loot); + org.bukkit.World bworld = this.world.getWorld(); + this.world.getServer().getPluginManager().callEvent(event); + + for (org.bukkit.inventory.ItemStack stack: event.getDrops()) { + bworld.dropItemNaturally(entity.getLocation(), stack); + } + // CraftBukkit end + } +} diff --git a/src/main/java/net/minecraft/server/EntityCow.java b/src/main/java/net/minecraft/server/EntityCow.java index 772c8fb16f..84cc8e5909 100644 --- a/src/main/java/net/minecraft/server/EntityCow.java +++ b/src/main/java/net/minecraft/server/EntityCow.java @@ -1,9 +1,13 @@ package net.minecraft.server; // CraftBukkit start +import java.util.List; + import org.bukkit.Location; +import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.player.PlayerBucketFillEvent; // CraftBukkit end @@ -44,23 +48,29 @@ public class EntityCow extends EntityAnimal { } protected void a(boolean flag) { - int i = this.random.nextInt(3); + // CraftBukkit start - whole method + List loot = new java.util.ArrayList(); + int count = this.random.nextInt(3); - int j; - - for (j = 0; j < i; ++j) { - this.b(Item.LEATHER.id, 1); + if (count > 0) { + loot.add(new org.bukkit.inventory.ItemStack(Item.LEATHER.id, count)); } - i = this.random.nextInt(3) + 1; + count = this.random.nextInt(3) + 1; - for (j = 0; j < i; ++j) { - if (this.fireTicks > 0) { - this.b(Item.COOKED_BEEF.id, 1); - } else { - this.b(Item.RAW_BEEF.id, 1); - } + if (count > 0) { + loot.add(new org.bukkit.inventory.ItemStack(this.fireTicks > 0 ? Item.COOKED_BEEF.id : Item.RAW_BEEF.id, count)); } + + CraftEntity entity = (CraftEntity) this.getBukkitEntity(); + EntityDeathEvent event = new EntityDeathEvent(entity, loot); + org.bukkit.World bworld = this.world.getWorld(); + this.world.getServer().getPluginManager().callEvent(event); + + for (org.bukkit.inventory.ItemStack stack: event.getDrops()) { + bworld.dropItemNaturally(entity.getLocation(), stack); + } + // CraftBukkit end } public boolean b(EntityHuman entityhuman) { diff --git a/src/main/java/net/minecraft/server/EntityEnderman.java b/src/main/java/net/minecraft/server/EntityEnderman.java index 7258620378..75417bae3f 100644 --- a/src/main/java/net/minecraft/server/EntityEnderman.java +++ b/src/main/java/net/minecraft/server/EntityEnderman.java @@ -1,10 +1,14 @@ package net.minecraft.server; -// Craftbukkit start +// CraftBukkit start +import java.util.List; + import org.bukkit.Location; +import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.event.entity.EndermanPickupEvent; import org.bukkit.event.entity.EndermanPlaceEvent; -// Craftbukkit end +import org.bukkit.event.entity.EntityDeathEvent; +// CraftBukkit end public class EntityEnderman extends EntityMonster { @@ -264,13 +268,23 @@ public class EntityEnderman extends EntityMonster { protected void a(boolean flag) { int i = this.k(); - if (i > 0) { - int j = this.random.nextInt(2); + // CraftBukkit start - whole method + List loot = new java.util.ArrayList(); + int count = this.random.nextInt(2); - for (int k = 0; k < j; ++k) { - this.b(i, 1); - } + if ((i > 0) && (count > 0)) { + loot.add(new org.bukkit.inventory.ItemStack(i, count)); } + + CraftEntity entity = (CraftEntity) this.getBukkitEntity(); + EntityDeathEvent event = new EntityDeathEvent(entity, loot); + org.bukkit.World bworld = this.world.getWorld(); + this.world.getServer().getPluginManager().callEvent(event); + + for (org.bukkit.inventory.ItemStack stack: event.getDrops()) { + bworld.dropItemNaturally(entity.getLocation(), stack); + } + // CraftBukkit end } public void setCarriedId(int i) {