public static boolean isBusy(final Block block, final Block other) { // Check to see if both sides of a rail block have rails. If they do, assume we're connected. Rails data = (Rails) block.getState().getData(); BlockFace bf = data.getDirection().getOppositeFace(); BlockFace face1, face2; if ( bf == BlockFace.NORTH_EAST ) { face1 = BlockFace.NORTH; face2 = BlockFace.EAST; } else if ( bf == BlockFace.NORTH_WEST ) { face1 = BlockFace.NORTH; face2 = BlockFace.WEST; } else if ( bf == BlockFace.SOUTH_EAST ) { face1 = BlockFace.SOUTH; face2 = BlockFace.EAST; } else if ( bf == BlockFace.SOUTH_WEST ) { face1 = BlockFace.SOUTH; face2 = BlockFace.WEST; } else { face1 = bf; face2 = bf.getOppositeFace(); } final Block block1 = block.getRelative(face1); final Block block2 = block.getRelative(face2); return !( block1.equals(other) || block2.equals(other) ) && isRail(block1) && isRail(block2); }
@Override public BlockFace getBearing() { if(isRail(block)) { return ((Rails)block).getDirection(); } return null; }
public static Block getConnectedSide(Location location, BlockFace side) { // int x = location.getBlockX(); // int y = location.getBlockY(); // int z = location.getBlockZ(); Block block = location.getBlock().getRelative(side); Block b = location.getBlock(); Bukkit.getLogger().info("Block: " + block.getX() + ", " + block.getY() + ", " + block.getZ()); Bukkit.getLogger().info("Side block: " + b.getX() + ", " + b.getY() + ", " + b.getZ()); switch (block.getType()) { // case 50: //case 65: // case 75: //case 76: // case 68: // case 69: // case 77: // case 96: case TORCH: case LADDER: case WALL_SIGN: case LEVER: case REDSTONE_TORCH_ON: case REDSTONE_TORCH_OFF: case STONE_BUTTON: case WOOD_BUTTON: case TRAP_DOOR: case IRON_TRAPDOOR: case WALL_BANNER: BlockFace face = ((Attachable) (block.getState().getData())).getAttachedFace().getOppositeFace(); if (b.getRelative(face).getX() == block.getX() && b.getRelative(face).getZ() == block.getZ()) { return block; } return null; case TRIPWIRE_HOOK: BlockFace face2 = ((Directional) (block.getState().getData())).getFacing().getOppositeFace(); if (b.getRelative(face2).getX() == block.getX() && b.getRelative(face2).getZ() == block.getZ()) { return block; } return null; //case 27: //case 28: //case 66: case RAILS: case ACTIVATOR_RAIL: case DETECTOR_RAIL: case POWERED_RAIL: Rails rail = (Rails) block.getState().getData(); if (rail.isOnSlope()) { BlockFace face1 = rail.getDirection().getOppositeFace(); if (b.getRelative(face1).getX() == block.getX() && b.getRelative(face1).getZ() == block.getZ()) { return block; } } default: return null; } }
public Rails() { }
@Deprecated public Rails(int type) { }
public Rails(Material type) { }
@Deprecated public Rails(int type, byte data) { }
@Deprecated public Rails(Material type, byte data) { }
public Rails clone() { return null; }
@Override public void run() { // If the event was cancelled, stop right now. if ( event.isCancelled() ) return; // If the block isn't still a rail, abort. if ( !BlockUtils.isRail(block) ) return; // Get the block state. BlockState bs = block.getState(); Rails data = (Rails) bs.getData(); // Find the first portal and stick to it. for(final ABPortal portal: portals) { BlockFace face = portal.getFace(block); if ( face == null ) continue; // Try finding a rail block. Block target = null; boolean sloped = false; // First, look ahead. Block other = block.getRelative(face); if ( (BlockUtils.isRail(other) && !BlockUtils.isBusy(other, block)) || (BlockUtils.isRail(other.getRelative(BlockFace.DOWN)) && !BlockUtils.isBusy(other.getRelative(BlockFace.DOWN), block)) ) { target = other; } else { // We can go up if it's straight away. other = other.getRelative(BlockFace.UP); if ( BlockUtils.isRail(other) && !BlockUtils.isBusy(other, block) ) { target = other; sloped = true; } else { // Check the sides. BlockFace f = BlockUtils.toLeft(face); other = block.getRelative(f); if ( BlockUtils.isRail(other) && !BlockUtils.isBusy(other, block) && portal.getFace(other) == null ) { target = other; face = BlockUtils.toRightSub(face); } else { f = BlockUtils.toRight(face); other = block.getRelative(f); if ( BlockUtils.isRail(other) && !BlockUtils.isBusy(other, block) && portal.getFace(other) == null ) { target = other; face = BlockUtils.toLeftSub(face); } } } } // Rotate this track. data.setDirection(face, sloped); bs.setData(data); bs.update(); return; } }