From 3b15da52dbdcb121e59e0938e1491ea1c847d1c7 Mon Sep 17 00:00:00 2001 From: kashike Date: Sat, 19 Mar 2016 09:57:19 -0700 Subject: [PATCH] Custom replacement for eaten items --- ...6-Custom-replacement-for-eaten-items.patch | 46 +++++++++++++++++++ ...7-Custom-replacement-for-eaten-items.patch | 39 ++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Spigot-API-Patches/0026-Custom-replacement-for-eaten-items.patch create mode 100644 Spigot-Server-Patches/0097-Custom-replacement-for-eaten-items.patch diff --git a/Spigot-API-Patches/0026-Custom-replacement-for-eaten-items.patch b/Spigot-API-Patches/0026-Custom-replacement-for-eaten-items.patch new file mode 100644 index 0000000000..71f773aee6 --- /dev/null +++ b/Spigot-API-Patches/0026-Custom-replacement-for-eaten-items.patch @@ -0,0 +1,46 @@ +From cfcfc4e550f7445c1817d2c8c1fd1c7f55708cd5 Mon Sep 17 00:00:00 2001 +From: Jedediah Smith +Date: Sun, 21 Jun 2015 15:05:21 -0400 +Subject: [PATCH] Custom replacement for eaten items + + +diff --git a/src/main/java/org/bukkit/event/player/PlayerItemConsumeEvent.java b/src/main/java/org/bukkit/event/player/PlayerItemConsumeEvent.java +index 8ab76b1..42aad88 100644 +--- a/src/main/java/org/bukkit/event/player/PlayerItemConsumeEvent.java ++++ b/src/main/java/org/bukkit/event/player/PlayerItemConsumeEvent.java +@@ -20,6 +20,7 @@ public class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean isCancelled = false; + private ItemStack item; ++ private ItemStack replacement; // Paper + + /** + * @param player the player consuming +@@ -55,6 +56,24 @@ public class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable { + } + } + ++ // Paper start ++ /** ++ * Return the custom item stack that will replace the consumed item, or null if no ++ * custom replacement has been set (which means the default replacement will be used). ++ */ ++ public ItemStack getReplacement() { ++ return this.replacement; ++ } ++ ++ /** ++ * Set a custom item stack to replace the consumed item. Pass null to clear any custom ++ * stack that has been set and use the default replacement. ++ */ ++ public void setReplacement(ItemStack replacement) { ++ this.replacement = replacement; ++ } ++ // Paper end ++ + public boolean isCancelled() { + return this.isCancelled; + } +-- +2.7.2 + diff --git a/Spigot-Server-Patches/0097-Custom-replacement-for-eaten-items.patch b/Spigot-Server-Patches/0097-Custom-replacement-for-eaten-items.patch new file mode 100644 index 0000000000..a60c831fbb --- /dev/null +++ b/Spigot-Server-Patches/0097-Custom-replacement-for-eaten-items.patch @@ -0,0 +1,39 @@ +From 1e28f461809ca1edf8b1477f6d1ed15cc277c07f Mon Sep 17 00:00:00 2001 +From: Jedediah Smith +Date: Sun, 21 Jun 2015 15:07:20 -0400 +Subject: [PATCH] Custom replacement for eaten items + + +diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java +index 34abdd4..1f2a8ee 100644 +--- a/src/main/java/net/minecraft/server/EntityLiving.java ++++ b/src/main/java/net/minecraft/server/EntityLiving.java +@@ -2214,12 +2214,25 @@ public abstract class EntityLiving extends Entity { + ItemStack itemstack = (craftItem.equals(event.getItem())) ? this.bm.a(this.world, this) : CraftItemStack.asNMSCopy(event.getItem()).a(world, this); + // CraftBukkit end + ++ // Paper start - save the default replacement item and change it if necessary ++ final ItemStack defaultReplacement = itemstack; ++ if (event.getReplacement() != null) { ++ itemstack = CraftItemStack.asNMSCopy(event.getReplacement()); ++ } ++ // Paper end ++ + if (itemstack != null && itemstack.count == 0) { + itemstack = null; + } + + this.a(this.ct(), itemstack); + this.cz(); ++ ++ // Paper start - if the replacement is anything but the default, update the client inventory ++ if (this instanceof EntityPlayer && !com.google.common.base.Objects.equal(defaultReplacement, itemstack)) { ++ ((EntityPlayer) this).getBukkitEntity().updateInventory(); ++ } ++ // Paper end + } + + } +-- +2.7.2 +