From e89980bd38866c8a9e738615d98327a1cfa6a0bd Mon Sep 17 00:00:00 2001 From: Doc Date: Tue, 11 Oct 2022 22:19:46 -0300 Subject: [PATCH] Support for results of ItemStacks in CraftItemEvent --- ...-results-of-ItemStacks-in-CraftItemEvent.patch} | 14 +++++++------- ...-results-of-ItemStacks-in-CraftItemEvent.patch} | 9 ++++----- 2 files changed, 11 insertions(+), 12 deletions(-) rename patches/api/{0399-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch => 0400-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch} (78%) rename patches/server/{0925-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch => 0926-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch} (92%) diff --git a/patches/api/0399-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch b/patches/api/0400-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch similarity index 78% rename from patches/api/0399-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch rename to patches/api/0400-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch index b3af4155a4..5e66bb23e1 100644 --- a/patches/api/0399-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch +++ b/patches/api/0400-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch @@ -5,14 +5,14 @@ Subject: [PATCH] Support for results of ItemStacks in CraftItemEvent diff --git a/src/main/java/org/bukkit/event/inventory/CraftItemEvent.java b/src/main/java/org/bukkit/event/inventory/CraftItemEvent.java -index cab13877fb38c361f18ce9a433e98fea689c9722..fef15af229bced8cfe526800ffe0591eecc6e06c 100644 +index cab13877fb38c361f18ce9a433e98fea689c9722..87351dd3a122c5af7b85a48497eeadcebf88b8d1 100644 --- a/src/main/java/org/bukkit/event/inventory/CraftItemEvent.java +++ b/src/main/java/org/bukkit/event/inventory/CraftItemEvent.java @@ -11,6 +11,7 @@ import org.jetbrains.annotations.NotNull; */ public class CraftItemEvent extends InventoryClickEvent { private Recipe recipe; -+ private java.util.List itemResults; // Paper ++ private java.util.Collection itemResults; // Paper public CraftItemEvent(@NotNull Recipe recipe, @NotNull InventoryView what, @NotNull SlotType type, int slot, @NotNull ClickType click, @NotNull InventoryAction action) { super(what, type, slot, click, action); @@ -24,22 +24,22 @@ index cab13877fb38c361f18ce9a433e98fea689c9722..fef15af229bced8cfe526800ffe0591e + public CraftItemEvent(@NotNull Recipe recipe, @NotNull InventoryView what, @NotNull SlotType type, int slot, @NotNull ClickType click, @NotNull InventoryAction action, @NotNull java.util.List itemResults) { + super(what, type, slot, click, action); + this.recipe = recipe; -+ this.itemResults = itemResults; ++ this.itemResults = java.util.Collections.unmodifiableList(itemResults); + } + + public CraftItemEvent(@NotNull Recipe recipe, @NotNull InventoryView what, @NotNull SlotType type, int slot, @NotNull ClickType click, @NotNull InventoryAction action, int key, @NotNull java.util.List itemResults) { + super(what, type, slot, click, action, key); + this.recipe = recipe; -+ this.itemResults = itemResults; ++ this.itemResults = java.util.Collections.unmodifiableList(itemResults); + } + + /** -+ * @return A list of copies of the items result from the craft. ++ * @return An unmodifiable list of items resulting from the craft. + */ + @NotNull -+ public java.util.List getItemResults() { ++ public java.util.@org.jetbrains.annotations.Unmodifiable Collection getItemResults() { + if (this.itemResults == null) { -+ return java.util.Collections.singletonList(recipe.getResult().clone()); ++ return java.util.Collections.singletonList(recipe.getResult()); + } + return this.itemResults; + } diff --git a/patches/server/0925-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch b/patches/server/0926-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch similarity index 92% rename from patches/server/0925-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch rename to patches/server/0926-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch index 5628349ed2..c680ad6c63 100644 --- a/patches/server/0925-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch +++ b/patches/server/0926-Support-for-results-of-ItemStacks-in-CraftItemEvent.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Support for results of ItemStacks in CraftItemEvent diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index 63c9040ed2349eec500ba6e9090440347c514a3b..4e6ba6588872172d1255c559e712be2ecdd733c6 100644 +index 63c9040ed2349eec500ba6e9090440347c514a3b..807aa6bccbfa62e84202ba12b1c5ffd58c79e862 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -@@ -3280,12 +3280,33 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic +@@ -3280,12 +3280,32 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic org.bukkit.inventory.Inventory top = inventory.getTopInventory(); if (packet.getSlotNum() == 0 && top instanceof CraftingInventory) { org.bukkit.inventory.Recipe recipe = ((CraftingInventory) top).getRecipe(); @@ -21,14 +21,13 @@ index 63c9040ed2349eec500ba6e9090440347c514a3b..4e6ba6588872172d1255c559e712be2e + if (packet.getClickType() == net.minecraft.world.inventory.ClickType.QUICK_MOVE && action == InventoryAction.MOVE_TO_OTHER_INVENTORY) { + for (itemstack = this.player.containerMenu.quickMoveStack(this.player, packet.getSlotNum()); !itemstack.isEmpty() && ItemStack.isSame(this.player.containerMenu.slots.get(packet.getSlotNum()).getItem(), itemstack); itemstack = this.player.containerMenu.quickMoveStack(player, packet.getSlotNum())) { + if (this.player.containerMenu.slots.get(packet.getSlotNum()).mayPickup(this.player) && (this.player.getInventory().getSlotWithRemainingSpace(this.player.containerMenu.slots.get(packet.getSlotNum()).getItem()) != -1 || this.player.getInventory().getFreeSlot() != -1)) { -+ itemResultCount++; ++ itemResultCount += itemstack.getCount(); + } + } + } + int remainResults = itemResultCount; + while(remainResults > 0) { -+ int resultAmount = Math.min(baseResult.getMaxStackSize(), itemResultCount); -+ ++ int resultAmount = Math.min(baseResult.getMaxStackSize(), remainResults); + remainResults -= resultAmount; + org.bukkit.inventory.ItemStack result = baseResult.clone(); + result.setAmount(resultAmount);