Solved Get the location of a double chest.

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

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

    the_merciless

    I'm using a BlockPlaceEvent to track when players place chests. if the chest they place creates a double chest I need to get the location of it. Since the Block placed is a single chest i can not find a way to retrieve it as a DoubleChest. Any ideas?
     
  2. Offline

    caseif

    You can get a Chest from a placed chest block, regardless of whether it's a double chest or not. But, if you really need to get the other half of the double chest, check the adjacent blocks' (x + 1, x - 1, z + 1, z - 1) types and compare them to Material.CHEST.
     
  3. Offline

    the_merciless

    My problem is i need to save the location of the DoubleChest, and i dont know what side of the chests location it saves. I can get the location of each single chest but i need to work out which 1 is equal to the location of the double.

    Solved it myself:

    Code:
    @EventHandler
        public void PlaceEvent(BlockPlaceEvent e){
            Block block = e.getBlockPlaced();          
            if (block.getState() instanceof Chest){
                Chest chest = (Chest) block.getState();
                InventoryHolder ih = chest.getInventory().getHolder();
                if (ih instanceof DoubleChest){
                    DoubleChest dc = (DoubleChest) ih;
                }
            }
        }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page