cn.nukkit.utils.Rail Java Examples

The following examples show how to use cn.nukkit.utils.Rail. 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: 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 #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: 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 #7
Source File: BlockRail.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private Map<BlockRail, BlockFace> checkRailsAround(Collection<BlockFace> faces) {
    Map<BlockRail, BlockFace> result = new HashMap<>();
    faces.forEach(f -> {
        Block b = this.getSide(f);
        Stream.of(b, b.up(), b.down())
                .filter(Rail::isRailBlock)
                .forEach(block -> result.put((BlockRail) block, f));
    });
    return result;
}
 
Example #8
Source File: BlockRail.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private Map<BlockRail, BlockFace> checkRailsAround(Collection<BlockFace> faces) {
    Map<BlockRail, BlockFace> result = new HashMap<>();
    faces.forEach(f -> {
        Block b = this.getSide(f);
        Stream.of(b, b.up(), b.down())
                .filter(Rail::isRailBlock)
                .forEach(block -> result.put((BlockRail) block, f));
    });
    return result;
}
 
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 = 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 #10
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 #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 = 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 #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 = 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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
Source File: ItemMinecartHopper.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;
        }
        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 #19
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 #20
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 #21
Source File: BlockRail.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
private Map<BlockRail, BlockFace> checkRailsAround(Collection<BlockFace> faces) {
    Map<BlockRail, BlockFace> result = new HashMap<>();
    faces.forEach(f -> {
        Block b = this.getSide(f);
        Stream.of(b, b.up(), b.down())
                .filter(Rail::isRailBlock)
                .forEach(block -> result.put((BlockRail) block, f));
    });
    return result;
}
 
Example #22
Source File: EntityMinecartAbstract.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
private Vector3 getNextRail(double dx, double dy, double dz) {
    int checkX = MathHelper.floor(dx);
    int checkY = MathHelper.floor(dy);
    int checkZ = MathHelper.floor(dz);

    if (Rail.isRailBlock(level.getBlockIdAt(checkX, checkY - 1, checkZ))) {
        --checkY;
    }

    Block block = level.getBlock(new Vector3(checkX, checkY, checkZ));

    if (Rail.isRailBlock(block)) {
        int[][] facing = matrix[((BlockRail) block).getRealMeta()];
        double rail;
        // Genisys mistake (Doesn't check surrounding more exactly)
        double nextOne = (double) checkX + 0.5D + (double) facing[0][0] * 0.5D;
        double nextTwo = (double) checkY + 0.5D + (double) facing[0][1] * 0.5D;
        double nextThree = (double) checkZ + 0.5D + (double) facing[0][2] * 0.5D;
        double nextFour = (double) checkX + 0.5D + (double) facing[1][0] * 0.5D;
        double nextFive = (double) checkY + 0.5D + (double) facing[1][1] * 0.5D;
        double nextSix = (double) checkZ + 0.5D + (double) facing[1][2] * 0.5D;
        double nextSeven = nextFour - nextOne;
        double nextEight = (nextFive - nextTwo) * 2;
        double nextMax = nextSix - nextThree;

        if (nextSeven == 0) {
            rail = dz - (double) checkZ;
        } else if (nextMax == 0) {
            rail = dx - (double) checkX;
        } else {
            double whatOne = dx - nextOne;
            double whatTwo = dz - nextThree;

            rail = (whatOne * nextSeven + whatTwo * nextMax) * 2;
        }

        dx = nextOne + nextSeven * rail;
        dy = nextTwo + nextEight * rail;
        dz = nextThree + nextMax * rail;
        if (nextEight < 0) {
            ++dy;
        }

        if (nextEight > 0) {
            dy += 0.5D;
        }

        return new Vector3(dx, dy, dz);
    } else {
        return null;
    }
}
 
Example #23
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 #24
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 #25
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 #26
Source File: EntityMinecartAbstract.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private Vector3 getNextRail(double dx, double dy, double dz) {
    int checkX = MathHelper.floor(dx);
    int checkY = MathHelper.floor(dy);
    int checkZ = MathHelper.floor(dz);

    if (Rail.isRailBlock(level.getBlockIdAt(checkX, checkY - 1, checkZ))) {
        --checkY;
    }

    Block block = level.getBlock(new Vector3(checkX, checkY, checkZ));

    if (Rail.isRailBlock(block)) {
        int[][] facing = matrix[((BlockRail) block).getRealMeta()];
        double rail;
        // Genisys mistake (Doesn't check surrounding more exactly)
        double nextOne = (double) checkX + 0.5D + (double) facing[0][0] * 0.5D;
        double nextTwo = (double) checkY + 0.5D + (double) facing[0][1] * 0.5D;
        double nextThree = (double) checkZ + 0.5D + (double) facing[0][2] * 0.5D;
        double nextFour = (double) checkX + 0.5D + (double) facing[1][0] * 0.5D;
        double nextFive = (double) checkY + 0.5D + (double) facing[1][1] * 0.5D;
        double nextSix = (double) checkZ + 0.5D + (double) facing[1][2] * 0.5D;
        double nextSeven = nextFour - nextOne;
        double nextEight = (nextFive - nextTwo) * 2;
        double nextMax = nextSix - nextThree;

        if (nextSeven == 0) {
            rail = dz - (double) checkZ;
        } else if (nextMax == 0) {
            rail = dx - (double) checkX;
        } else {
            double whatOne = dx - nextOne;
            double whatTwo = dz - nextThree;

            rail = (whatOne * nextSeven + whatTwo * nextMax) * 2;
        }

        dx = nextOne + nextSeven * rail;
        dy = nextTwo + nextEight * rail;
        dz = nextThree + nextMax * rail;
        if (nextEight < 0) {
            ++dy;
        }

        if (nextEight > 0) {
            dy += 0.5D;
        }

        return new Vector3(dx, dy, dz);
    } else {
        return null;
    }
}
 
