Adding items to Material chest?

Discussion in 'Plugin Development' started by CraftCreeper6, Dec 18, 2014.

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

    CraftCreeper6

    Hi! Just wondering, if I am using the setType(Material); method. How would I modify the contents of the chest? Any help appreciated! :D
     
  2. Offline

    mine-care

    @CraftCreeper6 what you want to do? change the type of different items in a chest?
    To do that, loop through all the items in the chest and change the type to whatever.
     
  3. Offline

    CraftCreeper6

    @mine-care
    How do I get the contents? Yes, I know how to do it with ItemStacks but the setType method only works with Material. Therefore, how can I get the contents if I only know it's a material? Wait, I'll try making it into an ItemStack. I'll edit if it fails/works.

    EDIT: Don't really know how that would work :/
     
  4. Offline

    mine-care

  5. Offline

    CraftCreeper6

    @mine-care
    Yes, I know how to do that ;p Although, what I meant was how to get the Material to make sure it's a chest. Then update it. E.G:
    Code:
    chest.getBlock().setType(Material.CHEST);
    
            ItemStack chestItem = new ItemStack(chest.getBlock().getType());
    "chest" is a Location. So, how would I update it? (With the current code I am unable to use chestItem.getInventory();)

    EDIT: Nevermind! I managed to get it working with:
    Code:
    Chest chestBlock = (Chest) chest.getBlock().getState();
           
            chestBlock.getInventory().addItem(new ItemStack(Material.______, _));
     
    Last edited: Dec 18, 2014
  6. Offline

    mine-care

    :p I thought you had issues with chest content types...
     
Thread Status:
Not open for further replies.

Share This Page