From 5dfb74032c97e34ab9fb405cd886266663342e45 Mon Sep 17 00:00:00 2001 From: Travis Watkins Date: Wed, 23 Apr 2014 13:46:19 -0500 Subject: Handle inventory max stack sizes better. Fixes BUKKIT-5564 Make sure we check the inventory's max stack size where appropriate and don't assume the inventory slot is able to take our entire stack just because it is empty. We also ensure the client is updated with the correct slot contents and cursor contents in cases where the max stack changes result in different behavior than the client expected. --- src/main/java/net/minecraft/server/Container.java | 41 ++++++++++++++++++----- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main/java/net/minecraft/server/Container.java b/src/main/java/net/minecraft/server/Container.java index bc52beb6..3443a192 100644 --- a/src/main/java/net/minecraft/server/Container.java +++ b/src/main/java/net/minecraft/server/Container.java @@ -282,7 +282,11 @@ public abstract class Container { if (itemstack4.count == 0) { playerinventory.setCarried((ItemStack) null); + // CraftBukkit start - Update client cursor if we didn't empty it + } else if (entityhuman instanceof EntityPlayer) { + ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, entityhuman.inventory.getCarried())); } + // CraftBukkit end } } else if (slot2.isAllowed(entityhuman)) { if (itemstack4 == null) { @@ -308,7 +312,11 @@ public abstract class Container { itemstack4.a(k1); if (itemstack4.count == 0) { playerinventory.setCarried((ItemStack) null); + // CraftBukkit start - Update client cursor if we didn't empty it + } else if (entityhuman instanceof EntityPlayer) { + ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, entityhuman.inventory.getCarried())); } + // CraftBukkit end itemstack1.count += k1; } else if (itemstack4.count <= slot2.getMaxStackSize()) { @@ -317,7 +325,10 @@ public abstract class Container { } } else if (itemstack1.getItem() == itemstack4.getItem() && itemstack4.getMaxStackSize() > 1 && (!itemstack1.usesData() || itemstack1.getData() == itemstack4.getData()) && ItemStack.equals(itemstack1, itemstack4)) { k1 = itemstack1.count; - if (k1 > 0 && k1 + itemstack4.count <= itemstack4.getMaxStackSize()) { + // CraftBukkit start - itemstack4.getMaxStackSize() -> maxStack + int maxStack = Math.min(itemstack4.getMaxStackSize(), slot2.getMaxStackSize()); + if (k1 > 0 && k1 + itemstack4.count <= maxStack) { + // CraftBukkit end itemstack4.count += k1; itemstack1 = slot2.a(k1); if (itemstack1.count == 0) { @@ -325,11 +336,20 @@ public abstract class Container { } slot2.a(entityhuman, playerinventory.getCarried()); + // CraftBukkit start - Update client cursor if we didn't empty it + } else if (entityhuman instanceof EntityPlayer) { + ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, entityhuman.inventory.getCarried())); } + // CraftBukkit end } } slot2.f(); + // CraftBukkit start - Make sure the client has the right slot contents + if (entityhuman instanceof EntityPlayer) { + ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutSetSlot(this.windowId, slot2.rawSlotIndex, slot2.getItem())); + } + // CraftBukkit end } } } else if (k == 2 && j >= 0 && j < 9) { @@ -468,17 +488,20 @@ public abstract class Container { if (itemstack1 != null && itemstack1.getItem() == itemstack.getItem() && (!itemstack.usesData() || itemstack.getData() == itemstack1.getData()) && ItemStack.equals(itemstack, itemstack1)) { int l = itemstack1.count + itemstack.count; - if (l <= itemstack.getMaxStackSize()) { + // CraftBukkit start - itemstack.getMaxStackSize() -> maxStack + int maxStack = Math.min(itemstack.getMaxStackSize(), slot.getMaxStackSize()); + if (l <= maxStack) { itemstack.count = 0; itemstack1.count = l; slot.f(); flag1 = true; - } else if (itemstack1.count < itemstack.getMaxStackSize()) { - itemstack.count -= itemstack.getMaxStackSize() - itemstack1.count; - itemstack1.count = itemstack.getMaxStackSize(); + } else if (itemstack1.count < maxStack) { + itemstack.count -= maxStack - itemstack1.count; + itemstack1.count = maxStack; slot.f(); - flag1 = true; + flag1 = itemstack.count == 0; // Don't give a success return if we have leftovers } + // CraftBukkit end } if (flag) { @@ -502,8 +525,10 @@ public abstract class Container { if (itemstack1 == null) { slot.set(itemstack.cloneItemStack()); slot.f(); - itemstack.count = 0; - flag1 = true; + // CraftBukkit start - Don't assume entire stack went in + itemstack.count -= slot.getItem().count; + flag1 = itemstack.count == 0; + // CraftBukkit end break; } -- cgit v1.2.3