From 14196c7d717dfbda0a2c85fafde04a02f69d870c Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Thu, 1 Mar 2012 22:57:30 -0500 Subject: [PATCH] Preserve data if possible when dropping Items from entities. Partial solution for BUKKIT-15 By: Tahg --- .../craftbukkit/event/CraftEventFactory.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 5c85f92c9d..abf81e09d2 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -288,7 +288,15 @@ public class CraftEventFactory { victim.expToDrop = event.getDroppedExp(); for (org.bukkit.inventory.ItemStack stack : event.getDrops()) { - world.dropItemNaturally(entity.getLocation(), stack); + if (stack == null || stack.getType() == Material.AIR) continue; + + if (stack instanceof CraftItemStack) { + // Use the internal item to preserve possible data. + victim.a(((CraftItemStack) stack).getHandle(), 0.0f); + } + else { + world.dropItemNaturally(entity.getLocation(), stack); + } } return event; @@ -310,7 +318,13 @@ public class CraftEventFactory { for (org.bukkit.inventory.ItemStack stack : event.getDrops()) { if (stack == null || stack.getType() == Material.AIR) continue; - world.dropItemNaturally(entity.getLocation(), stack); + if (stack instanceof CraftItemStack) { + // Use the internal item to preserve possible data. + victim.a(((CraftItemStack) stack).getHandle(), 0.0f); + } + else { + world.dropItemNaturally(entity.getLocation(), stack); + } } return event;