Resource 1.8 Open an anvil inventory [Not much code]

Discussion in 'Plugin Help/Development/Requests' started by lewysryan, Dec 13, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    First off I want to say this thread is a result of me digging around and trying for hours and combining and some changing and ugghhh a lot of headache. I'm putting this up because I think people should be able to find what exactly they need and to save them a lot of time. I didn't code anything.
    Hello people! So i'm not going to waste time so here is the code:

    Anvil class:

    import net.minecraft.server.v1_8_R1.ChatMessage;
    import net.minecraft.server.v1_8_R1.EntityPlayer;
    import net.minecraft.server.v1_8_R1.PacketPlayOutOpenWindow;
    import org.bukkit.Material;
    import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    public class Anvil {
        public static void openAnvilInventory(final Player player) {
            EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
            FakeAnvil fakeAnvil = new FakeAnvil(entityPlayer);
            int containerId = entityPlayer.nextContainerCounter();
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, "minecraft:anvil", new ChatMessage("Repairing", new Object[]{}), 0));
            entityPlayer.activeContainer = fakeAnvil;
            entityPlayer.activeContainer.windowId = containerId;
            entityPlayer.activeContainer = fakeAnvil;
            entityPlayer.activeContainer.windowId = containerId;
            Inventory inv = fakeAnvil.getBukkitView().getTopInventory();
            inv.setItem(0, new ItemStack(Material.PAPER)); //Remove this if you don't want to add stuff into slots. This is what I needed it for my GUI.
    FakeAnvil class:
    import net.minecraft.server.v1_8_R1.BlockPosition;
    import net.minecraft.server.v1_8_R1.ContainerAnvil;
    import net.minecraft.server.v1_8_R1.EntityHuman;
    public final class FakeAnvil extends ContainerAnvil {
    public FakeAnvil(EntityHuman entityHuman) {    
        super(entityHuman.inventory,, new BlockPosition(0,0,0), entityHuman);
    public boolean a(EntityHuman entityHuman) {    
    return true;
    This code will open a anvil inventory, and placed in a paper into slot one.

    Helpful links:
    For event tutorial for the anvil inventory go here:

    Thanks for reading! Like I said I claim no credit, jut put stuff together and figured it out! Enjoy. (PS I know this is spigot, but come on. Don't hate please. It's still like bukkit. so just let me help users. I mean no harm. I know I linked spigot also but I must reference my Findings as i'm not a credit stealer.
    Last edited: Dec 13, 2014
    Rexcantor64, GrandmaJam and ChipDev like this.
  2. Offline


    No it is not.
    Skionz likes this.
  3. Offline


  4. Offline


  5. Offline


    Doesn't work for me. Have to use this way. Stupid right?

    @chasechocolate nope I don't believe so and they changed it up even more in 1.8. (Hope you don't mind me posting parts your code. I did reference you and clearly state it's not my code.

    Okay changed my wording.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 29, 2016
  6. Offline


    Moved to Alternatives Section.

    We decided that Plugin Help/Developement/Requests is now a suitable place for any Resources/Tutorials which require an Alternative to be installed.
  7. Offline


    Thank you a lot!
  8. Offline


    @chasechocolate Yes, the actual Anvil inventory type class seems to be in the bukkit API, but the code was never complete. I've tried many ways to do this, and did not succeed. It would be great if this ressource works. I'm going to give it a shot. :)

    @TheDianondPicks If you have a basic knowledge of programming plugins, this should help you out.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 29, 2016
Thread Status:
Not open for further replies.

Share This Page