/** * Updates all block states contained in the BlockState list. */ public void updateBlockStates() { for (BlockState state : blockStateMap.values()) { state.update(true); } blockStateMap.clear(); }
/** * Roll-back previously backed-up block states. */ public void rollbackBlockStates() { for (BlockState state : blockStateBackupMap.values()) { state.update(true); } blockStateBackupMap.clear(); }
@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); } } } } }
@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); } } } }
@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; } }
/** * Spawn the portal and call the {@link EntityCreatePortalEvent}. */ private void createPortal(GlowPlayer player, GlowBlock center) { List<BlockState> blocks = new ArrayList<>(9); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { BlockState state = center.getRelative(i, 0, j).getState(); state.setType(Material.ENDER_PORTAL); blocks.add(state); } } if (!EventFactory.getInstance() .callEvent(new EntityCreatePortalEvent(player, blocks, PortalType.ENDER)) .isCancelled()) { for (BlockState state : blocks) { state.update(true); } } } }
state.setType(Material.DEAD_BUSH); state.setData(new LongGrass(GrassSpecies.DEAD)); state.update(true); break;
@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; } }
@Override public void grow(GlowPlayer player, GlowBlock block) { TreeType type; if (mushroomType == Material.BROWN_MUSHROOM) { type = TreeType.BROWN_MUSHROOM; } else if (mushroomType == Material.RED_MUSHROOM) { type = TreeType.RED_MUSHROOM; } else { return; } Location loc = block.getLocation(); BlockStateDelegate blockStateDelegate = new BlockStateDelegate(); if (GlowTree.newInstance(type, ThreadLocalRandom.current(), blockStateDelegate) .generate(loc)) { List<BlockState> blockStates = new ArrayList<>(blockStateDelegate.getBlockStates()); StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, true, player, blockStates); EventFactory.getInstance().callEvent(growEvent); if (!growEvent.isCancelled()) { for (BlockState state : blockStates) { state.update(true); } } } }
BlockState state = block.getState(); state.setType(Material.LAVA); state.update(true); new PulseTask((GlowBlock) block, true, 1, true).startPulseTask();
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; } } } } } }
private void setBlockOnFire(GlowBlock block) { if (block.isEmpty() && block.getRelative(BlockFace.DOWN).isFlammable()) { BlockIgniteEvent igniteEvent = new BlockIgniteEvent(block, IgniteCause.LIGHTNING, this); EventFactory.getInstance().callEvent(igniteEvent); if (!igniteEvent.isCancelled()) { BlockState state = block.getState(); state.setType(Material.FIRE); state.update(true); } } }
@Override public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) { BlockStateDelegate blockStateDelegate = new BlockStateDelegate(); if (GlowTree.newInstance(type, ThreadLocalRandom.current(), blockStateDelegate) .generate(loc)) { List<BlockState> blockStates = new ArrayList<>(blockStateDelegate.getBlockStates()); StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, false, null, blockStates); EventFactory.getInstance().callEvent(growEvent); if (!growEvent.isCancelled()) { for (BlockState state : blockStates) { state.update(true); if (delegate != null) { delegate.setTypeIdAndData(state.getX(), state.getY(), state.getZ(), state .getTypeId(), state.getRawData()); } } return true; } } return false; }
/** * 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; } }
/** * 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; }
/** * Sets the given block to a spawner for the given entity type. * * @param pos a point relative to this structure's root point * @param entityType the type of entity the spawner will spawn */ public void createMobSpawner(Vector pos, EntityType entityType) { 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(Material.MOB_SPAWNER); state.update(true); state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState(); if (state instanceof CreatureSpawner) { ((CreatureSpawner) state).setSpawnedType(entityType); } } }