Changing Anvilled Item

Discussion in 'Plugin Development' started by Ultimate_n00b, Sep 14, 2013.

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

    Ultimate_n00b

    I want to change the output of an anvilled item, how would I do that?
     
  2. Offline

    CubieX

    The API for anvils is not that great.
    This is what I used in one of my plugins:

    Code:
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
      public void onInventoryClick(InventoryClickEvent e)
      {
          if (e.getInventory().getType().equals(InventoryType.ANVIL))
          {
            if(e.getWhoClicked() instanceof Player)  // probably not necessary, but to be safe...
            {
                final Player player = (Player) e.getWhoClicked();         
     
                if(e.getSlotType() == SlotType.RESULT)
                {
                  if((e.getCursor().getType() == Material.AIR) && (e.getCurrentItem().getType() != Material.AIR)) // player will take the resulting item
                  {
                      // check if item in RESULT slot is the wanted type (by using .getContents() and checking the item in slot index 2 (RESULT slot should be index 2, but better double check this)
                      // clear the result slot
                      // call e.getInventory().setItem(2, myItemStack) so the player will pick up the new item
                      // or call player.getInventory().addItem(myItemStack) to add the new item directly to the players inventory
                  }
                }       
            }
          }
      }
    I've not tested the part which is in comments. But it should at least give your the idea.
     
    Ultimate_n00b likes this.
  3. Offline

    Ultimate_n00b

    Awesome, thanks.
     
Thread Status:
Not open for further replies.

Share This Page