Java Code Examples for cn.nukkit.level.ChunkManager#setBlockDataAt()

The following examples show how to use cn.nukkit.level.ChunkManager#setBlockDataAt() . 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: ObjectTree.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public void placeObject(ChunkManager level, int x, int y, int z, NukkitRandom random) {

        this.placeTrunk(level, x, y, z, random, this.getTreeHeight() - 1);

        for (int yy = y - 3 + this.getTreeHeight(); yy <= y + this.getTreeHeight(); ++yy) {
            double yOff = yy - (y + this.getTreeHeight());
            int mid = (int) (1 - yOff / 2);
            for (int xx = x - mid; xx <= x + mid; ++xx) {
                int xOff = Math.abs(xx - x);
                for (int zz = z - mid; zz <= z + mid; ++zz) {
                    int zOff = Math.abs(zz - z);
                    if (xOff == mid && zOff == mid && (yOff == 0 || random.nextBoundedInt(2) == 0)) {
                        continue;
                    }
                    if (!Block.solid[level.getBlockIdAt(xx, yy, zz)]) {

                        level.setBlockIdAt(xx, yy, zz, this.getLeafBlock());
                        level.setBlockDataAt(xx, yy, zz, this.getType());
                    }
                }
            }
        }
    }
 
Example 2
Source File: ObjectTallGrass.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public static void growGrass(ChunkManager level, Vector3 pos, NukkitRandom random, int count, int radius) {
    int[][] arr = {
            {Block.DANDELION, 0},
            {Block.POPPY, 0},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1}
    };
    int arrC = arr.length - 1;
    for (int c = 0; c < count; c++) {
        int x = random.nextRange((int) (pos.x - radius), (int) (pos.x + radius));
        int z = random.nextRange((int) (pos.z) - radius, (int) (pos.z + radius));

        if (level.getBlockIdAt(x, (int) (pos.y + 1), z) == Block.AIR && level.getBlockIdAt(x, (int) (pos.y), z) == Block.GRASS) {
            int[] t = arr[random.nextRange(0, arrC)];
            level.setBlockIdAt(x, (int) (pos.y + 1), z, t[0]);
            level.setBlockDataAt(x, (int) (pos.y + 1), z, t[1]);
        }
    }
}
 
Example 3
Source File: ObjectTree.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void placeObject(ChunkManager level, int x, int y, int z, NukkitRandom random) {

        this.placeTrunk(level, x, y, z, random, this.getTreeHeight() - 1);

        for (int yy = y - 3 + this.getTreeHeight(); yy <= y + this.getTreeHeight(); ++yy) {
            double yOff = yy - (y + this.getTreeHeight());
            int mid = (int) (1 - yOff / 2);
            for (int xx = x - mid; xx <= x + mid; ++xx) {
                int xOff = Math.abs(xx - x);
                for (int zz = z - mid; zz <= z + mid; ++zz) {
                    int zOff = Math.abs(zz - z);
                    if (xOff == mid && zOff == mid && (yOff == 0 || random.nextBoundedInt(2) == 0)) {
                        continue;
                    }
                    if (!Block.solid[level.getBlockIdAt(xx, yy, zz)]) {

                        level.setBlockIdAt(xx, yy, zz, this.getLeafBlock());
                        level.setBlockDataAt(xx, yy, zz, this.getType());
                    }
                }
            }
        }
    }
 
Example 4
Source File: ObjectTallGrass.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static void growGrass(ChunkManager level, Vector3 pos, NukkitRandom random, int count, int radius) {
    int[][] arr = {
            {Block.DANDELION, 0},
            {Block.POPPY, 0},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1}
    };
    int arrC = arr.length - 1;
    for (int c = 0; c < count; c++) {
        int x = random.nextRange((int) (pos.x - radius), (int) (pos.x + radius));
        int z = random.nextRange((int) (pos.z) - radius, (int) (pos.z + radius));

        if (level.getBlockIdAt(x, (int) (pos.y + 1), z) == Block.AIR && level.getBlockIdAt(x, (int) (pos.y), z) == Block.GRASS) {
            int[] t = arr[random.nextRange(0, arrC)];
            level.setBlockIdAt(x, (int) (pos.y + 1), z, t[0]);
            level.setBlockDataAt(x, (int) (pos.y + 1), z, t[1]);
        }
    }
}
 
Example 5
Source File: ObjectTree.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
protected void placeTrunk(ChunkManager level, int x, int y, int z, NukkitRandom random, int trunkHeight) {
    // The base dirt block
    level.setBlockIdAt(x, y - 1, z, Block.DIRT);

    for (int yy = 0; yy < trunkHeight; ++yy) {
        int blockId = level.getBlockIdAt(x, y + yy, z);
        if (this.overridable.containsKey(blockId)) {
            level.setBlockIdAt(x, y + yy, z, this.getTrunkBlock());
            level.setBlockDataAt(x, y + yy, z, this.getType());
        }
    }
}
 
