Java Code Examples for cn.nukkit.utils.Rail#Orientation

The following examples show how to use cn.nukkit.utils.Rail#Orientation . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockRailActivator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
protected boolean canPowered(Vector3 pos, Rail.Orientation state, int power, boolean relative) {
    Block block = level.getBlock(pos);

    if (!(block instanceof BlockRailActivator)) {
        return false;
    }

    Rail.Orientation base = ((BlockRailActivator) block).getOrientation();

    return (state != Rail.Orientation.STRAIGHT_EAST_WEST
            || base != Rail.Orientation.STRAIGHT_NORTH_SOUTH
            && base != Rail.Orientation.ASCENDING_NORTH
            && base != Rail.Orientation.ASCENDING_SOUTH)
            && (state != Rail.Orientation.STRAIGHT_NORTH_SOUTH
            || base != Rail.Orientation.STRAIGHT_EAST_WEST
            && base != Rail.Orientation.ASCENDING_EAST
            && base != Rail.Orientation.ASCENDING_WEST)
            && (level.isBlockPowered(pos) || checkSurrounding(pos, relative, power + 1));
}
 
Example 2
Source File: BlockRailPowered.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
protected boolean canPowered(Vector3 pos, Rail.Orientation state, int power, boolean relative) {
    Block block = level.getBlock(pos);
    // What! My block is air??!! Impossible! XD
    if (!(block instanceof BlockRailPowered)) {
        return false;
    }

    // Sometimes the rails are diffrent orientation
    Rail.Orientation base = ((BlockRailPowered) block).getOrientation();

    // Possible way how to know when the rail is activated is rail were directly powered
    // OR recheck the surrounding... Which will returns here =w=        
    return (state != Rail.Orientation.STRAIGHT_EAST_WEST
            || base != Rail.Orientation.STRAIGHT_NORTH_SOUTH
            && base != Rail.Orientation.ASCENDING_NORTH
            && base != Rail.Orientation.ASCENDING_SOUTH)
            && (state != Rail.Orientation.STRAIGHT_NORTH_SOUTH
            || base != Rail.Orientation.STRAIGHT_EAST_WEST
            && base != Rail.Orientation.ASCENDING_EAST
            && base != Rail.Orientation.ASCENDING_WEST)
            && (level.isBlockPowered(pos) || checkSurrounding(pos, relative, power + 1));
}
 
Example 3
Source File: BlockRailPowered.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
protected boolean canPowered(Vector3 pos, Rail.Orientation state, int power, boolean relative) {
    Block block = level.getBlock(pos);
    // What! My block is air??!! Impossible! XD
    if (!(block instanceof BlockRailPowered)) {
        return false;
    }

    // Sometimes the rails are diffrent orientation
    Rail.Orientation base = ((BlockRailPowered) block).getOrientation();

    // Possible way how to know when the rail is activated is rail were directly powered
    // OR recheck the surrounding... Which will returns here =w=        
    return (state != Rail.Orientation.STRAIGHT_EAST_WEST 
            || base != Rail.Orientation.STRAIGHT_NORTH_SOUTH 
            && base != Rail.Orientation.ASCENDING_NORTH 
            && base != Rail.Orientation.ASCENDING_SOUTH) 
            && (state != Rail.Orientation.STRAIGHT_NORTH_SOUTH 
            || base != Rail.Orientation.STRAIGHT_EAST_WEST 
            && base != Rail.Orientation.ASCENDING_EAST 
            && base != Rail.Orientation.ASCENDING_WEST) 
            && (level.isBlockPowered(pos) || checkSurrounding(pos, relative, power + 1));
}
 
