From 809f896dd642ec25cab8b4c0d5210c248677491d Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Sat, 4 Jan 2025 13:56:55 +0100 Subject: [PATCH] Fix InventoryAction wrong for Bundles --- build-data/paper.at | 1 + .../event/inventory/InventoryAction.java | 32 +++++++++++++ .../ServerGamePacketListenerImpl.java.patch | 47 +++++++++++++++++-- 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/build-data/paper.at b/build-data/paper.at index 47ca2bb35903..4e00475ec54f 100644 --- a/build-data/paper.at +++ b/build-data/paper.at @@ -503,6 +503,7 @@ public net.minecraft.world.item.ItemStackLinkedSet TYPE_AND_TAG public net.minecraft.world.item.JukeboxSongPlayer song public net.minecraft.world.item.MapItem createNewSavedData(Lnet/minecraft/world/level/Level;IIIZZLnet/minecraft/resources/ResourceKey;)Lnet/minecraft/world/level/saveddata/maps/MapId; public net.minecraft.world.item.StandingAndWallBlockItem wallBlock +public net.minecraft.world.item.component.BundleContents$Mutable getMaxAmountToAdd(Lnet/minecraft/world/item/ItemStack;)I; public net.minecraft.world.item.component.ItemContainerContents MAX_SIZE public net.minecraft.world.item.component.ItemContainerContents items public net.minecraft.world.item.context.UseOnContext (Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/phys/BlockHitResult;)V diff --git a/paper-api/src/main/java/org/bukkit/event/inventory/InventoryAction.java b/paper-api/src/main/java/org/bukkit/event/inventory/InventoryAction.java index b2bcc891196d..28e0ca543b39 100644 --- a/paper-api/src/main/java/org/bukkit/event/inventory/InventoryAction.java +++ b/paper-api/src/main/java/org/bukkit/event/inventory/InventoryAction.java @@ -93,5 +93,37 @@ public enum InventoryAction { * An unrecognized ClickType. */ UNKNOWN, + /** + * The first stack of items in the clicked bundle is moved to the cursor. + */ + PICKUP_FROM_BUNDLE, + /** + * All of the items on the clicked slot are moved into the bundle on the cursor. + */ + PICKUP_ALL_INTO_BUNDLE, + /** + * Some of the items on the clicked slot are moved into the bundle on the cursor. + */ + PICKUP_SOME_INTO_BUNDLE, + /** + * One of the items on the clicked slot is moved into the bundle on the cursor. + */ + PICKUP_ONE_INTO_BUNDLE, + /** + * The first stack of items is moved to the clicked slot. + */ + PLACE_FROM_BUNDLE, + /** + * All of the items on the cursor are moved into the bundle in the clicked slot. + */ + PLACE_ALL_INTO_BUNDLE, + /** + * Some of the items on the cursor are moved into the bundle in the clicked slot. + */ + PLACE_SOME_INTO_BUNDLE, + /** + * One of the items on the cursor is moved into the bundle in the clicked slot. + */ + PLACE_ONE_INTO_BUNDLE, ; } diff --git a/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch b/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch index 37ab47c80bb9..aae8ac56b9ce 100644 --- a/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch @@ -2017,7 +2017,7 @@ this.player.containerMenu.sendAllDataToRemote(); } else if (!this.player.containerMenu.stillValid(this.player)) { LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu); -@@ -1713,7 +_,313 @@ +@@ -1713,7 +_,352 @@ } else { boolean flag = packet.getStateId() != this.player.containerMenu.getStateId(); this.player.containerMenu.suppressRemoteUpdates(); @@ -2056,11 +2056,23 @@ + ItemStack cursor = this.player.containerMenu.getCarried(); + if (clickedItem.isEmpty()) { + if (!cursor.isEmpty()) { -+ action = packet.getButtonNum() == 0 ? InventoryAction.PLACE_ALL : InventoryAction.PLACE_ONE; ++ // Paper start - Fix InventoryAction wrong for Bundles ++ if (cursor.is(Items.BUNDLE) && packet.getButtonNum() != 0) { ++ action = cursor.get(DataComponents.BUNDLE_CONTENTS).isEmpty() ? InventoryAction.NOTHING : InventoryAction.PLACE_FROM_BUNDLE; ++ } else { ++ action = packet.getButtonNum() == 0 ? InventoryAction.PLACE_ALL : InventoryAction.PLACE_ONE; ++ } ++ // Paper end - Fix InventoryAction wrong for Bundles + } + } else if (slot.mayPickup(this.player)) { + if (cursor.isEmpty()) { -+ action = packet.getButtonNum() == 0 ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF; ++ // Paper start - Fix InventoryAction wrong for Bundles ++ if (slot.getItem().is(Items.BUNDLE) && packet.getButtonNum() != 0) { ++ action = slot.getItem().get(DataComponents.BUNDLE_CONTENTS).isEmpty() ? InventoryAction.NOTHING : InventoryAction.PICKUP_FROM_BUNDLE; ++ } else { ++ action = packet.getButtonNum() == 0 ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF; ++ } ++ // Paper end - Fix InventoryAction wrong for Bundles + } else if (slot.mayPlace(cursor)) { + if (ItemStack.isSameItemSameComponents(clickedItem, cursor)) { + int toPlace = packet.getButtonNum() == 0 ? cursor.getCount() : 1; @@ -2076,7 +2088,34 @@ + action = InventoryAction.PLACE_SOME; + } + } else if (cursor.getCount() <= slot.getMaxStackSize()) { -+ action = InventoryAction.SWAP_WITH_CURSOR; ++ // Paper start - Fix InventoryAction wrong for Bundles ++ if (cursor.is(Items.BUNDLE) && packet.getButtonNum() == 0) { ++ int toPickup = new net.minecraft.world.item.component.BundleContents.Mutable(cursor.get(DataComponents.BUNDLE_CONTENTS)).getMaxAmountToAdd(slot.getItem()); ++ if (toPickup >= slot.getItem().getCount()) { ++ action = InventoryAction.PICKUP_ALL_INTO_BUNDLE; ++ } else if (toPickup == 1) { ++ action = InventoryAction.PICKUP_ONE_INTO_BUNDLE; ++ } else if (toPickup == 0) { ++ action = InventoryAction.NOTHING; ++ } else { ++ action = InventoryAction.PICKUP_SOME_INTO_BUNDLE; ++ } ++ } else if (slot.getItem().is(Items.BUNDLE) && packet.getButtonNum() == 0) { ++ int toPickup = new net.minecraft.world.item.component.BundleContents.Mutable(slot.getItem().get(DataComponents.BUNDLE_CONTENTS)).getMaxAmountToAdd(cursor); ++ if (toPickup >= cursor.getCount()) { ++ action = InventoryAction.PLACE_ALL_INTO_BUNDLE; ++ } else if (toPickup == 1) { ++ action = InventoryAction.PLACE_ONE_INTO_BUNDLE; ++ } else if (toPickup == 0) { ++ action = InventoryAction.NOTHING; ++ } else { ++ action = InventoryAction.PLACE_SOME_INTO_BUNDLE; ++ } ++ ++ } else { ++ action = InventoryAction.SWAP_WITH_CURSOR; ++ } ++ // Paper end - Fix InventoryAction wrong for Bundles + } + } else if (ItemStack.isSameItemSameComponents(cursor, clickedItem)) { + if (clickedItem.getCount() >= 0) {