Solved getBlockInventory().addItem() - Assistance

Discussion in 'Plugin Development' started by DomThePotato, Nov 1, 2015.

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

    DomThePotato

    Hello so basically want I want to do is be able to add an ItemStack and have more than just 1 of that certain ItemStack.

    Code:
                    for (Map.Entry<ItemStack, Integer> is : reward.entrySet()) {
                            ((Chest) chest1).getBlockInventory().addItem(new ItemStack(is.getKey()));
                    }   
                    chest1.update();
    That is what I've done although it will only add one of that ItemStack where I want to be able to specify more than 1.
    For example for example if I try to do:
    Code:
        ((Chest) chest1).getBlockInventory().addItem(new ItemStack(is.getKey(),is.getValue()));
    It will say "The constructor ItemStack(ItemStack, Integer) is undefined" and tell me to remove it/change it.

    I understand that I may have made it hard to understand my situation what I need to get across but hopefully the main message has got across.

    Thanks

    ~Dom :D

    EDIT: Nevermind, figured it out. :D

    Requesting lock or something like that.

    ~Dom

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 1, 2015
  2. Offline

    zlToxicNetherlz

    Sorry if I do not understand, I do not speak your language
    The method is.getKey() return ItemStack, then it is not necessary use new ItemStack(is.getKey(), is.getValue()).
    The correct usage for new ItemStack is: new ItemStack(<Material>, <Amount>); NOT new ItemStack(<ItemStack>, <Amount>)
    I tried to create a solution:
    Code:
                   for (Map.Entry<ItemStack, Integer> is : reward.entrySet()) { 
                           is.getKey().setAmount(is.getValue()); // Set amount of item
                           ((Chest) chest1).getBlockInventory().addItem(is.getKey());  // Add Item to Chest
                   } 
    chest1.update(); // Update Chest
    
    NOT TESTED.
     
Thread Status:
Not open for further replies.

Share This Page