diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java index e60ddb718c..58310061f1 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java @@ -11,8 +11,10 @@ import net.minecraft.server.Packet100OpenWindow; import net.minecraft.server.Slot; public class CraftContainer extends Container { - InventoryView view; - InventoryType cachedType; + private InventoryView view; + private InventoryType cachedType; + private String cachedTitle; + private int cachedSize; public CraftContainer(InventoryView view, int id) { this.view = view; @@ -21,6 +23,8 @@ public class CraftContainer extends Container { IInventory top = ((CraftInventory)view.getTopInventory()).getInventory(); IInventory bottom = ((CraftInventory)view.getBottomInventory()).getInventory(); cachedType = view.getType(); + cachedTitle = view.getTitle(); + cachedSize = getSize(); setupSlots(top, bottom); } @@ -29,15 +33,21 @@ public class CraftContainer extends Container { return view; } + private int getSize() { + return view.getTopInventory().getSize(); + } + @Override public boolean b(EntityHuman entityhuman) { - if (cachedType == view.getType()) { + if (cachedType == view.getType() && cachedSize == getSize() && cachedTitle.equals(view.getTitle())) { return true; } // If the window type has changed for some reason, update the player // This method will be called every tick or something, so it's // as good a place as any to put something like this. + boolean typeChanged = (cachedType != view.getType()); cachedType = view.getType(); + cachedTitle = view.getTitle(); if (view.getPlayer() instanceof CraftPlayer) { CraftPlayer player = (CraftPlayer) view.getPlayer(); int type; @@ -51,6 +61,12 @@ public class CraftContainer extends Container { case DISPENSER: type = 3; break; + case ENCHANTING: + type = 4; + break; + case BREWING: + type = 5; + break; default: type = 0; break; @@ -59,8 +75,11 @@ public class CraftContainer extends Container { IInventory bottom = ((CraftInventory)view.getBottomInventory()).getInventory(); this.d.clear(); this.e.clear(); - setupSlots(top, bottom); - player.getHandle().netServerHandler.sendPacket(new Packet100OpenWindow(this.windowId, type, "Crafting", 9)); + if (typeChanged) { + setupSlots(top, bottom); + } + int size = getSize(); + player.getHandle().netServerHandler.sendPacket(new Packet100OpenWindow(this.windowId, type, cachedTitle, size)); player.updateInventory(); } return true;