@Override public BlockData getBlockData(int x, int y, int z) { return BukkitAdapter.adapt(editSession.getBlock(BlockVector3.at(x, y, z))); }
private void recurseHollow(Region region, BlockVector3 origin, Set<BlockVector3> outside) { final LinkedList<BlockVector3> queue = new LinkedList<>(); queue.addLast(origin); while (!queue.isEmpty()) { final BlockVector3 current = queue.removeFirst(); final BlockState block = getBlock(current); if (block.getBlockType().getMaterial().isMovementBlocker()) { continue; } if (!outside.add(current)) { continue; } if (!region.contains(current)) { continue; } for (BlockVector3 recurseDirection : recurseDirections) { queue.addLast(current.add(recurseDirection)); } } }
@Override public int getBlockType(double x, double y, double z) { return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId(); }
@Override public int getBlockTypeAbs(double x, double y, double z) { return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId(); }
@Override public int getBlockTypeRel(double x, double y, double z) { return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId(); }
/** * Set a block only if there's no block already there. * * @param position the position * @param block the block to set * @return if block was changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ private static <B extends BlockStateHolder<B>> boolean setBlockIfAir(EditSession session, BlockVector3 position, B block) throws MaxChangedBlocksException { return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block); }
/** * Set a block only if there's no block already there. * * @param position the position * @param block the block to set * @return if block was changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ private static <B extends BlockStateHolder<B>> boolean setBlockIfAir(EditSession session, BlockVector3 position, B block) throws MaxChangedBlocksException { return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block); } }
@Override public boolean isEmpty(int x, int y, int z) { return editSession.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isAir(); }
/** * Returns the highest solid 'terrain' block. * * @param x the X coordinate * @param z the Z coordinate * @param minY minimal height * @param maxY maximal height * @return height of highest block found or 'minY' */ public int getHighestTerrainBlock(int x, int z, int minY, int maxY) { for (int y = maxY; y >= minY; --y) { BlockVector3 pt = BlockVector3.at(x, y, z); BlockState block = getBlock(pt); if (block.getBlockType().getMaterial().isMovementBlocker()) { return y; } } return minY; }
@Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { final double startY = fullHeight ? editSession.getWorld().getMaxY() : position.getBlockY() + size; for (double x = position.getBlockX() + size; x > position.getBlockX() - size; --x) { for (double z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) { double y = startY; final List<BlockState> blockTypes = new ArrayList<>(); for (; y > position.getBlockY() - size; --y) { final BlockVector3 pt = BlockVector3.at(x, y, z); final BlockState block = editSession.getBlock(pt); if (!block.getBlockType().getMaterial().isAir()) { blockTypes.add(block); editSession.setBlock(pt, BlockTypes.AIR.getDefaultState()); } } BlockVector3 pt = BlockVector3.at(x, y, z); Collections.reverse(blockTypes); for (int i = 0; i < blockTypes.size();) { if (editSession.getBlock(pt).getBlockType().getMaterial().isAir()) { editSession.setBlock(pt, blockTypes.get(i++)); } pt = pt.add(0, 1, 0); } } } }
@Override public boolean apply(BlockVector3 position) throws WorldEditException { if (!editSession.getBlock(position).getBlockType().getMaterial().isAir()) { position = position.add(0, 1, 0); } if (editSession.getBlock(position.add(0, -1, 0)).getBlockType() != BlockTypes.GRASS_BLOCK) { return false; } BlockState leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState(); if (editSession.getBlock(position).getBlockType().getMaterial().isAir()) { editSession.setBlock(position, leavesBlock); } placeVine(position, position.add(0, 0, 1)); placeVine(position, position.add(0, 0, -1)); placeVine(position, position.add(1, 0, 0)); placeVine(position, position.add(-1, 0, 0)); return true; }
@Override public boolean apply(BlockVector3 position) throws WorldEditException { BlockState block = editSession.getBlock(position); if (block.getBlockType() == BlockTypes.GRASS_BLOCK) { editSession.setBlock(position.add(0, 1, 0), temperatePattern.apply(position)); return true; } else if (block.getBlockType() == BlockTypes.SAND) { editSession.setBlock(position.add(0, 1, 0), desertPattern.apply(position)); return true; } return false; }
@Override public boolean apply(BlockVector3 position) throws WorldEditException { BlockState block = editSession.getBlock(position); BlockType t = block.getBlockType(); if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT) { treeType.generate(editSession, position.add(0, 1, 0)); return true; } else if (t == BlockTypes.GRASS || t == BlockTypes.DEAD_BUSH || t == BlockTypes.POPPY || t == BlockTypes.DANDELION) { // TODO: This list needs to be moved editSession.setBlock(position, BlockTypes.AIR.getDefaultState()); treeType.generate(editSession, position); return true; } else if (t == BlockTypes.SNOW) { editSession.setBlock(position, BlockTypes.AIR.getDefaultState()); return false; } else { // Trees won't grow on this! return false; } } }
private void recurse(EditSession editSession, BlockVector3 pos, BlockVector3 origin, int size, BlockType initialType, Set<BlockVector3> visited) throws MaxChangedBlocksException { if (origin.distance(pos) > size || visited.contains(pos)) { return; } visited.add(pos); if (editSession.getBlock(pos).getBlockType() == initialType) { editSession.setBlock(pos, pattern.apply(pos)); } else { return; } recurse(editSession, pos.add(1, 0, 0), origin, size, initialType, visited); recurse(editSession, pos.add(-1, 0, 0), origin, size, initialType, visited); recurse(editSession, pos.add(0, 0, 1), origin, size, initialType, visited); recurse(editSession, pos.add(0, 0, -1), origin, size, initialType, visited); recurse(editSession, pos.add(0, 1, 0), origin, size, initialType, visited); recurse(editSession, pos.add(0, -1, 0), origin, size, initialType, visited); }
private static void recurse(Platform server, EditSession editSession, World world, BlockVector3 pos, BlockVector3 origin, double size, BlockType initialType, Set<BlockVector3> visited) throws MaxChangedBlocksException { final double distanceSq = origin.distanceSq(pos); if (distanceSq > size*size || visited.contains(pos)) { return; } visited.add(pos); if (editSession.getBlock(pos).getBlockType() != initialType) { return; } world.queueBlockBreakEffect(server, pos, initialType, distanceSq); editSession.setBlock(pos, BlockTypes.AIR.getDefaultState()); recurse(server, editSession, world, pos.add(1, 0, 0), origin, size, initialType, visited); recurse(server, editSession, world, pos.add(-1, 0, 0), origin, size, initialType, visited); recurse(server, editSession, world, pos.add(0, 0, 1), origin, size, initialType, visited); recurse(server, editSession, world, pos.add(0, 0, -1), origin, size, initialType, visited); recurse(server, editSession, world, pos.add(0, 1, 0), origin, size, initialType, visited); recurse(server, editSession, world, pos.add(0, -1, 0), origin, size, initialType, visited); }
+ size; ++z) { if (!getBlock(BlockVector3.at(x, basePosition.getBlockY(), z)).getBlockType().getMaterial().isAir()) { continue; BlockType t = getBlock(BlockVector3.at(x, y, z)).getBlockType(); if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT) { treeType.generate(this, BlockVector3.at(x, y + 1, z));
BlockType id = getBlock(pt).getBlockType();
final BlockState block = getBlock(pt);
@Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) { final World world = (World) clicked.getExtent(); final BlockState state = world.getBlock(clicked.toVector().toBlockPoint()); if (!isTreeBlock(state.getBlockType())) { player.printError("That's not a tree."); return true; } try (EditSession editSession = session.createEditSession(player)) { try { final Set<BlockVector3> blockSet = bfs(world, clicked.toVector().toBlockPoint()); if (blockSet == null) { player.printError("That's not a floating tree."); return true; } for (BlockVector3 blockVector : blockSet) { final BlockState otherState = editSession.getBlock(blockVector); if (isTreeBlock(otherState.getBlockType())) { editSession.setBlock(blockVector, BlockTypes.AIR.getDefaultState()); } } } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } finally { session.remember(editSession); } } return true; }
for (int z = oz - range; z <= oz + range; ++z) { BlockVector3 pos = BlockVector3.at(x, y, z); if (editSession.getBlock(pos).getBlockType() != initialType) { continue;