Support for results of ItemStacks in CraftItemEvent

This commit is contained in:
Doc 2022-10-11 22:19:46 -03:00
parent 19b727787e
commit e89980bd38
No known key found for this signature in database
GPG key ID: 20C3B20323EFD295
2 changed files with 11 additions and 12 deletions

View file

@ -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<org.bukkit.inventory.ItemStack> itemResults; // Paper
+ private java.util.Collection<org.bukkit.inventory.ItemStack> 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<org.bukkit.inventory.ItemStack> 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<org.bukkit.inventory.ItemStack> 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<org.bukkit.inventory.ItemStack> getItemResults() {
+ public java.util.@org.jetbrains.annotations.Unmodifiable Collection<org.bukkit.inventory.ItemStack> getItemResults() {
+ if (this.itemResults == null) {
+ return java.util.Collections.singletonList(recipe.getResult().clone());
+ return java.util.Collections.singletonList(recipe.getResult());
+ }
+ return this.itemResults;
+ }

View file

@ -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);