Anvil Inventory

Discussion in 'Spigot Plugin Development' started by Floriskn, Oct 6, 2019.

  1. Hello,

    I want to open an anvil inventory with the code:
    Code (Java):
    p.openInventory(Bukkit.createInventory(p, InventoryType.ANVIL, "test"));
    But I get an error when I click on the slots of the anvil inventory, also I cann't set items to the slots.
  2. you can try to replace the invtory owner to null, so you get:
    Code (Text):
    p.openInventory(Bukkit.createInventory(null, InventoryType.ANVIL, "test"));
    If it workt let me now with a rating! :)(y)
  3. Still get errors...
  4. It says that it is not supported YET... so i think it is a problem with bukkit but I could be wrong...:unsure:
  5. Code (Text):
    (e.getInventory() instanceof AnvilInventory)
    Used this code but with instanceof EnchantingInventory and it worked fine, let me know if it works for you.
  6. I don't want this to use in a event, I just want open the anvil inventory and repair and rename stuff.
  7. Gadse

    Gadse Previously GummiBoat

    I'm pretty sure the error occurs because it's not possible to change the anvil's title with API methods yet. (It's possible with NMS, but I don't know if you want to get into that.) Try opening it without a title.

    If you want a more in-depth look at NMS and more control over your GUI, there is this lovely API that you could take a look at.
    • Useful Useful x 1
  8. I still get the same error....
  9. I finally solved it!
    for people with the same problem this is my code:
    Code (Java):
    ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutOpenWindow(1, Containers.ANVIL, new ChatComponentText("IT WORKS!")));
    Thanks Gadse for the tip for using NMS.