Example 4
Source File: BlockRailPowered.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
protected boolean canPowered(Vector3 pos, Rail.Orientation state, int power, boolean relative) {
    Block block = level.getBlock(pos);
    // What! My block is air??!! Impossible! XD
    if (!(block instanceof BlockRailPowered)) {
        return false;
    }

    // Sometimes the rails are diffrent orientation
    Rail.Orientation base = ((BlockRailPowered) block).getOrientation();

    // Possible way how to know when the rail is activated is rail were directly powered
    // OR recheck the surrounding... Which will returns here =w=        
    return (state != Rail.Orientation.STRAIGHT_EAST_WEST
            || base != Rail.Orientation.STRAIGHT_NORTH_SOUTH
            && base != Rail.Orientation.ASCENDING_NORTH
            && base != Rail.Orientation.ASCENDING_SOUTH)
            && (state != Rail.Orientation.STRAIGHT_NORTH_SOUTH
            || base != Rail.Orientation.STRAIGHT_EAST_WEST
            && base != Rail.Orientation.ASCENDING_EAST
            && base != Rail.Orientation.ASCENDING_WEST)
            && (level.isBlockPowered(pos) || checkSurrounding(pos, relative, power + 1));
}
 
Example 5
Source File: BlockRailActivator.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
protected boolean canPowered(Vector3 pos, Rail.Orientation state, int power, boolean relative) {
    Block block = level.getBlock(pos);

    if (!(block instanceof BlockRailActivator)) {
        return false;
    }

    Rail.Orientation base = ((BlockRailActivator) block).getOrientation();
 
    return (state != Rail.Orientation.STRAIGHT_EAST_WEST
            || base != Rail.Orientation.STRAIGHT_NORTH_SOUTH
            && base != Rail.Orientation.ASCENDING_NORTH
            && base != Rail.Orientation.ASCENDING_SOUTH)
            && (state != Rail.Orientation.STRAIGHT_NORTH_SOUTH
            || base != Rail.Orientation.STRAIGHT_EAST_WEST
            && base != Rail.Orientation.ASCENDING_EAST
            && base != Rail.Orientation.ASCENDING_WEST)
            && (level.isBlockPowered(pos) || checkSurrounding(pos, relative, power + 1));
}
 
Example 6
Source File: ItemMinecartChest.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartChest minecart = (EntityMinecartChest) Entity.createEntity("MinecartChest",
                level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("")
                        .putList(new ListTag<>("Pos")
                                .add(new DoubleTag("", target.getX() + 0.5))
                                .add(new DoubleTag("", target.getY() + 0.0625D + adjacent))
                                .add(new DoubleTag("", target.getZ() + 0.5)))
                        .putList(new ListTag<>("Motion")
                                .add(new DoubleTag("", 0))
                                .add(new DoubleTag("", 0))
                                .add(new DoubleTag("", 0)))
                        .putList(new ListTag<>("Rotation")
                                .add(new FloatTag("", 0))
                                .add(new FloatTag("", 0)))
        );

        if(minecart == null) {
            return false;
        }

        if (player.isSurvival()) {
            Item item = player.getInventory().getItemInHand();
            item.setCount(item.getCount() - 1);
            player.getInventory().setItemInHand(item);
        }

        minecart.spawnToAll();
        return true;
    }
    return false;
}
 
Example 7
Source File: ItemMinecartChest.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartChest minecart = new EntityMinecartChest(
                level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("")
                .putList(new ListTag<>("Pos")
                        .add(new DoubleTag("", target.getX() + 0.5))
                        .add(new DoubleTag("", target.getY() + 0.0625D + adjacent))
                        .add(new DoubleTag("", target.getZ() + 0.5)))
                .putList(new ListTag<>("Motion")
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0)))
                .putList(new ListTag<>("Rotation")
                        .add(new FloatTag("", 0))
                        .add(new FloatTag("", 0)))
        );
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
 
Example 8
Source File: ItemMinecartHopper.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartHopper minecart = new EntityMinecartHopper(
                level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("")
                .putList(new ListTag<>("Pos")
                        .add(new DoubleTag("", target.getX() + 0.5))
                        .add(new DoubleTag("", target.getY() + 0.0625D + adjacent))
                        .add(new DoubleTag("", target.getZ() + 0.5)))
                .putList(new ListTag<>("Motion")
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0)))
                .putList(new ListTag<>("Rotation")
                        .add(new FloatTag("", 0))
                        .add(new FloatTag("", 0)))
        );
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
 
