Working with double chests...

Discussion in 'Plugin Development' started by d3x, Mar 22, 2011.

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

    d3x

    Code:
            Block block1 = event.getBlock();
            Block block2 = block1;
            BlockFace[] faces = {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
            for (int i = 0; i < 5; i++) {
                if (i > 0) block2 = block1.getFace(faces[i - 1]);
                if (block2.getTypeId() != 54) continue;
                Chest chest = (Chest) block2.getState();
                //do your chest stuff
            }
    How do you deal with double chests?
     
  2. Offline

    Celtic Minstrel

    I always thought that block.getState() would just return a Chest with double the capacity, but I never tried it...
     
  3. Offline

    Kekec852

    You need to get both chests and handle them individually.
     
  4. Offline

    Afforess

    +1 this.

    A pain in the rear, and why I wrote custom inventory interfaces and API's for MM.
     
  5. Offline

    darknesschaos

    That looks like too many steps, I use:
    Code:
    if(chest.getBlock().getRelative(BlockFace.NORTH).getType() == Material.CHEST)
                 return (Chest)chest.getBlock().getRelative(BlockFace.NORTH).getState();
            else if(chest.getBlock().getRelative(BlockFace.SOUTH).getType() == Material.CHEST)
                 return (Chest)chest.getBlock().getRelative(BlockFace.SOUTH).getState();
            else if(chest.getBlock().getRelative(BlockFace.EAST).getType() == Material.CHEST)
                 return (Chest)chest.getBlock().getRelative(BlockFace.EAST).getState();
            else if(chest.getBlock().getRelative(BlockFace.WEST).getType() == Material.CHEST)
                 return (Chest)chest.getBlock().getRelative(BlockFace.WEST).getState();
            return null;
    Sure, its goofy with triple and quad chests, but honestly, how many of them actually exist?
     
  6. Offline

    Celtic Minstrel

    Since it's not possible to place a chest beside a large chest, that method seems foolproof to me.
     
  7. Offline

    Afforess

    Yep. It is. That solution works for small cases, but I get tired of the copy-n-pasted code, especially when you deal with inventories a lot. But if that's all you need it for, no need fixing what isn't broken.
     
  8. Offline

    darknesschaos

    I use it as a part of a "Toolset" that I can transport between plugins almost seamlessly. yay static methods :D
     
  9. Offline

    Edward Hand

    It depends what exactly you're trying to do. While bukkit doesn't support double chests, the server itself has lots of bits of code for handling double chests which can be cannibalised.
     
Thread Status:
Not open for further replies.

Share This Page