Java Code Examples for cn.nukkit.math.Vector3#getFloorX()

The following examples show how to use cn.nukkit.math.Vector3#getFloorX() . 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: ObjectDarkOakTree.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
private boolean placeTreeOfHeight(ChunkManager worldIn, Vector3 pos, int height) {
    int i = pos.getFloorX();
    int j = pos.getFloorY();
    int k = pos.getFloorZ();
    Vector3 blockPos = new Vector3();

    for (int l = 0; l <= height + 1; ++l) {
        int i1 = 1;

        if (l == 0) {
            i1 = 0;
        }

        if (l >= height - 1) {
            i1 = 2;
        }

        for (int j1 = -i1; j1 <= i1; ++j1) {
            for (int k1 = -i1; k1 <= i1; ++k1) {
                blockPos.setComponents(i + j1, j + l, k + k1);
                if (!this.canGrowInto(worldIn.getBlockIdAt(blockPos.getFloorX(), blockPos.getFloorY(), blockPos.getFloorZ()))) {
                    return false;
                }
            }
        }
    }

    return true;
}
 
Example 2
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void setSpawnLocation(Vector3 pos) {
    Position previousSpawn = this.getSpawnLocation();
    this.provider.setSpawn(pos);
    this.server.getPluginManager().callEvent(new SpawnChangeEvent(this, previousSpawn));
    SetSpawnPositionPacket pk = new SetSpawnPositionPacket();
    pk.spawnType = SetSpawnPositionPacket.TYPE_WORLD_SPAWN;
    pk.x = pos.getFloorX();
    pk.y = pos.getFloorY();
    pk.z = pos.getFloorZ();
    for (Player p : getPlayers().values()) p.dataPacket(pk);
}
 
Example 3
Source File: ObjectDarkOakTree.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private boolean placeTreeOfHeight(ChunkManager worldIn, Vector3 pos, int height) {
    int i = pos.getFloorX();
    int j = pos.getFloorY();
    int k = pos.getFloorZ();
    Vector3 blockPos = new Vector3();

    for (int l = 0; l <= height + 1; ++l) {
        int i1 = 1;

        if (l == 0) {
            i1 = 0;
        }

        if (l >= height - 1) {
            i1 = 2;
        }

        for (int j1 = -i1; j1 <= i1; ++j1) {
            for (int k1 = -i1; k1 <= i1; ++k1) {
                blockPos.setComponents(i + j1, j + l, k + k1);
                if (!this.canGrowInto(worldIn.getBlockIdAt(blockPos.getFloorX(), blockPos.getFloorY(), blockPos.getFloorZ()))) {
                    return false;
                }
            }
        }
    }

    return true;
}
 
Example 4
Source File: ObjectTallGrass.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static void growGrass(ChunkManager level, Vector3 pos, NukkitRandom random) {
    for (int i = 0; i < 128; ++i) {
        int num = 0;

        int x = pos.getFloorX();
        int y = pos.getFloorY() + 1;
        int z = pos.getFloorZ();

        while (true) {
            if (num >= i / 16) {
                if (level.getBlockIdAt(x, y, z) == Block.AIR) {
                    if (random.nextBoundedInt(8) == 0) {
                        //porktodo: biomes have specific flower types that can grow in them
                        if (random.nextBoolean()) {
                            level.setBlockAt(x, y, z, Block.DANDELION);
                        } else {
                            level.setBlockAt(x, y, z, Block.POPPY);
                        }
                    } else {
                        level.setBlockAt(x, y, z, Block.TALL_GRASS, 1);
                    }
                }

                break;
            }

            x += random.nextRange(-1, 1);
            y += random.nextRange(-1, 1) * random.nextBoundedInt(3) / 2;
            z += random.nextRange(-1, 1);

            if (level.getBlockIdAt(x, y - 1, z) != Block.GRASS || y > 255 || y < 0) {
                break;
            }

            ++num;
        }
    }
}
 
Example 5
Source File: ObjectDarkOakTree.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private boolean placeTreeOfHeight(ChunkManager worldIn, Vector3 pos, int height) {
    int i = pos.getFloorX();
    int j = pos.getFloorY();
    int k = pos.getFloorZ();
    Vector3 blockPos = new Vector3();

    for (int l = 0; l <= height + 1; ++l) {
        int i1 = 1;

        if (l == 0) {
            i1 = 0;
        }

        if (l >= height - 1) {
            i1 = 2;
        }

        for (int j1 = -i1; j1 <= i1; ++j1) {
            for (int k1 = -i1; k1 <= i1; ++k1) {
                blockPos.setComponents(i + j1, j + l, k + k1);
                if (!this.canGrowInto(worldIn.getBlockIdAt(blockPos.getFloorX(), blockPos.getFloorY(), blockPos.getFloorZ()))) {
                    return false;
                }
            }
        }
    }

    return true;
}
 
Example 6
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 7
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 8
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 9
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 10
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 11
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);
}