[Bleeding] Account for new rare drops in EntityDeath events. Fixes BUKKIT-1105

This commit is contained in:
zerg960
2012-03-20 20:55:45 -05:00
committed by EvilSeph
parent 1c95413f49
commit 96c4bb7da6
4 changed files with 77 additions and 34 deletions

View File

@@ -9,6 +9,7 @@ import java.util.Random;
// CraftBukkit start
import org.bukkit.craftbukkit.TrigMath;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
@@ -778,20 +779,18 @@ public abstract class EntityLiving extends Entity {
if (!this.isBaby()) {
this.dropDeathLoot(this.lastDamageByPlayerTime > 0, i);
if (this.lastDamageByPlayerTime > 0) {
int j = this.random.nextInt(200) - i;
if (j < 5) {
this.b(j <= 0 ? 1 : 0);
}
}
// CraftBukkit - move rare item drop call to dropDeathLoot
}
}
this.world.broadcastEntityEffect(this, (byte) 3);
}
protected void b(int i) {}
// CraftBukkit start - change return type to ItemStack
protected ItemStack b(int i) {
return null;
}
// CraftBukkit end
protected void dropDeathLoot(boolean flag, int i) {
int j = this.getLootId();
@@ -811,6 +810,18 @@ public abstract class EntityLiving extends Entity {
}
}
// Determine rare item drops and add them to the loot
if (this.lastDamageByPlayerTime > 0) {
int k = this.random.nextInt(200) - i;
if (k < 5) {
ItemStack itemstack = this.b(k <= 0 ? 1 : 0);
if (itemstack != null) {
loot.add(new CraftItemStack(itemstack));
}
}
}
CraftEventFactory.callEntityDeathEvent(this, loot); // raise event even for those times when the entity does not drop loot
// CraftBukkit end
}