Taking 1 item from ItemStack and placing 64 on cursor

Discussion in 'Plugin Development' started by martijnpold, Jan 10, 2016.

Thread Status:
Not open for further replies.
  1. What I need to do is when you right-click an item it will take 1 away and give you 64 of another item on the cursor.
    This is what I currently have:
    Code:
    @EventHandler
        public void decompress(InventoryClickEvent e) {
            if (e.getAction().equals(InventoryAction.PICKUP_HALF)) {
                ItemStack item = e.getCurrentItem();
                Integer amount = item.getAmount();
                if (item.getType().equals(Material.GOLD_INGOT)) {
                    e.setCancelled(true);
                    if(amount > 1) {
                        item.setAmount(amount-1);
    
                    } else {
                        item = null;
                    }
                }
            }
        }
    But I don't know if I should use e.getCurrentItem() and take 1 away from it since I cancel the event. And if that is what I'm supposed to do then what do I use to set an item on the cursor afterwards?
     
  2. Offline

    CraftCreeper6

    @martijnpold
    So, I take one item, then it takes 64 of that item?
     
  3. No, I want to take 1 from the item i clicked and then add 64 of another item to the cursor.
     
  4. Offline

    CraftCreeper6

    @martijnpold
    player#setItemInHand();

    EDIT: player#setItemInCursor();
     
Thread Status:
Not open for further replies.

Share This Page