Get the location of an InventoryHolder

Discussion in 'Plugin Development' started by blackwolf12333, Aug 3, 2013.

Thread Status:
Not open for further replies.
  1. It has been a while since I had to post something here :p

    But anyway, I need a way to get the location of an InventoryHolder in general, not just a chest, that can be done with casting.

    What I got is here, and as you can see I only have DoubleChests, StorageMinecarts and Chests, but I want to be able to have all different types of InventoryHolders...

    Thanks in advance,
    blackwolf12333
     
  2. Offline

    stirante

    Check for Beacon, ContainerBlock, DoubleChest, Dropper, Hopper, HumanEntity, HopperMinecart, StorageMinecart. These are all possible InventoryHolders.
     
  3. I know, but that would make it a huge if else if statement, I hoped something simpler would be possible.
     
  4. Offline

    stirante

    I don't know any other way. Maybe some fun with reflection?
     
  5. Offline

    AmShaegar

    Afaik there are only 3 different scenarios: The InventoryHolder either is a DoubleChest, implements BlockState or implements Entity. So you'd just need to check for:
    Code:
    if(ih instanceof BlockState) {
      location = ((BlockState) ih).getLocation();
    } else if(ih instanceof Entity) {
      location = ((Entity) ih).getLocation();
    } else if(ih instanceof DoubleChest) {
      location = ((DoubleChest) ih).getLocation();
    } else {
      // report unexpected error to be sure
    }
     
  6. That is pretty much what I was looking for, thanks :)
     
  7. Offline

    stirante

Thread Status:
Not open for further replies.

Share This Page