From c51c0f7fbb1157aa47c1b32a756ca568b581816f Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 1 Jun 2021 18:52:49 +1000 Subject: [PATCH] SPIGOT-6483: Fix cancelling EntityPickupEvent for villagers --- .../net/minecraft/world/InventorySubcontainer.patch | 7 ++++++- .../minecraft/world/entity/npc/EntityVillager.patch | 12 ++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/nms-patches/net/minecraft/world/InventorySubcontainer.patch b/nms-patches/net/minecraft/world/InventorySubcontainer.patch index 12d058b04..4e92b6527 100644 --- a/nms-patches/net/minecraft/world/InventorySubcontainer.patch +++ b/nms-patches/net/minecraft/world/InventorySubcontainer.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/InventorySubcontainer.java +++ b/net/minecraft/world/InventorySubcontainer.java -@@ -13,13 +13,64 @@ +@@ -13,13 +13,69 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -54,6 +54,11 @@ + public Location getLocation() { + return null; + } ++ ++ public InventorySubcontainer(InventorySubcontainer original) { ++ this.a = original.a; ++ this.items = NonNullList.a(ItemStack.b, original.items.toArray(ItemStack[]::new)); ++ } + public InventorySubcontainer(int i) { + this(i, null); diff --git a/nms-patches/net/minecraft/world/entity/npc/EntityVillager.patch b/nms-patches/net/minecraft/world/entity/npc/EntityVillager.patch index 87653bc4a..700a6ab90 100644 --- a/nms-patches/net/minecraft/world/entity/npc/EntityVillager.patch +++ b/nms-patches/net/minecraft/world/entity/npc/EntityVillager.patch @@ -90,24 +90,20 @@ this.fq(); this.die(); } else { -@@ -791,9 +811,16 @@ +@@ -791,6 +811,13 @@ return; } + // CraftBukkit start -+ ItemStack itemstack1 = inventorysubcontainer.a(itemstack); -+ if (CraftEventFactory.callEntityPickupItemEvent(this, entityitem, itemstack1.getCount(), false).isCancelled()) { ++ ItemStack remaining = new InventorySubcontainer(inventorysubcontainer).a(itemstack); ++ if (CraftEventFactory.callEntityPickupItemEvent(this, entityitem, remaining.getCount(), false).isCancelled()) { + return; + } + // CraftBukkit end + this.a(entityitem); this.receive(entityitem, itemstack.getCount()); -- ItemStack itemstack1 = inventorysubcontainer.a(itemstack); -+ // ItemStack itemstack1 = inventorysubcontainer.a(itemstack); // CraftBukkit - moved up - - if (itemstack1.isEmpty()) { - entityitem.die(); + ItemStack itemstack1 = inventorysubcontainer.a(itemstack); @@ -903,7 +930,7 @@ if (entityirongolem != null) {