@Override public void decorate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = random.nextInt(128); for (int i = 0; i < 64; i++) { int x = sourceX + random.nextInt(8) - random.nextInt(8); int z = sourceZ + random.nextInt(8) - random.nextInt(8); int y = sourceY + random.nextInt(4) - random.nextInt(4); Block block = world.getBlockAt(x, y, z); Block blockBelow = world.getBlockAt(x, y - 1, z); if (y < 128 && block.getType() == Material.AIR && Arrays.asList(MATERIALS) .contains(blockBelow.getType())) { BlockState state = block.getState(); state.setType(type); state.setData(new MaterialData(type)); state.update(true); } } } }
@Override public void decorate(World world, Random random, Chunk source) { int amount = 1 + random.nextInt(1 + random.nextInt(10)); for (int j = 0; j < amount; j++) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = 4 + random.nextInt(120); for (int i = 0; i < 64; i++) { int x = sourceX + random.nextInt(8) - random.nextInt(8); int z = sourceZ + random.nextInt(8) - random.nextInt(8); int y = sourceY + random.nextInt(4) - random.nextInt(4); Block block = world.getBlockAt(x, y, z); Block blockBelow = world.getBlockAt(x, y - 1, z); if (y < 128 && block.getType() == Material.AIR && blockBelow.getType() == Material.NETHERRACK) { BlockState state = block.getState(); state.setType(Material.FIRE); state.setData(new MaterialData(Material.FIRE)); state.update(true); } } } } }
@Override public void populate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = random.nextInt(world.getSeaLevel() << 1); for (int i = 0; i < 64; i++) { int x = sourceX + random.nextInt(8) - random.nextInt(8); int z = sourceZ + random.nextInt(8) - random.nextInt(8); int y = sourceY + random.nextInt(4) - random.nextInt(4); if (world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y - 1, z).getType() == Material.GRASS) { BlockState state = world.getBlockAt(x, y, z).getState(); state.setType(Material.MELON_BLOCK); state.setData(new MaterialData(Material.MELON_BLOCK)); state.update(true); } } } }
@Override public void populate(World world, Random random, Chunk source) { if (random.nextInt(32) == 0) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) << 1); for (int i = 0; i < 64; i++) { int x = sourceX + random.nextInt(8) - random.nextInt(8); int z = sourceZ + random.nextInt(8) - random.nextInt(8); int y = sourceY + random.nextInt(4) - random.nextInt(4); if (world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y - 1, z).getType() == Material.GRASS) { BlockState state = world.getBlockAt(x, y, z).getState(); state.setType(Material.PUMPKIN); // random facing state.setData(new Pumpkin(FACES[random.nextInt(FACES.length)])); state.update(true); } } } } }
BlockState state = world.getBlockAt(x, y, z).getState(); state.setType(type); state.setData(data); state.update(true); succeeded = true;
@Override public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) { Block thisBlock; do { thisBlock = world.getBlockAt(sourceX, sourceY, sourceZ); sourceY--; } while ((thisBlock.isEmpty() || thisBlock.getType() == Material.LEAVES) && sourceY > 0); sourceY++; boolean succeeded = false; for (int i = 0; i < 128; i++) { int x = sourceX + random.nextInt(8) - random.nextInt(8); int z = sourceZ + random.nextInt(8) - random.nextInt(8); int y = sourceY + random.nextInt(4) - random.nextInt(4); Block block = world.getBlockAt(x, y, z); Material blockTypeBelow = block.getRelative(BlockFace.DOWN).getType(); if (y < 255 && block.getType() == Material.AIR && ( blockTypeBelow == Material.GRASS || blockTypeBelow == Material.DIRT)) { BlockState state = block.getState(); state.setType(Material.LONG_GRASS); state.setData(grassType); state.update(true); succeeded = true; } } return succeeded; } }
@Override public void decorate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) << 1); while (world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType() == Material.AIR && sourceY > 0) { sourceY--; } for (int j = 0; j < 10; j++) { int x = sourceX + random.nextInt(8) - random.nextInt(8); int z = sourceZ + random.nextInt(8) - random.nextInt(8); int y = sourceY + random.nextInt(4) - random.nextInt(4); if (y >= 0 && y <= 255 && world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y - 1, z).getType() == Material.STATIONARY_WATER) { BlockState state = world.getBlockAt(x, y, z).getState(); state.setType(Material.WATER_LILY); state.setData(new MaterialData(Material.WATER_LILY)); state.update(true); } } } }
BlockState state = block.getState(); state.setType(Material.DOUBLE_PLANT); state.setData(new DoublePlant(species)); state.update(true); state = topBlock.getState(); state.setType(Material.DOUBLE_PLANT); state.setData(new DoublePlant(DoublePlantSpecies.PLANT_APEX)); state.update(true); placed = true;
BlockState state = world.getBlockAt(x, y, z).getState(); state.setType(Material.DEAD_BUSH); state.setData(new LongGrass(GrassSpecies.DEAD)); state.update(true); break;
state.setData(new MaterialData(Material.MOSSY_COBBLESTONE)); state.update(true);
@Override public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) { boolean succeeded = false; int n = random.nextInt(horizRadius - MIN_RADIUS) + MIN_RADIUS; int nsquared = n * n; for (int x = sourceX - n; x <= sourceX + n; x++) { for (int z = sourceZ - n; z <= sourceZ + n; z++) { if ((x - sourceX) * (x - sourceX) + (z - sourceZ) * (z - sourceZ) > nsquared) { continue; } for (int y = sourceY - vertRadius; y <= sourceY + vertRadius; y++) { Block block = world.getBlockAt(x, y, z); if (!overridables.contains(block.getType())) { continue; } if (TerrainObject.killPlantAbove(block)) { break; } BlockState state = block.getState(); state.setType(type); state.setData(new MaterialData(type)); state.update(true); succeeded = true; break; } } } return succeeded; } }
BlockState state = block.getState(); state.setType(type); state.setData(new MaterialData(type)); state.update(true);
private void generatePodzolPatch(int sourceX, int sourceY, int sourceZ, World world) { for (int x = -2; x <= 2; x++) { for (int z = -2; z <= 2; z++) { if (Math.abs(x) == 2 && Math.abs(z) == 2) { continue; } for (int y = 2; y >= -3; y--) { Block block = world .getBlockAt(sourceX + x, sourceY + y, sourceZ + z); if (block.getType() == Material.GRASS || block.getType() == Material.DIRT) { BlockState state = block.getState(); state.setType(Material.DIRT); DirtType dirtType = DirtType.PODZOL; if (world.getBlockAt(sourceX + x, sourceY + y + 1, sourceZ + z) .getType().isOccluding()) { dirtType = DirtType.NORMAL; } state.setData(new Dirt(dirtType)); state.update(true); } else if (!block.isEmpty() && sourceY + y < sourceY) { break; } } } } } }
/** * Generates or extends a cactus, if there is space. */ @Override public boolean generate(World world, Random random, int x, int y, int z) { if (world.getBlockAt(x, y, z).isEmpty()) { int height = random.nextInt(random.nextInt(3) + 1) + 1; for (int n = y; n < y + height; n++) { Block block = world.getBlockAt(x, n, z); Material typeBelow = block.getRelative(BlockFace.DOWN).getType(); if ((typeBelow == Material.SAND || typeBelow == Material.CACTUS) && block.getRelative(BlockFace.UP).isEmpty()) { for (BlockFace face : FACES) { if (block.getRelative(face).getType().isSolid()) { return n > y; } } BlockState state = block.getState(); state.setType(Material.CACTUS); state.setData(new MaterialData(Material.CACTUS)); state.update(true); } } } return true; } }
otherPartState.setData(otherChest); otherPartState.update(); } else {
/** * Sets the given block to a container and fills it with random items. * * @param pos a point relative to this structure's root point * @param random the PRNG to use * @param content the distribution to draw items from * @param container the container to place * @param maxStacks the maximum number of slots to fill * @return true if the container was placed and filled; false if {@code pos} is outside the * builder's bounding box or {@link RandomItemsContent#fillContainer(Random, BlockState, * int)} fails */ public boolean createRandomItemsContainer(Vector pos, Random random, RandomItemsContent content, DirectionalContainer container, int maxStacks) { Vector vec = translate(pos); if (boundingBox.isVectorInside(vec)) { BlockState state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()) .getState(); delegate.backupBlockState(state.getBlock()); state.setType(container.getItemType()); state.setData(container); state.update(true); return content.fillContainer(random, state, maxStacks); } return false; }
state.setData(new MaterialData(Material.SUGAR_CANE_BLOCK)); state.update(true);
@Override public void setData(final MaterialData data) { base.setData(data); }
Block block = ....; BlockState state = block.getState(); PistonBaseMaterial piston = (PistonBaseMaterial)state.getData(); piston.setFacingDirection(BlockFace.NORTH); piston.setFacingDirection(BlockFace.SOUTH); piston.setFacingDirection(BlockFace.WEST); piston.setFacingDirection(BlockFace.EAST); piston.setFacingDirection(BlockFace.UP); piston.setFacingDirection(BlockFace.DOWN); state.setData(piston); state.update();
@Override public void run(NPC npc, Block point, ListIterator<Block> path) { BlockState state = point.getState(); Door door = (Door) state.getData(); if (npc.getStoredLocation().distance(point.getLocation()) < 2) { boolean bottom = !door.isTopHalf(); Block set = bottom ? point : point.getRelative(BlockFace.DOWN); state = set.getState(); door = (Door) state.getData(); door.setOpen(true); state.setData(door); state.update(); } } }