Problems with Two- removing item from inventory

Discussion in 'Plugin Development' started by dibujaron, Oct 19, 2013.

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

    dibujaron

    Code:
                Inventory i = d.getInventory();
                int slot = i.first(stack.getType());
                ItemStack first = i.getItem(slot);
                int amount = first.getAmount();
                System.out.println("Amount: " + amount);
                if (amount <= 1){
                    i.clear(slot);
                    System.out.println("only one item, clearing!");
                }
                else{
                    first.setAmount(amount - 1);
                    System.out.println("Setting to one less item.");
                }
    
    The above code is meant to remove one item from the inventory of dispenser d. It works fine, until you get to two items in a stack. If there's three stacked items, it works fine; it becomes a stack of two. If it's two or less, though, it doesn't do anything to it. At all.

    Any insight, anyone? This really shouldn't be that hard. It's interesting to me that it's breaking at two, not one- because there's nothing that makes two different from three or anything else. It's not less than or equal to one last I checked, haha. I even tried fiddling with the amount variable, setting it to first.getAmount() + 1 and stuff, but it still broke on two...

    Any help appreciated. Thanks! :)
     
Thread Status:
Not open for further replies.

Share This Page