block to chest

Discussion in 'Plugin Development' started by Moon_werewolf, Feb 20, 2011.

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

    Moon_werewolf

    I want to add i item to a chest but i don't know how. i try with this but it don't work :/

    Code:
                    ItemStack item = new ItemStack(1);
                    item.setAmount(10);
    
                    Chest test = (Chest)event.getBlock();
                    test.getInventory().addItem(item);
     
  2. Offline

    Jerry Larsson

    Bump. I really want to know this as well. Can't seem to cast the block to Chest, CraftChest, ContainerBlock or anything. The block type is really a chest. block.getType() == Material.Chest.

    Please help.
     
  3. Offline

    Edward Hand

    Use Craftblock.getState(). That returns the chest/sign/funace etc corresponding to a block.
     
  4. Offline

    Moon_werewolf

    Thx after some seaching on Craftblock i got it to work :D

    Code:
                    ItemStack item = new ItemStack(1);
                    item.setAmount(10);
    
                    Chest test = (Chest)event.getBlock().getState();
                    test.getInventory().addItem(item);
     
Thread Status:
Not open for further replies.

Share This Page