Solved Anvil inventory help

Discussion in 'Plugin Development' started by lewysryan, Nov 3, 2014.

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

    lewysryan

    I have looked for hours and finally found this:

    Code:java
    1. public static void openAnvilInventory(Player player){
    2.  
    3. EntityPlayer entityPlayer = ((CraftPlayer)player).getHandle();
    4. int containerCounter = entityPlayer.nextContainerCounter();
    5. entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerCounter, 8, "Repair", 9, true));
    6. entityPlayer.activeContainer = new ContainerAnvil(entityPlayer.inventory, (World) player.getWorld(), 0, 0, 0, entityPlayer);
    7. entityPlayer.activeContainer.windowId = containerCounter;
    8. entityPlayer.activeContainer.addSlotListener(entityPlayer);
    9. entityPlayer.playerConnection.sendPacket(new PacketPlayOutSetSlot(containerCounter, 0, new ItemStack(Items.PAPER)));
    10.  
    11. }


    Everything works great. However I need a item in slot 0 so the player can re name it.

    I thought this would work:
    Code:java
    1. entityPlayer.playerConnection.sendPacket(new PacketPlayOutSetSlot(containerCounter, 0, new ItemStack(Items.PAPER)));


    But there is nothing in slot 0. Any help please?

    And before someone says
    Code:
    Inventory i = Bukkit.createInventory(null, InventoryType.anvil, "rapair");
    i.setItem(0, new ItemStack(Material.paper);
    player.openInventory(i);
     
    
    It doesn't work as anvil inventories can't be opened with that method.
     
  2. Offline

    SleepyDog

    **Not tested**



    Code:java
    1. import com.sleepydog.anvil
    2. import com.sleepydog.editAnvil
    3. import com.sleepydog.AnvilInventory
    4.  
    5. public void anvil {
    6. if(Anvilinventory){
    7. //code
    8. }
    9. else {
    10. bukkit.sleepyCode().editAnvil("Swaggy name here");
    11. }
    12. }



    This is a joke, wish i could help.
     
  3. Offline

    lewysryan

    Thanks for the amazing help SleepyDog .......Wish NMS was that simple
     
  4. Offline

    leon3001

    lewysryan likes this.
  5. Offline

    lewysryan

    Thanks a bunch leon3001 Worked like a charm. Can't believe I could not find that. I looked for hours ._.
     
    leon3001 likes this.
Thread Status:
Not open for further replies.

Share This Page