How can i open an ANVIL window?

Discussion in 'Plugin Development' started by Goty_Metal, Feb 24, 2013.

Thread Status:
Not open for further replies.
  1. Hi guys! i know how to make personal chests/vaults/backpacks, or open chests from a location with a command but i don't know how to create a virtual anvil window (to open it with a command) or open an existing one, any idea? thanks!
     
  2. Offline

    chasechocolate

    Code:java
    1. Inventory anvil = Bukkit.createInventory(player, InventoryType.ANVIL);
    2. player.openInventory(anvil);

    Not 100% sure if it will work.
     
  3. Sorry but didn't work :( no errors at all but just didn't do anything, thanks anyway.
     
  4. BUMP!

    RE-BUMP!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  5. Offline

    orange451

    CraftPlayer cplayer = (CraftPlayer)(player);
    cplayer.getHandle().openAnvil(i, j, k);


    I'm assuming i, j, and k are x y and z variables for the location of the Anvil.
     
  6. Offline

    Tirelessly

    Goty_Metal player.openInventory(Bukkit.createInventory(null, InventoryType.ANVIL));

    chasechocolate 's solution works fine too. If it isn't, then your code isn't reaching that point.

    null is kind of hard to explain. Basically it means "nothing." Instead of providing an object there, I put null because I didn't want the inventory to have an owner. Look it up and I'm sure you'll find plenty of answers.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  7. I can bet 500$ for my code is reaching perfecly, chasechocolate solution didn't worked, i'm grateful anyways, your code didn't worked neither Tirelessly.. sorry, it's the same but short.

    Didn't test your code Orange, there's any way to use the bukkit api instead of the craftbukkit code? thanks :)
    P.D: yes your code works 100% Mr.Orange thanks :) just wondering if it's possible to open a virtual anvil, i mean without an existing one.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  8. Offline

    Tirelessly

    That code works for me so.. Check yourself.
     
  9. Offline

    DomIsAmazing27

    Goty_Metal You could always create one in the world somewhere protected and always reference that one, or when they do the command you create one let them use it and then delete it again once they are done?
     
  10. Offline

    Tirelessly

  11. Man if you say it's working right now for you, there must be a reason, just that, can you post the code u're using and working? thanks
     
  12. Offline

    Tirelessly

    I never tested it. 99% of the time when things don't work it's user error and people don't seem to want to accept that.
     
  13. Offline

    Technius

    If it's executed on an event, did you register it?

    If it's a command, are you sure the code reaches that point?

    Make sure that it doesn't work by putting a "System.out.println("Test")" line after it. If "Test" doesn't display on the console, then it's not reaching that point.
     
    caldabeast likes this.
  14. Offline

    Tirelessly

    I actually did test it and it wasn't working. Like, actually not working.
     
  15. I said... don't works, i've tons of plugins i think I KNOW how to make a simple command XD
     
  16. Offline

    Cybermaxke

    Maybe you can try:
    Code:
    public static void openAnvil(Player player) {
        EntityPlayer p = ((CraftPlayer) player).getHandle();
        AnvilContainer container = new AnvilContainer(p);
     
        int c = p.nextContainerCounter();
        p.playerConnection.sendPacket(new Packet100OpenWindow(c, 8, "Repairing", 9));
        p.activeContainer = container;
        p.activeContainer.windowId = c;
        p.activeContainer.addSlotListener(p);
    }
     
    public class AnvilContainer extends ContainerAnvil {
     
        public AnvilContainer(EntityHuman entity) {
            super(entity.inventory, entity.world, 0, 0, 0, entity);
        }
     
        @Override
        public boolean a(EntityHuman entityhuman) {
            return true;
        }
    }
     
    Laekh and Ultimate_n00b like this.
  17. Thanks for the try but i get "No enclosing instance of type ForeverAnvil is accessible. Must qualify the allocation with an enclosing instance of type ForeverAnvil (e.g. x.new A() where x is an instance of ForeverAnvil)."
     
  18. Offline

    Cybermaxke

    It was working when I tried.
     
  19. move the anvilcontainer to its own class
     
  20. Om right i didn't read that was another class XD my bad! thanks :)
     
  21. Offline

    NZSwAg40

    Did anyone end up getting this ?
     
Thread Status:
Not open for further replies.

Share This Page