Java Code Examples for cn.nukkit.level.ChunkManager#setBlockAt()
The following examples show how to use
cn.nukkit.level.ChunkManager#setBlockAt() .
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 Nukkit with GNU General Public License v3.0 | 6 votes |
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.setBlockAt(xx, yy, zz, this.getLeafBlock(), this.getType()); } } } } }
Example 2
Source File: ObjectBigSpruceTree.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override protected void placeTrunk(ChunkManager level, int x, int y, int z, NukkitRandom random, int trunkHeight) { // The base dirt block level.setBlockAt(x, y - 1, z, Block.DIRT); int radius = 2; for (int yy = 0; yy < trunkHeight; ++yy) { for (int xx = 0; xx < radius; xx++) { for (int zz = 0; zz < radius; zz++) { int blockId = level.getBlockIdAt(x, y + yy, z); if (this.overridable(blockId)) { level.setBlockAt(x + xx, y + yy, z + zz, this.getTrunkBlock(), this.getType()); } } } } }
Example 3
Source File: PopulatorGlowStone.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) { int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15); int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15); int y = this.getHighestWorkableBlock(chunk, x & 0xF, z & 0xF); if (y != -1 && level.getBlockIdAt(x, y, z) != NETHERRACK) { int count = NukkitMath.randomRange(random, 40, 60); for (int i = 0; i < count; i++) { level.setBlockAt(x + (random.nextBoundedInt(7) - 3), y + (random.nextBoundedInt(9) - 4), z + (random.nextBoundedInt(7) - 3), GLOWSTONE); } } }
Example 4
Source File: ObjectTree.java From Nukkit with GNU General Public License v3.0 | 5 votes |
protected void placeTrunk(ChunkManager level, int x, int y, int z, NukkitRandom random, int trunkHeight) { // The base dirt block level.setBlockAt(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.setBlockAt(x, y + yy, z, this.getTrunkBlock(), this.getType()); } } }
Example 5
Source File: ObjectSpruceTree.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public void placeLeaves(ChunkManager level, int topSize, int lRadius, int x, int y, int z, NukkitRandom random) { 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.setBlockAt(xx, yyy, zz, this.getLeafBlock(), this.getType()); } } } if (radius >= maxR) { radius = minR; minR = 1; if (++maxR > lRadius) { maxR = lRadius; } } else { ++radius; } } }
Example 6
Source File: ObjectTallGrass.java From Nukkit with GNU General Public License v3.0 | 5 votes |
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 7
Source File: BasicGenerator.java From Nukkit with GNU General Public License v3.0 | 4 votes |
protected void setBlock(ChunkManager level, Vector3 v, Block b) { level.setBlockAt((int) v.x, (int) v.y, (int) v.z, b.getId(), b.getDamage()); }
Example 8
Source File: IcePlainsSpikesBiome.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) { for (int i = 0; i < 8; i++) { int x = (chunkX << 4) + random.nextBoundedInt(16); int z = (chunkZ << 4) + random.nextBoundedInt(16); boolean isTall = random.nextBoundedInt(16) == 0; int height = 10 + random.nextBoundedInt(16) + (isTall ? random.nextBoundedInt(31) : 0); int startY = getHighestWorkableBlock(x, z, chunk); int maxY = startY + height; if (isTall) { for (int y = startY; y < maxY; y++) { //center column level.setBlockAt(x, y, z, PACKED_ICE); //t shape level.setBlockAt(x + 1, y, z, PACKED_ICE); level.setBlockAt(x - 1, y, z, PACKED_ICE); level.setBlockAt(x, y, z + 1, PACKED_ICE); level.setBlockAt(x, y, z - 1, PACKED_ICE); //additional blocks on the side if (random.nextBoolean()) { level.setBlockAt(x + 1, y, z + 1, PACKED_ICE); } if (random.nextBoolean()) { level.setBlockAt(x + 1, y, z - 1, PACKED_ICE); } if (random.nextBoolean()) { level.setBlockAt(x - 1, y, z + 1, PACKED_ICE); } if (random.nextBoolean()) { level.setBlockAt(x - 1, y, z - 1, PACKED_ICE); } } //finish with a point level.setBlockAt(x + 1, maxY, z, PACKED_ICE); level.setBlockAt(x - 1, maxY, z, PACKED_ICE); level.setBlockAt(x, maxY, z + 1, PACKED_ICE); level.setBlockAt(x, maxY, z - 1, PACKED_ICE); for (int y = maxY; y < maxY + 3; y++) { level.setBlockAt(x, y, z, PACKED_ICE); } } else { //the maximum possible radius in blocks int baseWidth = random.nextBoundedInt(1) + 4; float shrinkFactor = baseWidth / (float) height; float currWidth = baseWidth; for (int y = startY; y < maxY; y++) { for (int xx = (int) -currWidth; xx < currWidth; xx++) { for (int zz = (int) -currWidth; zz < currWidth; zz++) { int currDist = (int) Math.sqrt(xx * xx + zz * zz); if ((int) currWidth != currDist && random.nextBoolean()) { level.setBlockAt(x + xx, y, z + zz, PACKED_ICE); } } } currWidth -= shrinkFactor; } } } }