fix: always set carried item after successful InventoryDragEvent

This commit is contained in:
Emilxyz 2025-08-27 20:02:23 +02:00
parent b96f4d4d62
commit 006317816a
No known key found for this signature in database
GPG Key ID: DB21C49EF31596ED

View File

@ -107,7 +107,7 @@
for (Slot slot1 : this.quickcraftSlots) {
ItemStack carried1 = this.getCarried();
@@ -385,12 +_,46 @@
@@ -385,12 +_,42 @@
int min = Math.min(itemStack.getMaxStackSize(), slot1.getMaxStackSize(itemStack));
int min1 = Math.min(getQuickCraftPlaceCount(this.quickcraftSlots, this.quickcraftType, itemStack) + i2, min);
count -= min1 - i2;
@ -148,11 +148,7 @@
+ for (final it.unimi.dsi.fastutil.ints.Int2ObjectMap.Entry<net.minecraft.world.item.ItemStack> entry : draggedSlots.int2ObjectEntrySet()) {
+ view.setItem(entry.getIntKey(), org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(entry.getValue()));
+ }
+ // The only time the carried item will be set to empty is if the inventory is closed by the server.
+ // If the inventory is closed by the server, then the cursor items are dropped. This is why we change the cursor early.
+ if (!this.getCarried().isEmpty()) {
+ this.setCarried(org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getCursor()));
+ }
+ this.setCarried(org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getCursor()));
+ } else {
+ this.setCarried(oldCarried);
+ }