Rework mob item dropping on death. Fixes BUKKIT-5625

After the changes in d611cff2 we started including a mob's equipment when
calling EntityDeathEvent so plugins can access this data. However, the
changes to enable this triggered a bug that makes skeletons and pig zombies
no longer drop equipment because they handle this differently than the rest.
On top of this we don't handle dropping equipment for mobs that cannot
pick up items in vanilla even though vanilla does drop equipment for them
if you summon them with it. We also do not include a horse's inventory
in the event so they drop their saddle, armor, chest, and chest contents
with no way for a plugin to control this.

To solve this issues we revert mob item dropping back to vanilla logic
and instead just capture all their drops in the method they all call to
spawn them into the world. We also move horse inventory dropping so it
happens at a time when we're capturing these drops. With these changes
all items mobs drop on death should now be included in the event and
we have less diff to worry about for future updates.
This commit is contained in:
Travis Watkins
2014-05-26 02:17:53 -05:00
parent 4ab4fa5bb1
commit e080bafa58
23 changed files with 120 additions and 689 deletions

View File

@@ -8,6 +8,7 @@ import java.util.Random;
import java.util.UUID;
// CraftBukkit start
import java.util.ArrayList;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
@@ -77,6 +78,7 @@ public abstract class EntityLiving extends Entity {
// CraftBukkit start
public int expToDrop;
public int maxAirTicks = 300;
ArrayList<org.bukkit.inventory.ItemStack> drops = null;
// CraftBukkit end
public EntityLiving(World world) {
@@ -781,28 +783,31 @@ public abstract class EntityLiving extends Entity {
}
if (this.aF() && this.world.getGameRules().getBoolean("doMobLoot")) {
this.drops = new ArrayList<org.bukkit.inventory.ItemStack>(); // CraftBukkit - Setup drop capture
this.dropDeathLoot(this.lastDamageByPlayerTime > 0, i);
this.dropEquipment(this.lastDamageByPlayerTime > 0, i);
if (false && this.lastDamageByPlayerTime > 0) { // CraftBukkit - move rare item drop call to dropDeathLoot
if (this.lastDamageByPlayerTime > 0) {
int j = this.random.nextInt(200) - i;
if (j < 5) {
this.getRareDrop(j <= 0 ? 1 : 0);
}
}
} else { // CraftBukkit
CraftEventFactory.callEntityDeathEvent(this); // CraftBukkit
// CraftBukkit start - Call death event
CraftEventFactory.callEntityDeathEvent(this, this.drops);
this.drops = null;
} else {
CraftEventFactory.callEntityDeathEvent(this);
// CraftBukkit end
}
}
this.world.broadcastEntityEffect(this, (byte) 3);
}
// CraftBukkit start - return dropped equipment for EntityDeathEvent processing
protected ItemStack[] dropEquipment(boolean flag, int i) {
return new ItemStack[this.getEquipment().length];
}
// CraftBukkit end
protected void dropEquipment(boolean flag, int i) {}
public void a(Entity entity, float f, double d0, double d1) {
if (this.random.nextDouble() >= this.getAttributeInstance(GenericAttributes.c).getValue()) {
@@ -830,11 +835,7 @@ public abstract class EntityLiving extends Entity {
return "game.neutral.die";
}
// CraftBukkit start - Change return type to ItemStack
protected ItemStack getRareDrop(int i) {
return null;
}
// CraftBukkit end
protected void getRareDrop(int i) {}
protected void dropDeathLoot(boolean flag, int i) {}