Java Code Examples for cn.nukkit.level.ChunkManager#getBlockIdAt()
The following examples show how to use
cn.nukkit.level.ChunkManager#getBlockIdAt() .
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: HugeTreesGenerator.java From Nukkit with GNU General Public License v3.0 | 6 votes |
protected void growLeavesLayerStrict(ChunkManager worldIn, Vector3 layerCenter, int width) { int i = width * width; for (int j = -width; j <= width + 1; ++j) { for (int k = -width; k <= width + 1; ++k) { int l = j - 1; int i1 = k - 1; if (j * j + k * k <= i || l * l + i1 * i1 <= i || j * j + i1 * i1 <= i || l * l + k * k <= i) { Vector3 blockpos = layerCenter.add(j, 0, k); int id = worldIn.getBlockIdAt((int) blockpos.x, (int) blockpos.y, (int) blockpos.z); if (id == Block.AIR || id == Block.LEAVES) { this.setBlockAndNotifyAdequately(worldIn, blockpos, this.leavesMetadata); } } } } }
Example 2
Source File: HugeTreesGenerator.java From Jupiter with GNU General Public License v3.0 | 6 votes |
/** * grow leaves in a circle */ protected void growLeavesLayer(ChunkManager worldIn, Vector3 layerCenter, int width) { int i = width * width; for (int j = -width; j <= width; ++j) { for (int k = -width; k <= width; ++k) { if (j * j + k * k <= i) { Vector3 blockpos = layerCenter.add(j, 0, k); int id = worldIn.getBlockIdAt((int) blockpos.x, (int) blockpos.y, (int) blockpos.z); if (id == Block.AIR || id == Block.LEAVES) { this.setBlockAndNotifyAdequately(worldIn, blockpos, this.leavesMetadata); } } } } }
Example 3
Source File: ObjectTree.java From Jupiter 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.setBlockIdAt(xx, yy, zz, this.getLeafBlock()); level.setBlockDataAt(xx, yy, zz, this.getType()); } } } } }
Example 4
Source File: ObjectTallGrass.java From Jupiter with GNU General Public License v3.0 | 6 votes |
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: HugeTreesGenerator.java From Nukkit with GNU General Public License v3.0 | 6 votes |
/** * grow leaves in a circle with the outsides being within the circle */ protected void growLeavesLayerStrict(ChunkManager worldIn, Vector3 layerCenter, int width) { int i = width * width; for (int j = -width; j <= width + 1; ++j) { for (int k = -width; k <= width + 1; ++k) { int l = j - 1; int i1 = k - 1; if (j * j + k * k <= i || l * l + i1 * i1 <= i || j * j + i1 * i1 <= i || l * l + k * k <= i) { Vector3 blockpos = layerCenter.add(j, 0, k); int id = worldIn.getBlockIdAt((int) blockpos.x, (int) blockpos.y, (int) blockpos.z); if (id == Block.AIR || id == Block.LEAVES) { this.setBlockAndNotifyAdequately(worldIn, blockpos, this.leavesMetadata); } } } } }
Example 6
Source File: HugeTreesGenerator.java From Nukkit with GNU General Public License v3.0 | 6 votes |
protected void growLeavesLayer(ChunkManager worldIn, Vector3 layerCenter, int width) { int i = width * width; for (int j = -width; j <= width; ++j) { for (int k = -width; k <= width; ++k) { if (j * j + k * k <= i) { Vector3 blockpos = layerCenter.add(j, 0, k); int id = worldIn.getBlockIdAt((int) blockpos.x, (int) blockpos.y, (int) blockpos.z); if (id == Block.AIR || id == Block.LEAVES) { this.setBlockAndNotifyAdequately(worldIn, blockpos, this.leavesMetadata); } } } } }
Example 7
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 8
Source File: ObjectSwampTree.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void addHangingVine(ChunkManager worldIn, BlockVector3 pos, int meta) { this.addVine(worldIn, pos, meta); int i = 4; for (pos = pos.down(); i > 0 && worldIn.getBlockIdAt(pos.x, pos.y, pos.z) == Block.AIR; --i) { this.addVine(worldIn, pos, meta); pos = pos.down(); } }
Example 9
Source File: ObjectDarkOakTree.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void placeLeafAt(ChunkManager worldIn, int x, int y, int z) { Vector3 blockpos = new Vector3(x, y, z); int material = worldIn.getBlockIdAt(blockpos.getFloorX(), blockpos.getFloorY(), blockpos.getFloorZ()); if (material == Block.AIR) { this.setBlockAndNotifyAdequately(worldIn, blockpos, DARK_OAK_LEAVES); } }
Example 10
Source File: HugeTreesGenerator.java From Nukkit with GNU General Public License v3.0 | 5 votes |
/** * returns whether or not there is dirt underneath the block where the tree will be grown. * It also generates dirt around the block in a 2x2 square if there is dirt underneath the blockpos. */ private boolean ensureDirtsUnderneath(Vector3 pos, ChunkManager worldIn) { Vector3 blockpos = pos.down(); int block = worldIn.getBlockIdAt((int) blockpos.x, (int) blockpos.y, (int) blockpos.z); if ((block == Block.GRASS || block == Block.DIRT) && pos.getY() >= 2) { this.setDirtAt(worldIn, blockpos); this.setDirtAt(worldIn, blockpos.east()); this.setDirtAt(worldIn, blockpos.south()); this.setDirtAt(worldIn, blockpos.south().east()); return true; } else { return false; } }
Example 11
Source File: NewJungleTree.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void addHangingVine(ChunkManager worldIn, BlockVector3 pos, int meta) { this.addVine(worldIn, pos, meta); int i = 4; for (pos = pos.down(); i > 0 && worldIn.getBlockIdAt(pos.x, pos.y, pos.z) == Block.AIR; --i) { this.addVine(worldIn, pos, meta); pos = pos.down(); } }
Example 12
Source File: ObjectDarkOakTree.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void placeLeafAt(ChunkManager worldIn, int x, int y, int z) { Vector3 blockpos = new Vector3(x, y, z); int material = worldIn.getBlockIdAt(blockpos.getFloorX(), blockpos.getFloorY(), blockpos.getFloorZ()); if (material == Block.AIR) { this.setBlockAndNotifyAdequately(worldIn, blockpos, DARK_OAK_LEAVES); } }
Example 13
Source File: ObjectSwampTree.java From Jupiter with GNU General Public License v3.0 | 5 votes |
private void addHangingVine(ChunkManager worldIn, BlockVector3 pos, int meta) { this.addVine(worldIn, pos, meta); int i = 4; for (pos = pos.down(); i > 0 && worldIn.getBlockIdAt(pos.x, pos.y, pos.z) == Block.AIR; --i) { this.addVine(worldIn, pos, meta); pos = pos.down(); } }
Example 14
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 15
Source File: ObjectDarkOakTree.java From Jupiter with GNU General Public License v3.0 | 5 votes |
private void placeLeafAt(ChunkManager worldIn, int x, int y, int z) { Vector3 blockpos = new Vector3(x, y, z); int material = worldIn.getBlockIdAt(blockpos.getFloorX(), blockpos.getFloorY(), blockpos.getFloorZ()); if (material == Block.AIR) { this.setBlockAndNotifyAdequately(worldIn, blockpos, DARK_OAK_LEAVES); } }
Example 16
Source File: ObjectTree.java From Jupiter 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.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 17
Source File: TreeGenerator.java From Nukkit with GNU General Public License v3.0 | 4 votes |
protected void setDirtAt(ChunkManager level, Vector3 pos) { if (level.getBlockIdAt((int) pos.x, (int) pos.y, (int) pos.z) != Item.DIRT) { this.setBlockAndNotifyAdequately(level, pos, Block.get(BlockID.DIRT)); } }
Example 18
Source File: TreeGenerator.java From Jupiter with GNU General Public License v3.0 | 4 votes |
/** * sets dirt at a specific location if it isn't already dirt */ protected void setDirtAt(ChunkManager level, Vector3 pos) { if (level.getBlockIdAt((int) pos.x, (int) pos.y, (int) pos.z) != Item.DIRT) { this.setBlockAndNotifyAdequately(level, pos, new BlockDirt()); } }
Example 19
Source File: ObjectSpruceTree.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@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 20
Source File: ObjectJungleBigTree.java From Nukkit with GNU General Public License v3.0 | 4 votes |
private void placeVine(ChunkManager level, NukkitRandom random, Vector3 pos, int meta) { if (random.nextBoundedInt(3) > 0 && level.getBlockIdAt((int) pos.x, (int) pos.y, (int) pos.z) == 0) { this.setBlockAndNotifyAdequately(level, pos, new BlockVine(meta)); } }