Example 9
Source File: ItemMinecart.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartEmpty minecart = (EntityMinecartEmpty) Entity.createEntity("MinecartRideable",
                level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("")
                .putList(new ListTag<>("Pos")
                        .add(new DoubleTag("", target.getX() + 0.5))
                        .add(new DoubleTag("", target.getY() + 0.0625D + adjacent))
                        .add(new DoubleTag("", target.getZ() + 0.5)))
                .putList(new ListTag<>("Motion")
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0)))
                .putList(new ListTag<>("Rotation")
                        .add(new FloatTag("", 0))
                        .add(new FloatTag("", 0)))
        );

        if(minecart == null) {
            return false;
        }

        if (player.isSurvival()) {
            Item item = player.getInventory().getItemInHand();
            item.setCount(item.getCount() - 1);
            player.getInventory().setItemInHand(item);
        }

        minecart.spawnToAll();
        return true;
    }
    return false;
}
 
Example 10
Source File: ItemMinecartTNT.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartTNT minecart = new EntityMinecartTNT(
                level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("")
                .putList(new ListTag<>("Pos")
                        .add(new DoubleTag("", target.getX() + 0.5))
                        .add(new DoubleTag("", target.getY() + 0.0625D + adjacent))
                        .add(new DoubleTag("", target.getZ() + 0.5)))
                .putList(new ListTag<>("Motion")
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0)))
                .putList(new ListTag<>("Rotation")
                        .add(new FloatTag("", 0))
                        .add(new FloatTag("", 0)))
        );
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
 
Example 11
Source File: ItemMinecartHopper.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartHopper minecart = (EntityMinecartHopper) Entity.createEntity("MinecartHopper",
                level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("")
                        .putList(new ListTag<>("Pos")
                                .add(new DoubleTag("", target.getX() + 0.5))
                                .add(new DoubleTag("", target.getY() + 0.0625D + adjacent))
                                .add(new DoubleTag("", target.getZ() + 0.5)))
                        .putList(new ListTag<>("Motion")
                                .add(new DoubleTag("", 0))
                                .add(new DoubleTag("", 0))
                                .add(new DoubleTag("", 0)))
                        .putList(new ListTag<>("Rotation")
                                .add(new FloatTag("", 0))
                                .add(new FloatTag("", 0)))
        );

        if(minecart == null) {
            return false;
        }

        if (player.isSurvival()) {
            Item item = player.getInventory().getItemInHand();
            item.setCount(item.getCount() - 1);
            player.getInventory().setItemInHand(item);
        }

        minecart.spawnToAll();
        return true;
    }
    return false;
}
 
Example 12
Source File: ItemMinecartTNT.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartTNT minecart = (EntityMinecartTNT) Entity.createEntity("MinecartTnt",
                level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("")
                .putList(new ListTag<>("Pos")
                        .add(new DoubleTag("", target.getX() + 0.5))
                        .add(new DoubleTag("", target.getY() + 0.0625D + adjacent))
                        .add(new DoubleTag("", target.getZ() + 0.5)))
                .putList(new ListTag<>("Motion")
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0)))
                .putList(new ListTag<>("Rotation")
                        .add(new FloatTag("", 0))
                        .add(new FloatTag("", 0)))
        );

        if(minecart == null) {
            return false;
        }

        if (player.isSurvival()) {
            Item item = player.getInventory().getItemInHand();
            item.setCount(item.getCount() - 1);
            player.getInventory().setItemInHand(item);
        }

        minecart.spawnToAll();
        return true;
    }
    return false;
}
 
Example 13
Source File: ItemMinecart.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartEmpty minecart = new EntityMinecartEmpty(
                level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("")
                .putList(new ListTag<>("Pos")
                        .add(new DoubleTag("", target.getX() + 0.5))
                        .add(new DoubleTag("", target.getY() + 0.0625D + adjacent))
                        .add(new DoubleTag("", target.getZ() + 0.5)))
                .putList(new ListTag<>("Motion")
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0)))
                .putList(new ListTag<>("Rotation")
                        .add(new FloatTag("", 0))
                        .add(new FloatTag("", 0)))
        );
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
 
