Only one type of item in a chest

Discussion in 'Plugin Development' started by blizzblang, Jun 5, 2012.

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

    blizzblang

    Due to the upcoming 1.3 update of Minecraft, i need the code/or plugin to limit types items in a chest.
    (i.e. gold can only be placed in one chest and only coal can be placed in another chest)
    I'm planning to make a simple bank system for Emerald , the new minecraft currency.
    When completed emerald can be spent as long as it is the bank. some help with this would be appreciated.
     
  2. Offline

    hawkfalcon

    Register the chest to a hash map, then if someone tries to put something in chest, check if that is emerald.
     
  3. Offline

    CorrieKay

    Assuming you have the inventory object...


    Code:
    Inventory inv;//inventory in question
    Material type;//material type in question
    ItemStack item; //item stack youre trying to put into the chest
     
     
    for(ItemStack is : inv.getContents()){
      if(is != null){
        if(is.getType() == type){
          //prevent placement here
          return;
        }
      }
    }
     
  4. Offline

    blizzblang

    I've got the code working for getting the items from the chest.
    but then i use SetAmount,SetTypeid, or SetType, i can delete teh item. i've tried setting the amount to 0. the type to air, and the amount to zero.
     
  5. Offline

    Njol

    You have to set an item to null to completely remove it, e.g. with inventory.set(index, null)
     
  6. Offline

    blizzblang

    Got it to work.
    Now i can run a command while looking at a chest and remove all the items inside, exept gold(pre 1.3 currency) .
    Thanks for all the help
     
Thread Status:
Not open for further replies.

Share This Page