Skip to content

Instantly share code, notes, and snippets.

@Garris0n-
Created December 20, 2013 18:14
Show Gist options
  • Save Garris0n-/8058944 to your computer and use it in GitHub Desktop.
Save Garris0n-/8058944 to your computer and use it in GitHub Desktop.
// https://github.com/Bukkit/CraftBukkit/blob/7e1ac0a77129b169704c1e222ff2deb3ab6cd2d2/src/main/java/net/minecraft/server/EntityPlayer.java#L596
//Method to open an anvil inventory to a player
public static void openAnvil(Player player, Inventory inventory){
//Get our EntityPlayer
EntityPlayer p = ((CraftPlayer) player).getHandle();
//Create the AnvilContainer
AnvilContainer container = new AnvilContainer(p);
//Set the items to the items from the inventory given
container.getBukkitView().getTopInventory().setItem(0, inventory.getItem(0));
container.getBukkitView().getTopInventory().setItem(1, inventory.getItem(1));
//container.getBukkitView().getTopInventory().setItem(2, inventory.getItem(2));
//Counter stuff that the game uses to keep track of inventories
int c = p.nextContainerCounter();
//Send the packet
p.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, 8, "Repairing", 9, true));
//Set their active container to the container
p.activeContainer = container;
//Set their active container window id to that counter stuff
p.activeContainer.windowId = c;
//Add the slot listener
p.activeContainer.addSlotListener(p);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment