@Override public List<Block> findContainerNeighbors(Block block) { // Currently only chests share an inventory // Minecraft connects two chests next to each other that have the same // direction. We simply check for that condition, taking both normal // and trapped chests into account if (!(BlockData.get(block) instanceof Chest)) { return Collections.singletonList(block); } Material chestMaterial = block.getType(); // CHEST or TRAPPED_CHEST BlockFace chestFacing = ((Directional) BlockData.get(block)).getFacing(); for (BlockFace face : CARDINAL_FACES) { Block atPosition = block.getRelative(face); if (atPosition.getType() != chestMaterial) { continue; } MaterialData materialData = BlockData.get(atPosition); if (!(materialData instanceof Directional)) { continue; } BlockFace facing = ((Directional) materialData).getFacing(); if (!facing.equals(chestFacing)) { if (!facing.equals(chestFacing.getOppositeFace())) { // ^ If the chest was carried over from older Minecraft // versions, block data can be a bit weird. So opposite // face is allowed too for chest connections continue; } } return ImmutableList.of(block, atPosition); } return Collections.singletonList(block); }
public Chest() { super(Material.CHEST); }
public Chest(BlockFace direction) { super(Material.CHEST); }
@Deprecated public Chest(int type) { super(Material.getMaterial(type)); }
public Chest(Material type) { super(type); }
@Deprecated public Chest(int type, byte data) { super(Material.getMaterial(type)); }
@Deprecated public Chest(Material type, byte data) { super(type); }
public Chest clone() { return null; }
/** * Fast alternative for the slow {@code block.getState().getData()} call. * This method skips the part where unnecessary BlockStates are created. For * chests this is quite slow, as all items need to be copied. * * <p> * Some materials, like Trapped Chest, don't return the appropriate material * data in Bukkit. This method fixes those bugs. For example, * {@link Material#TRAPPED_CHEST} returns a {@link MaterialData} of * {@link Chest}. * * @param block * The block. * @return The material data of the block. */ @SuppressWarnings("deprecation") public static MaterialData get(Block block) { Material material = block.getType(); byte data = block.getData(); // Special-case trapped chest, it should have a Chest MaterialData, but // hasn't for some reason if (material == Material.TRAPPED_CHEST) { return new Chest(Material.TRAPPED_CHEST, data); } return material.getNewData(data); }