001    /**
002     * Chest.java - Interface to chests.
003     * @author James
004     */
005    public class Chest extends BaseContainerBlock<kc> implements ComplexBlock {
006        
007        public Chest(kc chest) {
008            super(chest, "Chest");
009        }
010    
011        public DoubleChest findAttachedChest() {
012            Block block = getBlock();
013    
014            DoubleChest result;
015    
016            result = tryAttachedChest(block, Block.Face.Front);
017            if (result != null) return result;
018    
019            result = tryAttachedChest(block, Block.Face.Back);
020            if (result != null) return result;
021    
022            result = tryAttachedChest(block, Block.Face.Left);
023            if (result != null) return result;
024            
025            result = tryAttachedChest(block, Block.Face.Right);
026            if (result != null) return result;
027    
028            return null;
029        }
030    
031        private DoubleChest tryAttachedChest(Block origin, Block.Face face) {
032            Block block = origin.getFace(face);
033            
034            if (block.blockType == Block.Type.Chest) {
035                ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(block);
036                if ((cblock != null) && (cblock instanceof Chest)) {
037                    Chest chest = (Chest)cblock;
038                    return new DoubleChest(new ay(getName(), this.container, chest.container));
039                }
040            }
041    
042            return null;
043        }
044    
045    }