Example 6
Source File: ObjectTree.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void placeTrunk(ChunkManager level, int x, int y, int z, NukkitRandom random, int trunkHeight) {
    // The base dirt block
    level.setBlockIdAt(x, y - 1, z, Block.DIRT);

    for (int yy = 0; yy < trunkHeight; ++yy) {
        int blockId = level.getBlockIdAt(x, y + yy, z);
        if (this.overridable(blockId)) {
            level.setBlockIdAt(x, y + yy, z, this.getTrunkBlock());
            level.setBlockDataAt(x, y + yy, z, this.getType());
        }
    }
}
 
Example 7
Source File: BasicPopulator.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
protected void setBlock(ChunkManager level, Vector3 v, Block b) {
    level.setBlockIdAt((int) v.x, (int) v.y, (int) v.z, b.getId());
    level.setBlockDataAt((int) v.x, (int) v.y, (int) v.z, b.getDamage());
}
 
Example 8
Source File: ObjectSpruceTree.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void placeObject(ChunkManager level, int x, int y, int z, NukkitRandom random) {
    this.treeHeight = random.nextBoundedInt(4) + 6;

    int topSize = this.getTreeHeight() - (1 + random.nextBoundedInt(2));
    int lRadius = 2 + random.nextBoundedInt(2);

    this.placeTrunk(level, x, y, z, random, this.getTreeHeight() - random.nextBoundedInt(3));

    int radius = random.nextBoundedInt(2);
    int maxR = 1;
    int minR = 0;

    for (int yy = 0; yy <= topSize; ++yy) {
        int yyy = y + this.treeHeight - yy;

        for (int xx = x - radius; xx <= x + radius; ++xx) {
            int xOff = Math.abs(xx - x);
            for (int zz = z - radius; zz <= z + radius; ++zz) {
                int zOff = Math.abs(zz - z);
                if (xOff == radius && zOff == radius && radius > 0) {
                    continue;
                }

                if (!Block.solid[level.getBlockIdAt(xx, yyy, zz)]) {
                    level.setBlockIdAt(xx, yyy, zz, this.getLeafBlock());
                    level.setBlockDataAt(xx, yyy, zz, this.getType());
                }
            }
        }

        if (radius >= maxR) {
            radius = minR;
            minR = 1;
            if (++maxR > lRadius) {
                maxR = lRadius;
            }
        } else {
            ++radius;
        }
    }
}
 
