diff --git a/patches/server/1049-Fix-CraftBukkit-drag-system.patch b/patches/server/1049-Fix-CraftBukkit-drag-system.patch index 14a43e49b672b..834d3efeec240 100644 --- a/patches/server/1049-Fix-CraftBukkit-drag-system.patch +++ b/patches/server/1049-Fix-CraftBukkit-drag-system.patch @@ -5,80 +5,55 @@ Subject: [PATCH] Fix CraftBukkit drag system == AT == public net.minecraft.world.inventory.AbstractContainerMenu quickcraftType +public net.minecraft.world.inventory.AbstractContainerMenu quickcraftSlots diff --git a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java -index 34357f2040069a4d42d15e8726a980baf08bdfd4..5505f4e13abfdba48f9ae37b6bcb3cf43fca9c74 100644 +index 8aa03a367419a749c1d363b4b1ba74ca80973e2f..d835b2af666d69d0252048cf37c461253bc388eb 100644 --- a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java +++ b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java -@@ -379,7 +379,7 @@ public abstract class AbstractContainerMenu { - - public void clicked(int slotIndex, int button, ClickType actionType, Player player) { - try { -- this.doClick(slotIndex, button, actionType, player); -+ this.doClick(slotIndex, button, actionType, player, false); // Paper - Fix CraftBukkit drag system - } catch (Exception exception) { - CrashReport crashreport = CrashReport.forThrowable(exception, "Container click"); - CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Click info"); -@@ -398,7 +398,7 @@ public abstract class AbstractContainerMenu { - } - } - -- private void doClick(int slotIndex, int button, ClickType actionType, Player player) { -+ private void doClick(int slotIndex, int button, ClickType actionType, Player player, boolean isSingleSlotDrag) { // Paper - Fix CraftBukkit drag system - Inventory playerinventory = player.getInventory(); - Slot slot; - ItemStack itemstack; -@@ -431,10 +431,10 @@ public abstract class AbstractContainerMenu { +@@ -431,10 +431,12 @@ public abstract class AbstractContainerMenu { } } else if (this.quickcraftStatus == 2) { if (!this.quickcraftSlots.isEmpty()) { - if (false && this.quickcraftSlots.size() == 1) { // CraftBukkit - treat everything as a drag since we are unable to easily call InventoryClickEvent instead -+ if (this.quickcraftSlots.size() == 1) { // Paper - Fix CraftBukkit drag system ++ // Paper start - Fix CraftBukkit drag system ++ if (this.quickcraftSlots.size() == 1) { k = ((Slot) this.quickcraftSlots.iterator().next()).index; - this.resetQuickCraft(); -- this.doClick(k, this.quickcraftType, ClickType.PICKUP, player); -+ this.doClick(k, this.quickcraftType, ClickType.PICKUP, player, true); // Paper - Fix CraftBukkit drag system +- this.resetQuickCraft(); ++ this.quickcraftStatus = 0; + this.doClick(k, this.quickcraftType, ClickType.PICKUP, player); ++ // Paper end - Fix CraftBukkit drag system return; } -@@ -549,11 +549,11 @@ public abstract class AbstractContainerMenu { - ItemStack itemstack3 = this.getCarried(); - - player.updateTutorialInventoryAction(itemstack3, slot.getItem(), clickaction); -- if (!this.tryItemClickBehaviourOverride(player, clickaction, slot, itemstack, itemstack3)) { -+ if (!this.tryItemClickBehaviourOverride(player, clickaction, slot, itemstack, itemstack3, isSingleSlotDrag)) { // Paper - Fix CraftBukkit drag system +@@ -553,7 +555,7 @@ public abstract class AbstractContainerMenu { if (itemstack.isEmpty()) { if (!itemstack3.isEmpty()) { i2 = clickaction == ClickAction.PRIMARY ? itemstack3.getCount() : 1; - this.setCarried(slot.safeInsert(itemstack3, i2)); -+ this.setCarried(slot.safeInsert(this, itemstack3, i2, isSingleSlotDrag)); // Paper - Fix CraftBukkit drag system ++ this.setCarried(slot.safeInsert(this, itemstack3, i2)); // Paper - Fix CraftBukkit drag system } } else if (slot.mayPickup(player)) { if (itemstack3.isEmpty()) { -@@ -567,7 +567,7 @@ public abstract class AbstractContainerMenu { +@@ -567,7 +569,7 @@ public abstract class AbstractContainerMenu { } else if (slot.mayPlace(itemstack3)) { if (ItemStack.isSameItemSameComponents(itemstack, itemstack3)) { i2 = clickaction == ClickAction.PRIMARY ? itemstack3.getCount() : 1; - this.setCarried(slot.safeInsert(itemstack3, i2)); -+ this.setCarried(slot.safeInsert(this, itemstack3, i2, isSingleSlotDrag)); // Paper - Fix CraftBukkit drag system ++ this.setCarried(slot.safeInsert(this, itemstack3, i2)); // Paper - Fix CraftBukkit drag system } else if (itemstack3.getCount() <= slot.getMaxStackSize(itemstack3)) { this.setCarried(itemstack); slot.setByPlayer(itemstack3); -@@ -680,10 +680,10 @@ public abstract class AbstractContainerMenu { - - } - -- private boolean tryItemClickBehaviourOverride(Player player, ClickAction clickType, Slot slot, ItemStack stack, ItemStack cursorStack) { -+ private boolean tryItemClickBehaviourOverride(Player player, ClickAction clickType, Slot slot, ItemStack stack, ItemStack cursorStack, boolean isSingleSlotDrag) { // Paper - Fix CraftBukkit drag system - FeatureFlagSet featureflagset = player.level().enabledFeatures(); - -- return cursorStack.isItemEnabled(featureflagset) && cursorStack.overrideStackedOnOther(slot, clickType, player) ? true : stack.isItemEnabled(featureflagset) && stack.overrideOtherStackedOnMe(cursorStack, slot, clickType, player, this.createCarriedSlotAccess()); -+ return cursorStack.isItemEnabled(featureflagset) && cursorStack.overrideStackedOnOther(slot, clickType, player, isSingleSlotDrag) ? true : stack.isItemEnabled(featureflagset) && stack.overrideOtherStackedOnMe(cursorStack, slot, clickType, player, this.createCarriedSlotAccess()); // Paper - Fix CraftBukkit drag system - } +@@ -582,6 +584,7 @@ public abstract class AbstractContainerMenu { + } + } + } ++ this.quickcraftSlots.clear(); // Paper - Fix CraftBukkit drag system - private SlotAccess createCarriedSlotAccess() { + slot.setChanged(); + // CraftBukkit start - Make sure the client has the right slot contents diff --git a/src/main/java/net/minecraft/world/inventory/Slot.java b/src/main/java/net/minecraft/world/inventory/Slot.java -index c39c773112fb8b534b926f2f2b47fe6fbb69fcb2..e62373600edd148d30d978f82f1feebed71214cb 100644 +index c39c773112fb8b534b926f2f2b47fe6fbb69fcb2..a2040a2d2fc8afe58e8c5a43744f1df373ac5149 100644 --- a/src/main/java/net/minecraft/world/inventory/Slot.java +++ b/src/main/java/net/minecraft/world/inventory/Slot.java @@ -7,6 +7,7 @@ import net.minecraft.resources.ResourceLocation; @@ -94,10 +69,10 @@ index c39c773112fb8b534b926f2f2b47fe6fbb69fcb2..e62373600edd148d30d978f82f1feebe public ItemStack safeInsert(ItemStack stack, int count) { + // Paper start - Fix CraftBukkit drag system -+ return this.safeInsert(null, stack, count, false); ++ return this.safeInsert(null, stack, count); + } + -+ public ItemStack safeInsert(AbstractContainerMenu container, ItemStack stack, int count, boolean isSingleSlotDrag) { ++ public ItemStack safeInsert(AbstractContainerMenu container, ItemStack stack, int count) { if (!stack.isEmpty() && this.mayPlace(stack)) { ItemStack itemStack = this.getItem(); int i = Math.min(Math.min(count, stack.getCount()), this.getMaxStackSize(stack) - itemStack.getCount()); @@ -109,7 +84,7 @@ index c39c773112fb8b534b926f2f2b47fe6fbb69fcb2..e62373600edd148d30d978f82f1feebe - this.setByPlayer(itemStack); + ItemStack newCursor = stack.copy(); + newCursor.shrink(i); -+ if (isSingleSlotDrag) { ++ if (container.quickcraftSlots.size() == 1) { + container.setCarried(newCursor); + + org.bukkit.event.inventory.InventoryDragEvent event = new org.bukkit.event.inventory.InventoryDragEvent( @@ -140,7 +115,7 @@ index c39c773112fb8b534b926f2f2b47fe6fbb69fcb2..e62373600edd148d30d978f82f1feebe public boolean allowModification(Player player) { diff --git a/src/main/java/net/minecraft/world/item/BundleItem.java b/src/main/java/net/minecraft/world/item/BundleItem.java -index 233c50af05085c1ecb069dd2e90d17c85f27e5ab..2bd2ba588a225d9c5c19c55a3d75e97dc5f080f0 100644 +index 233c50af05085c1ecb069dd2e90d17c85f27e5ab..369fcb09cb1162fb0b1a18bf1aafbf83bc14b47b 100644 --- a/src/main/java/net/minecraft/world/item/BundleItem.java +++ b/src/main/java/net/minecraft/world/item/BundleItem.java @@ -22,6 +22,7 @@ import net.minecraft.world.inventory.tooltip.TooltipComponent; @@ -151,15 +126,6 @@ index 233c50af05085c1ecb069dd2e90d17c85f27e5ab..2bd2ba588a225d9c5c19c55a3d75e97d public class BundleItem extends Item { private static final int BAR_COLOR = Mth.color(0.4F, 0.4F, 1.0F); -@@ -37,7 +38,7 @@ public class BundleItem extends Item { - } - - @Override -- public boolean overrideStackedOnOther(ItemStack stack, Slot slot, ClickAction clickType, Player player) { -+ public boolean overrideStackedOnOther(ItemStack stack, Slot slot, ClickAction clickType, Player player, boolean isSingleSlotDrag) { // Paper - Fix CraftBukkit drag system - if (clickType != ClickAction.SECONDARY) { - return false; - } else { @@ -46,26 +47,64 @@ public class BundleItem extends Item { return false; } else { @@ -173,7 +139,7 @@ index 233c50af05085c1ecb069dd2e90d17c85f27e5ab..2bd2ba588a225d9c5c19c55a3d75e97d - ItemStack itemStack3 = slot.safeInsert(itemStack2); - mutable.tryInsert(itemStack3); - } -+ ItemStack itemStack3 = this.safeInsert(player.containerMenu, stack, slot, isSingleSlotDrag); ++ ItemStack itemStack3 = this.safeInsert(player.containerMenu, stack, slot); + player.containerMenu.setCarried(itemStack3); } else if (itemStack.getItem().canFitInsideContainerItems()) { + BundleContents.Mutable mutable = new BundleContents.Mutable(bundleContents); @@ -191,7 +157,7 @@ index 233c50af05085c1ecb069dd2e90d17c85f27e5ab..2bd2ba588a225d9c5c19c55a3d75e97d } } + // Paper start - Fix CraftBukkit drag system -+ public ItemStack safeInsert(net.minecraft.world.inventory.AbstractContainerMenu container, ItemStack bundle, Slot slot, boolean isSingleSlotDrag) { ++ public ItemStack safeInsert(net.minecraft.world.inventory.AbstractContainerMenu container, ItemStack bundle, Slot slot) { + ItemStack newCursor = bundle.copy(); + BundleContents bundleContents = newCursor.get(DataComponents.BUNDLE_CONTENTS); + if (bundleContents == null) @@ -206,7 +172,7 @@ index 233c50af05085c1ecb069dd2e90d17c85f27e5ab..2bd2ba588a225d9c5c19c55a3d75e97d + newContent.shrink(i); + mutable.tryInsert(newContent); + newCursor.set(DataComponents.BUNDLE_CONTENTS, mutable.toImmutable()); -+ if (isSingleSlotDrag) { ++ if (container.quickcraftSlots.size() == 1) { + container.setCarried(newCursor); + + org.bukkit.event.inventory.InventoryDragEvent event = new org.bukkit.event.inventory.InventoryDragEvent( @@ -233,33 +199,3 @@ index 233c50af05085c1ecb069dd2e90d17c85f27e5ab..2bd2ba588a225d9c5c19c55a3d75e97d @Override public boolean overrideOtherStackedOnMe( -diff --git a/src/main/java/net/minecraft/world/item/Item.java b/src/main/java/net/minecraft/world/item/Item.java -index 00d2819494d60b54aa268bbe2ccf57be605ceb30..8220912814b5ee9c1269dca0e0bb2c8481080655 100644 ---- a/src/main/java/net/minecraft/world/item/Item.java -+++ b/src/main/java/net/minecraft/world/item/Item.java -@@ -168,7 +168,7 @@ public class Item implements FeatureElement, ItemLike { - return Mth.hsvToRgb(f / 3.0F, 1.0F, 1.0F); - } - -- public boolean overrideStackedOnOther(ItemStack stack, Slot slot, ClickAction clickType, Player player) { -+ public boolean overrideStackedOnOther(ItemStack stack, Slot slot, ClickAction clickType, Player player, boolean isSingleSlotDrag) { // Paper - Fix CraftBukkit drag system - return false; - } - -diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java -index 893efb2c4a07c33d41e934279dd914a9dbd4ef79..e25bd331128ea0aef48bf743ae75278729235544 100644 ---- a/src/main/java/net/minecraft/world/item/ItemStack.java -+++ b/src/main/java/net/minecraft/world/item/ItemStack.java -@@ -757,8 +757,10 @@ public final class ItemStack implements DataComponentHolder { - return this.getItem().getBarColor(this); - } - -- public boolean overrideStackedOnOther(Slot slot, ClickAction clickType, net.minecraft.world.entity.player.Player player) { -- return this.getItem().overrideStackedOnOther(this, slot, clickType, player); -+ // Paper start - Fix CraftBukkit drag system -+ public boolean overrideStackedOnOther(Slot slot, ClickAction clickType, net.minecraft.world.entity.player.Player player, boolean isSingleSlotDrag) { -+ return this.getItem().overrideStackedOnOther(this, slot, clickType, player, isSingleSlotDrag); -+ // Paper end - Fix CraftBukkit drag system - } - - public boolean overrideOtherStackedOnMe(ItemStack stack, Slot slot, ClickAction clickType, net.minecraft.world.entity.player.Player player, SlotAccess cursorStackReference) {