Skip to content

Instantly share code, notes, and snippets.

@mooman219
Created June 23, 2013 21:08
Show Gist options
  • Save mooman219/5846551 to your computer and use it in GitHub Desktop.
Save mooman219/5846551 to your computer and use it in GitHub Desktop.
public boolean isInventoryOpen() {
EntityPlayer handle = getHandle();
return handle.activeContainer != handle.defaultContainer;
}
public void openInventory(Inventory inventory) {
if(isInventoryOpen()) {
EntityPlayer handle = getHandle();
CraftPlayer craftPlayer = (CraftPlayer) player;
CraftInventory craftInventory = (CraftInventory) inventory;
PlayerInventory handleinventory = handle.inventory;
IInventory iinventory = craftInventory.getInventory();
Container container = new ContainerChest(handle.inventory, iinventory);
container.checkReachable = false;
sendPacket(new Packet101CloseWindow(handle.activeContainer.windowId));
handle.activeContainer.transferTo(container, craftPlayer);
if (handleinventory.getCarried() != null) {
handle.updateInventory(container);
}
int counter = handle.nextContainerCounter();
int windowType = CraftContainer.getNotchInventoryType(inventory.getType());
String title = iinventory.getName();
int size = iinventory.getSize();
boolean useTitle = true;
handle.playerConnection.sendPacket(new Packet100OpenWindow(counter, windowType, title, size, useTitle));
handle.activeContainer = container;
handle.activeContainer.windowId = counter;
handle.activeContainer.addSlotListener(handle);
} else {
player.openInventory(inventory);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment