Skip to content

Instantly share code, notes, and snippets.

@mooman219
Created June 22, 2013 00:51
Show Gist options
  • Save mooman219/5835354 to your computer and use it in GitHub Desktop.
Save mooman219/5835354 to your computer and use it in GitHub Desktop.
public void openInventory(Inventory inventory) {
if(isInventoryOpen()) {
EntityPlayer handle = getHandle();
CraftPlayer craftPlayer = (CraftPlayer) player;
CraftInventory craftInventory = (CraftInventory) inventory;
IInventory iinventory = craftInventory.getInventory();
Container container = new ContainerChest(handle.inventory, iinventory);
container.checkReachable = false;
//
dropItemInHand();
sendPacket(new Packet101CloseWindow(handle.activeContainer.windowId));
//
handle.activeContainer.transferTo(container, craftPlayer);
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);
}
}
public void dropItemInHand() {
EntityPlayer handle = getHandle();
PlayerInventory playerinventory = handle.inventory;
if (playerinventory.getCarried() != null) {
handle.drop(playerinventory.getCarried());
playerinventory.setCarried((ItemStack) null);
}
}
public boolean isInventoryOpen() {
EntityPlayer handle = getHandle();
return handle.activeContainer != handle.defaultContainer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment