Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InventoryAction wrong for Bundles #11313

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions patches/api/0496-Fix-InventoryAction-wrong-for-Bundles.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tamion <[email protected]>
Date: Wed, 21 Aug 2024 15:07:24 +0200
Subject: [PATCH] Fix InventoryAction wrong for Bundles


diff --git a/src/main/java/org/bukkit/event/inventory/InventoryAction.java b/src/main/java/org/bukkit/event/inventory/InventoryAction.java
index b2bcc891196d487cf4c1962b51ec439e921f49f6..f5abc15444e0d6b50e3a82d0a452fc237be155a0 100644
--- a/src/main/java/org/bukkit/event/inventory/InventoryAction.java
+++ b/src/main/java/org/bukkit/event/inventory/InventoryAction.java
@@ -93,5 +93,38 @@ public enum InventoryAction {
* An unrecognized ClickType.
*/
UNKNOWN,
- ;
+ // Paper start - Fix InventoryAction wrong for Bundles
+ /**
+ * 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,
+ // Paper end - Fix InventoryAction wrong for Bundles
}
74 changes: 74 additions & 0 deletions patches/server/1060-Fix-InventoryAction-wrong-for-Bundles.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tamion <[email protected]>
Date: Wed, 21 Aug 2024 14:21:00 +0200
Subject: [PATCH] Fix InventoryAction wrong for Bundles

== AT ==
public net/minecraft/world/item/component/BundleContents$Mutable getMaxAmountToAdd(Lnet/minecraft/world/item/ItemStack;)I;

diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index b5d5dbc50a7b8c40739a15f164ffd08fdc534f9c..4f4e3a027a1e67a0c93413c91afd525738c95056 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -3041,11 +3041,23 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
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;
@@ -3061,7 +3073,34 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
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) {
Loading