Example 9
Source File: ObjectOre.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public void placeObject(ChunkManager level, int x, int y, int z) {
    int clusterSize = this.type.clusterSize;
    double angle = this.random.nextFloat() * Math.PI;
    Vector2 offset = VectorMath.getDirection2D(angle).multiply(clusterSize).divide(8);
    double x1 = x + 8 + offset.x;
    double x2 = x + 8 - offset.x;
    double z1 = z + 8 + offset.y;
    double z2 = z + 8 - offset.y;
    double y1 = y + this.random.nextBoundedInt(3) + 2;
    double y2 = y + this.random.nextBoundedInt(3) + 2;
    for (int count = 0; count <= clusterSize; ++count) {
        double seedX = x1 + (x2 - x1) * count / clusterSize;
        double seedY = y1 + (y2 - y1) * count / clusterSize;
        double seedZ = z1 + (z2 - z1) * count / clusterSize;
        double size = ((Math.sin(count * (Math.PI / clusterSize)) + 1) * this.random.nextFloat() * clusterSize / 16 + 1) / 2;

        int startX = (int) (seedX - size);
        int startY = (int) (seedY - size);
        int startZ = (int) (seedZ - size);
        int endX = (int) (seedX + size);
        int endY = (int) (seedY + size);
        int endZ = (int) (seedZ + size);

        for (x = startX; x <= endX; ++x) {
            double sizeX = (x + 0.5 - seedX) / size;
            sizeX *= sizeX;

            if (sizeX < 1) {
                for (y = startY; y <= endY; ++y) {
                    double sizeY = (y + 0.5 - seedY) / size;
                    sizeY *= sizeY;

                    if (y > 0 && (sizeX + sizeY) < 1) {
                        for (z = startZ; z <= endZ; ++z) {
                            double sizeZ = (z + 0.5 - seedZ) / size;
                            sizeZ *= sizeZ;

                            if ((sizeX + sizeY + sizeZ) < 1 && level.getBlockIdAt(x, y, z) == replaceId) {
                                level.setBlockIdAt(x, y, z, this.type.material.getId());
                                if (this.type.material.getDamage() != 0) {
                                    level.setBlockDataAt(x, y, z, this.type.material.getDamage());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 10
Source File: BasicGenerator.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
protected void setBlock(ChunkManager level, Vector3 v, Block b) {
    level.setBlockIdAt((int) v.x, (int) v.y, (int) v.z, b.getId());
    level.setBlockDataAt((int) v.x, (int) v.y, (int) v.z, b.getDamage());
}
 
Example 11
Source File: BasicPopulator.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
protected void setBlock(ChunkManager level, Vector3 v, Block b) {
    level.setBlockIdAt((int) v.x, (int) v.y, (int) v.z, b.getId());
    level.setBlockDataAt((int) v.x, (int) v.y, (int) v.z, b.getDamage());
}
 
Example 12
Source File: ObjectSpruceTree.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void placeObject(ChunkManager level, int x, int y, int z, NukkitRandom random) {
    this.treeHeight = random.nextBoundedInt(4) + 6;

    int topSize = this.getTreeHeight() - (1 + random.nextBoundedInt(2));
    int lRadius = 2 + random.nextBoundedInt(2);

    this.placeTrunk(level, x, y, z, random, this.getTreeHeight() - random.nextBoundedInt(3));

    int radius = random.nextBoundedInt(2);
    int maxR = 1;
    int minR = 0;

    for (int yy = 0; yy <= topSize; ++yy) {
        int yyy = y + this.treeHeight - yy;

        for (int xx = x - radius; xx <= x + radius; ++xx) {
            int xOff = Math.abs(xx - x);
            for (int zz = z - radius; zz <= z + radius; ++zz) {
                int zOff = Math.abs(zz - z);
                if (xOff == radius && zOff == radius && radius > 0) {
                    continue;
                }

                if (!Block.solid[level.getBlockIdAt(xx, yyy, zz)]) {
                    level.setBlockIdAt(xx, yyy, zz, this.getLeafBlock());
                    level.setBlockDataAt(xx, yyy, zz, this.getType());
                }
            }
        }

        if (radius >= maxR) {
            radius = minR;
            minR = 1;
            if (++maxR > lRadius) {
                maxR = lRadius;
            }
        } else {
            ++radius;
        }
    }
}
 
Example 13
Source File: ObjectOre.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void placeObject(ChunkManager level, int x, int y, int z) {
    int clusterSize = this.type.clusterSize;
    double angle = this.random.nextFloat() * Math.PI;
    Vector2 offset = VectorMath.getDirection2D(angle).multiply(clusterSize).divide(8);
    double x1 = x + 8 + offset.x;
    double x2 = x + 8 - offset.x;
    double z1 = z + 8 + offset.y;
    double z2 = z + 8 - offset.y;
    double y1 = y + this.random.nextBoundedInt(3) + 2;
    double y2 = y + this.random.nextBoundedInt(3) + 2;
    for (int count = 0; count <= clusterSize; ++count) {
        double seedX = x1 + (x2 - x1) * count / clusterSize;
        double seedY = y1 + (y2 - y1) * count / clusterSize;
        double seedZ = z1 + (z2 - z1) * count / clusterSize;
        double size = ((Math.sin(count * (Math.PI / clusterSize)) + 1) * this.random.nextFloat() * clusterSize / 16 + 1) / 2;

        int startX = (int) (seedX - size);
        int startY = (int) (seedY - size);
        int startZ = (int) (seedZ - size);
        int endX = (int) (seedX + size);
        int endY = (int) (seedY + size);
        int endZ = (int) (seedZ + size);

        for (x = startX; x <= endX; ++x) {
            double sizeX = (x + 0.5 - seedX) / size;
            sizeX *= sizeX;

            if (sizeX < 1) {
                for (y = startY; y <= endY; ++y) {
                    double sizeY = (y + 0.5 - seedY) / size;
                    sizeY *= sizeY;

                    if (y > 0 && (sizeX + sizeY) < 1) {
                        for (z = startZ; z <= endZ; ++z) {
                            double sizeZ = (z + 0.5 - seedZ) / size;
                            sizeZ *= sizeZ;

                            if ((sizeX + sizeY + sizeZ) < 1 && level.getBlockIdAt(x, y, z) == replaceId) {
                                level.setBlockIdAt(x, y, z, this.type.material.getId());
                                if (this.type.material.getDamage() != 0) {
                                    level.setBlockDataAt(x, y, z, this.type.material.getDamage());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 14
Source File: BasicGenerator.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
protected void setBlock(ChunkManager level, Vector3 v, Block b) {
    level.setBlockIdAt((int) v.x, (int) v.y, (int) v.z, b.getId());
    level.setBlockDataAt((int) v.x, (int) v.y, (int) v.z, b.getDamage());
}