ContainerBlock to InventoryHolder Issue - Please Help!

Discussion in 'Plugin Development' started by Taien, Mar 14, 2012.

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

    Taien

    So I read about the changes in the Inventory class and really like the idea of some of them. However, I have an issue with a plugin I've made (TreasureHunt).

    Formerly, I created a chest, then grabbed its inventory like this:

    Code:
    ContainerBlock tb = (ContainerBlock)block.getState();
                contents = tb.getInventory();
    But I'm having trouble figuring out how to use the new InventoryHolder. I've checked the docs and I don't see the method anywhere for getting the InventoryHolder for a particular chest. I know there is a specific class for double chests now, but is there no longer a way to get an Inventory for a chest without the player firing an InventoryOpen? Any help would be greatly appreciated as this is the only thing holding my plugin back from being compatible with the current release. :)
     
  2. Offline

    Taien

    Yeah I have read that, but it wasn't explaining how to get an inventory holder for a chest.

    But, for some reason, I had never thought to cast it to Chest :p

    Thanks.
     
  3. No problem. Hope this will solve your issues.
     
  4. Offline

    Taien

    What can you cast to a Chest? I'm trying to cast a Block to Chest and it's giving me invalid cast.
     
  5. Offline

    desht

    Like so:
    PHP:
    if (block.getState() instanceof Chest) {
      
    Chest chest = (Chest)block.getState();
      
    // ...
    }
    You could also use InventoryHolder in place of Chest there if you're looking for any block which can hold an inventory.
     
  6. Offline

    Taien

    Wait, so I'm casting a BlockState to an InventoryHolder?
    So it's exactly like the old way except with InventoryHolder instead of ContainerBlock?

    ...facepalm
     
Thread Status:
Not open for further replies.

Share This Page