Anvil inventory result item

Discussion in 'Plugin Development' started by DarkBladee12, Nov 9, 2013.

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

    DarkBladee12

    Hey Guys, I'm trying to implement an anvil fix in my EnchantPlus plugin (so you can enchant items with enchated books that have a higher level than the natural level), but it doesn't seem to work since getting the result item with "i.getItem(2)" is throwing me an ArrayIndexOutOfBoundsException. I've already searched for this and found out that this is a bug in Bukkit, even "i.getSize()" returns me 3, but "i.getItem(2)" can't be performed... Do you know any workaround for this issue?

    Bump

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

    Bart

    Not quite sure what the question is. Explain more.
     
  3. Offline

    NathanWolf

    Are you looking to get the item that was just removed from the result slot after repairing/renaming?

    Here is what I do for that, it works well for me (renaming custom items)

    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent event) {
    3.  
    4. if (!(event.getWhoClicked() instanceof Player)) return;
    5.  
    6. if (event.getInventory().getType() == InventoryType.ANVIL)
    7. {
    8. SlotType slotType = event.getSlotType();
    9. ItemStack cursor = event.getCursor();
    10. ItemStack current = event.getCurrentItem();
    11.  
    12. // Adding/removing items from the crafting slot
    13. // In case you need to do something to the item before it is repaired
    14. if (slotType == SlotType.CRAFTING) {
    15. // work with “cursor” and “current” here
    16. // cursor will be the thing about to be repaired
    17. // current will be whatever is in the repair slot already
    18. }
    19.  
    20. // This is removing an item from the result slot
    21. if (slotType == SlotType.RESULT) {
    22. // here you should check if “current” is an item you care about
    23. // and do your special thing.
    24. }
    25. }
    26. }
     
  4. Offline

    DarkBladee12

    NathanWolf Well I'm trying to change the result item when you put an item in the first or second slot!
     
  5. Offline

    NathanWolf

    I think the above code should work. I haven't used the second slot, but I think either would have the crafting slot type.

    I haven't tried accessing the anvil inventory by index though, so if there is a bug ther I may not have run into it myself.
     
  6. Offline

    DarkBladee12

    NathanWolf Well I know that your code works, but I need to access the result slot for my idea when the player clicks the first or second slot. I had it like you before, but it is kinda odd then, because when you put an item + enchanted book with sharpness X in the ingredients slots and hover over the result sharpness V is shown, but when you take the result out it will be sharpness X. So I wanted that if you put the second ingredient in the window, it'll instantly change the result so it will display sharpness X when you hover over it!
     
  7. Offline

    DarkBladee12

  8. Offline

    DarkBladee12

Thread Status:
Not open for further replies.

Share This Page