Example 14
Source File: ItemMinecartChest.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartChest minecart = new EntityMinecartChest(
                level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("")
                .putList(new ListTag<>("Pos")
                        .add(new DoubleTag("", target.getX() + 0.5))
                        .add(new DoubleTag("", target.getY() + 0.0625D + adjacent))
                        .add(new DoubleTag("", target.getZ() + 0.5)))
                .putList(new ListTag<>("Motion")
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0)))
                .putList(new ListTag<>("Rotation")
                        .add(new FloatTag("", 0))
                        .add(new FloatTag("", 0)))
        );
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
 
Example 15
Source File: BlockRailPowered.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Check the surrounding of the rail
 *
 * @param pos      The rail position
 * @param relative The relative of the rail that will be checked
 * @param power    The count of the rail that had been counted
 * @return Boolean of the surrounding area. Where the powered rail on!
 */
protected boolean checkSurrounding(Vector3 pos, boolean relative, int power) {
    // The powered rail can power up to 8 blocks only
    if (power >= 8) {
        return false;
    }
    // The position of the floor numbers
    int dx = pos.getFloorX();
    int dy = pos.getFloorY();
    int dz = pos.getFloorZ();
    // First: get the base block
    BlockRail block;
    Block block2 = level.getBlock(new Vector3(dx, dy, dz));

    // Second: check if the rail is Powered rail
    if (Rail.isRailBlock(block2)) {
        block = (BlockRail) block2;
    } else {
        return false;
    }

    // Used to check if the next ascending rail should be what
    Rail.Orientation base = null;
    boolean onStraight = true;
    // Third: Recalculate the base position
    switch (block.getOrientation()) {
        case STRAIGHT_NORTH_SOUTH:
            if (relative) {
                dz++;
            } else {
                dz--;
            }
            break;
        case STRAIGHT_EAST_WEST:
            if (relative) {
                dx--;
            } else {
                dx++;
            }
            break;
        case ASCENDING_EAST:
            if (relative) {
                dx--;
            } else {
                dx++;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_WEST:
            if (relative) {
                dx--;
                dy++;
                onStraight = false;
            } else {
                dx++;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_NORTH:
            if (relative) {
                dz++;
            } else {
                dz--;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        case ASCENDING_SOUTH:
            if (relative) {
                dz++;
                dy++;
                onStraight = false;
            } else {
                dz--;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        default:
            // Unable to determinate the rail orientation
            // Wrong rail?
            return false;
    }
    // Next check the if rail is on power state
    return canPowered(new Vector3(dx, dy, dz), base, power, relative)
            || onStraight && canPowered(new Vector3(dx, dy - 1, dz), base, power, relative);
}
 
Example 16
Source File: BlockRailActivator.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Check the surrounding of the rail
 *
 * @param pos The rail position
 * @param relative The relative of the rail that will be checked
 * @param power The count of the rail that had been counted
 * @return Boolean of the surrounding area. Where the powered rail on!
 */
protected boolean checkSurrounding(Vector3 pos, boolean relative, int power) {
    if (power >= 8) {
        return false;
    }
    int dx = pos.getFloorX();
    int dy = pos.getFloorY();
    int dz = pos.getFloorZ();
    
    BlockRail block;
    Block block2 = level.getBlock(new Vector3(dx, dy, dz));

    if (Rail.isRailBlock(block2)) {
        block = (BlockRail) block2;
    } else {
        return false;
    }

    Rail.Orientation base = null;
    boolean onStraight = true;

    switch (block.getOrientation()) {
        case STRAIGHT_NORTH_SOUTH:
            if (relative) {
                dz++;
            } else {
                dz--;
            }
            break;
        case STRAIGHT_EAST_WEST:
            if (relative) {
                dx--;
            } else {
                dx++;
            }
            break;
        case ASCENDING_EAST:
            if (relative) {
                dx--;
            } else {
                dx++;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_WEST:
            if (relative) {
                dx--;
                dy++;
                onStraight = false;
            } else {
                dx++;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_NORTH:
            if (relative) {
                dz++;
            } else {
                dz--;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        case ASCENDING_SOUTH:
            if (relative) {
                dz++;
                dy++;
                onStraight = false;
            } else {
                dz--;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        default:
            return false;
    }

    return canPowered(new Vector3(dx, dy, dz), base, power, relative)
            || onStraight && canPowered(new Vector3(dx, dy - 1, dz), base, power, relative);
}
 
Example 17
Source File: BlockRailActivator.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Check the surrounding of the rail
 *
 * @param pos      The rail position
 * @param relative The relative of the rail that will be checked
 * @param power    The count of the rail that had been counted
 * @return Boolean of the surrounding area. Where the powered rail on!
 */
protected boolean checkSurrounding(Vector3 pos, boolean relative, int power) {
    if (power >= 8) {
        return false;
    }
    int dx = pos.getFloorX();
    int dy = pos.getFloorY();
    int dz = pos.getFloorZ();

    BlockRail block;
    Block block2 = level.getBlock(new Vector3(dx, dy, dz));

    if (Rail.isRailBlock(block2)) {
        block = (BlockRail) block2;
    } else {
        return false;
    }

    Rail.Orientation base = null;
    boolean onStraight = true;

    switch (block.getOrientation()) {
        case STRAIGHT_NORTH_SOUTH:
            if (relative) {
                dz++;
            } else {
                dz--;
            }
            break;
        case STRAIGHT_EAST_WEST:
            if (relative) {
                dx--;
            } else {
                dx++;
            }
            break;
        case ASCENDING_EAST:
            if (relative) {
                dx--;
            } else {
                dx++;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_WEST:
            if (relative) {
                dx--;
                dy++;
                onStraight = false;
            } else {
                dx++;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_NORTH:
            if (relative) {
                dz++;
            } else {
                dz--;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        case ASCENDING_SOUTH:
            if (relative) {
                dz++;
                dy++;
                onStraight = false;
            } else {
                dz--;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        default:
            return false;
    }

    return canPowered(new Vector3(dx, dy, dz), base, power, relative)
            || onStraight && canPowered(new Vector3(dx, dy - 1, dz), base, power, relative);
}
 
Example 18
Source File: BlockRailPowered.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Check the surrounding of the rail
 *
 * @param pos The rail position
 * @param relative The relative of the rail that will be checked
 * @param power The count of the rail that had been counted
 * @return Boolean of the surrounding area. Where the powered rail on!
 */
protected boolean checkSurrounding(Vector3 pos, boolean relative, int power) {
    // The powered rail can power up to 8 blocks only
    if (power >= 8) {
        return false;
    }
    // The position of the floor numbers
    int dx = pos.getFloorX();
    int dy = pos.getFloorY();
    int dz = pos.getFloorZ();
    // First: get the base block
    BlockRail block;
    Block block2 = level.getBlock(new Vector3(dx, dy, dz));

    // Second: check if the rail is Powered rail
    if (Rail.isRailBlock(block2)) {
        block = (BlockRail) block2;
    } else {
        return false;
    }
    
    // Used to check if the next ascending rail should be what
    Rail.Orientation base = null;
    boolean onStraight = true;
    // Third: Recalculate the base position
    switch (block.getOrientation()) {
        case STRAIGHT_NORTH_SOUTH:
            if (relative) {
                dz++;
            } else {
                dz--;
            }
            break;
        case STRAIGHT_EAST_WEST:
            if (relative) {
                dx--;
            } else {
                dx++;
            }
            break;
        case ASCENDING_EAST:
            if (relative) {
                dx--;
            } else {
                dx++;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_WEST:
            if (relative) {
                dx--;
                dy++;
                onStraight = false;
            } else {
                dx++;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_NORTH:
            if (relative) {
                dz++;
            } else {
                dz--;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        case ASCENDING_SOUTH:
            if (relative) {
                dz++;
                dy++;
                onStraight = false;
            } else {
                dz--;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        default:
            // Unable to determinate the rail orientation
            // Wrong rail?
            return false;
   } 
    // Next check the if rail is on power state
    return canPowered(new Vector3(dx, dy, dz), base, power, relative)
            || onStraight && canPowered(new Vector3(dx, dy - 1, dz), base, power, relative);
}
 
Example 19
Source File: BlockRailPowered.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Check the surrounding of the rail
 *
 * @param pos      The rail position
 * @param relative The relative of the rail that will be checked
 * @param power    The count of the rail that had been counted
 * @return Boolean of the surrounding area. Where the powered rail on!
 */
protected boolean checkSurrounding(Vector3 pos, boolean relative, int power) {
    // The powered rail can power up to 8 blocks only
    if (power >= 8) {
        return false;
    }
    // The position of the floor numbers
    int dx = pos.getFloorX();
    int dy = pos.getFloorY();
    int dz = pos.getFloorZ();
    // First: get the base block
    BlockRail block;
    Block block2 = level.getBlock(new Vector3(dx, dy, dz));

    // Second: check if the rail is Powered rail
    if (Rail.isRailBlock(block2)) {
        block = (BlockRail) block2;
    } else {
        return false;
    }

    // Used to check if the next ascending rail should be what
    Rail.Orientation base = null;
    boolean onStraight = true;
    // Third: Recalculate the base position
    switch (block.getOrientation()) {
        case STRAIGHT_NORTH_SOUTH:
            if (relative) {
                dz++;
            } else {
                dz--;
            }
            break;
        case STRAIGHT_EAST_WEST:
            if (relative) {
                dx--;
            } else {
                dx++;
            }
            break;
        case ASCENDING_EAST:
            if (relative) {
                dx--;
            } else {
                dx++;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_WEST:
            if (relative) {
                dx--;
                dy++;
                onStraight = false;
            } else {
                dx++;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_NORTH:
            if (relative) {
                dz++;
            } else {
                dz--;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        case ASCENDING_SOUTH:
            if (relative) {
                dz++;
                dy++;
                onStraight = false;
            } else {
                dz--;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        default:
            // Unable to determinate the rail orientation
            // Wrong rail?
            return false;
    }
    // Next check the if rail is on power state
    return canPowered(new Vector3(dx, dy, dz), base, power, relative)
            || onStraight && canPowered(new Vector3(dx, dy - 1, dz), base, power, relative);
}
 
Example 20
Source File: BlockRailActivator.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Check the surrounding of the rail
 *
 * @param pos      The rail position
 * @param relative The relative of the rail that will be checked
 * @param power    The count of the rail that had been counted
 * @return Boolean of the surrounding area. Where the powered rail on!
 */
protected boolean checkSurrounding(Vector3 pos, boolean relative, int power) {
    if (power >= 8) {
        return false;
    }
    int dx = pos.getFloorX();
    int dy = pos.getFloorY();
    int dz = pos.getFloorZ();

    BlockRail block;
    Block block2 = level.getBlock(new Vector3(dx, dy, dz));

    if (Rail.isRailBlock(block2)) {
        block = (BlockRail) block2;
    } else {
        return false;
    }

    Rail.Orientation base = null;
    boolean onStraight = true;

    switch (block.getOrientation()) {
        case STRAIGHT_NORTH_SOUTH:
            if (relative) {
                dz++;
            } else {
                dz--;
            }
            break;
        case STRAIGHT_EAST_WEST:
            if (relative) {
                dx--;
            } else {
                dx++;
            }
            break;
        case ASCENDING_EAST:
            if (relative) {
                dx--;
            } else {
                dx++;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_WEST:
            if (relative) {
                dx--;
                dy++;
                onStraight = false;
            } else {
                dx++;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_NORTH:
            if (relative) {
                dz++;
            } else {
                dz--;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        case ASCENDING_SOUTH:
            if (relative) {
                dz++;
                dy++;
                onStraight = false;
            } else {
                dz--;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        default:
            return false;
    }

    return canPowered(new Vector3(dx, dy, dz), base, power, relative)
            || onStraight && canPowered(new Vector3(dx, dy - 1, dz), base, power, relative);
}