Solved Get inventory from chest block

Discussion in 'Plugin Development' started by BeMacized, Apr 6, 2013.

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

    BeMacized

    Hi there

    Here I am with another question...
    I wonder if it is possible to get the inventory from a chest block. Like the actual block instance.
    I could just create a custom inventory, and show it when people interact with that specific chest block, but I would need to save that somewhere manually, and ofc it would be way more convenient to store it in the world file like a normal chest. So, to quickly give the question, how can I get the inventory of a block instance with Material.CHEST as type?

    - BeMacized
     
  2. Offline

    chasechocolate

    Code:java
    1. if(block.getState() instanceof Chest){
    2. Chest chest = (Chest) block.getState();
    3. Inventory inv = chest.getInventory();
    4. }

    May also work with:
    Code:java
    1. if(block.getType() == Material.CHEST){
    2. Chest chest = (Chest) block.getState();
    3. Inventory inv = chest.getInventory();
    4. }
     
    BeMacized likes this.
  3. Offline

    BeMacized

    Thanks a bunch! It worked :)
     
Thread Status:
Not open for further replies.

Share This Page