Example #27
Source File: EntityMinecartAbstract.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onUpdate(int currentTick) {
    if (this.closed) {
        return false;
    }

    if (!this.isAlive()) {
        ++this.deadTicks;
        if (this.deadTicks >= 10) {
            this.despawnFromAll();
            this.close();
        }
        return this.deadTicks < 10;
    }

    int tickDiff = currentTick - this.lastUpdate;

    if (tickDiff <= 0) {
        return false;
    }

    this.lastUpdate = currentTick;

    if (isAlive()) {
        super.onUpdate(currentTick);

        // Entity variables
        lastX = x;
        lastY = y;
        lastZ = z;
        motionY -= 0.03999999910593033D;
        int dx = MathHelper.floor(x);
        int dy = MathHelper.floor(y);
        int dz = MathHelper.floor(z);

        // Some hack to check rails
        if (Rail.isRailBlock(level.getBlockIdAt(dx, dy - 1, dz))) {
            --dy;
        }

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

        // Ensure that the block is a rail
        if (Rail.isRailBlock(block)) {
            processMovement(dx, dy, dz, (BlockRail) block);
            if (block instanceof BlockRailActivator) {
                // Activate the minecart/TNT
                activate(dx, dy, dz, (block.getDamage() & 0x8) != 0);
            }
        } else {
            setFalling();
        }
        checkBlockCollision();

        // Minecart head
        pitch = 0;
        double diffX = this.lastX - this.x;
        double diffZ = this.lastZ - this.z;
        double yawToChange = yaw;
        if (diffX * diffX + diffZ * diffZ > 0.001D) {
            yawToChange = (Math.atan2(diffZ, diffX) * 180 / 3.141592653589793D);
        }

        // Reverse yaw if yaw is below 0
        if (yawToChange < 0) {
            // -90-(-90)-(-90) = 90
            yawToChange -= yawToChange - yawToChange;
        }

        setRotation(yawToChange, pitch);

        Location from = new Location(lastX, lastY, lastZ, lastYaw, lastPitch, level);
        Location to = new Location(this.x, this.y, this.z, this.yaw, this.pitch, level);

        this.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(this));

        if (!from.equals(to)) {
            this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to));
        }

        // Collisions
        for (Entity entity : level.getNearbyEntities(boundingBox.grow(0.2D, 0, 0.2D), this)) {
            if (entity != linkedEntity && entity instanceof EntityMinecartAbstract) {
                entity.applyEntityCollision(this);
            }
        }

        // Easier
        if ((linkedEntity != null) && (!linkedEntity.isAlive())) {
            if (linkedEntity.riding == this) {
                linkedEntity.riding = null;
            }
            linkedEntity = null;
        }
        // No need to onGround or Motion diff! This always have an update
        return true;
    }
    return false;
}
 
Example #28
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 #29
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 #30
Source File: EntityMinecartAbstract.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private Vector3 getNextRail(double dx, double dy, double dz) {
    int checkX = MathHelper.floor(dx);
    int checkY = MathHelper.floor(dy);
    int checkZ = MathHelper.floor(dz);

    if (Rail.isRailBlock(level.getBlockIdAt(checkX, checkY - 1, checkZ))) {
        --checkY;
    }

    Block block = level.getBlock(new Vector3(checkX, checkY, checkZ));

    if (Rail.isRailBlock(block)) {
        int[][] facing = matrix[((BlockRail) block).getRealMeta()];
        double rail;
        // Genisys mistake (Doesn't check surrounding more exactly)
        double nextOne = (double) checkX + 0.5D + (double) facing[0][0] * 0.5D;
        double nextTwo = (double) checkY + 0.5D + (double) facing[0][1] * 0.5D;
        double nextThree = (double) checkZ + 0.5D + (double) facing[0][2] * 0.5D;
        double nextFour = (double) checkX + 0.5D + (double) facing[1][0] * 0.5D;
        double nextFive = (double) checkY + 0.5D + (double) facing[1][1] * 0.5D;
        double nextSix = (double) checkZ + 0.5D + (double) facing[1][2] * 0.5D;
        double nextSeven = nextFour - nextOne;
        double nextEight = (nextFive - nextTwo) * 2;
        double nextMax = nextSix - nextThree;

        if (nextSeven == 0) {
            rail = dz - (double) checkZ;
        } else if (nextMax == 0) {
            rail = dx - (double) checkX;
        } else {
            double whatOne = dx - nextOne;
            double whatTwo = dz - nextThree;

            rail = (whatOne * nextSeven + whatTwo * nextMax) * 2;
        }

        dx = nextOne + nextSeven * rail;
        dy = nextTwo + nextEight * rail;
        dz = nextThree + nextMax * rail;
        if (nextEight < 0) {
            ++dy;
        }

        if (nextEight > 0) {
            dy += 0.5D;
        }

        return new Vector3(dx, dy, dz);
    } else {
        return null;
    }
}