/** * 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); }
/** * Performs a redo * * @param newBlockBag a new block bag * @param player the player * @return whether anything was redone */ public EditSession redo(@Nullable BlockBag newBlockBag, Player player) { checkNotNull(player); if (historyPointer < history.size()) { EditSession editSession = history.get(historyPointer); try (EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory() .getEditSession(editSession.getWorld(), -1, newBlockBag, player)) { newEditSession.enableStandardMode(); newEditSession.setReorderMode(reorderMode); newEditSession.setFastMode(fastMode); editSession.redo(newEditSession); } ++historyPointer; return editSession; } return null; }
/** * Disable the queue. This will {@linkplain #flushSession() flush the session}. * * @deprecated Use {@link EditSession#setReorderMode(ReorderMode)} with another mode instead. */ @Deprecated public void disableQueue() { if (isQueueEnabled()) { flushSession(); } setReorderMode(ReorderMode.NONE); }
/** * Disable all buffering extents. * * @see #setReorderMode(ReorderMode) * @see #setBatchingChunks(boolean) */ public void disableBuffering() { // We optimize here to avoid repeated calls to flushSession. if (commitRequired()) { flushSession(); } setReorderMode(ReorderMode.NONE); if (chunkBatchingExtent != null) { chunkBatchingExtent.setEnabled(false); } }
/** * Enable or disable chunk batching. Disabling will * {@linkplain #flushSession() flush the session}. * * @param batchingChunks {@code true} to enable, {@code false} to disable */ public void setBatchingChunks(boolean batchingChunks) { if (chunkBatchingExtent == null) { if (batchingChunks) { throw new UnsupportedOperationException("Chunk batching not supported by this session."); } return; } if (!batchingChunks && isBatchingChunks()) { flushSession(); } chunkBatchingExtent.setEnabled(batchingChunks); }
/** * Set blocks that are in a set of positions and return the number of times * that the block set calls returned true. * * @param vset a set of positions * @param pattern the pattern * @return the number of changed blocks * @throws MaxChangedBlocksException thrown if too many blocks are changed */ private int setBlocks(Set<BlockVector3> vset, Pattern pattern) throws MaxChangedBlocksException { int affected = 0; for (BlockVector3 v : vset) { affected += setBlock(v, pattern) ? 1 : 0; } return affected; }
@Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) { Location pos = getTargetFace(player); if (pos == null) return false; try (EditSession eS = session.createEditSession(player)) { eS.disableBuffering(); BlockVector3 blockPoint = pos.toVector().toBlockPoint(); BaseBlock applied = primary.apply(blockPoint); if (applied.getBlockType().getMaterial().isAir()) { eS.setBlock(blockPoint, primary); } else { eS.setBlock(pos.getDirection().toBlockPoint(), primary); } return true; } catch (MaxChangedBlocksException e) { // one block? eat it } return false; }
@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); } } } }
/** * Performs an undo. * * @param newBlockBag a new block bag * @param player the player * @return whether anything was undone */ public EditSession undo(@Nullable BlockBag newBlockBag, Player player) { checkNotNull(player); --historyPointer; if (historyPointer >= 0) { EditSession editSession = history.get(historyPointer); try (EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory() .getEditSession(editSession.getWorld(), -1, newBlockBag, player)) { newEditSession.enableStandardMode(); newEditSession.setReorderMode(reorderMode); newEditSession.setFastMode(fastMode); editSession.undo(newEditSession); } return editSession; } else { historyPointer = 0; return null; } }
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop); for (int z = oz - range; z <= oz + range; ++z) { BlockVector3 pos = BlockVector3.at(x, y, z); if (editSession.getBlock(pos).getBlockType() != initialType) { continue; editSession.setBlock(pos, BlockTypes.AIR.getDefaultState());
double distanceSq = lengthSq(xn, yn, zn); if (distanceSq > 1) { if (z == 0) { if (lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 && lengthSq(xn, yn, nextZn) <= 1) { continue; if (setBlock(pos.add(x, y, z), block)) { ++affected; if (setBlock(pos.add(-x, y, z), block)) { ++affected; if (setBlock(pos.add(x, -y, z), block)) { ++affected; if (setBlock(pos.add(x, y, -z), block)) { ++affected; if (setBlock(pos.add(-x, -y, z), block)) { ++affected; if (setBlock(pos.add(x, -y, -z), block)) { ++affected; if (setBlock(pos.add(-x, y, -z), block)) { ++affected; if (setBlock(pos.add(-x, -y, -z), block)) {
/** * Remove a cuboid above the given position with a given apothem and a given height. * * @param position base position * @param apothem an apothem of the cuboid (on the XZ plane), where the minimum is 1 * @param height the height of the cuboid, where the minimum is 1 * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public int removeAbove(BlockVector3 position, int apothem, int height) throws MaxChangedBlocksException { checkNotNull(position); checkArgument(apothem >= 1, "apothem >= 1"); checkArgument(height >= 1, "height >= 1"); Region region = new CuboidRegion( getWorld(), // Causes clamping of Y range position.add(-apothem + 1, 0, -apothem + 1), position.add(apothem - 1, height - 1, apothem - 1)); Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); return setBlocks(region, pattern); }
@Override public BlockVector3 getMaximumPoint() { return getWorld().getMaximumPoint(); }
@Override public BlockData getBlockData(int x, int y, int z) { return BukkitAdapter.adapt(editSession.getBlock(BlockVector3.at(x, y, z))); }
vset = getBallooned(vset, radius); if (!filled) { vset = getHollowed(vset); return setBlocks(vset, pattern);
recurseHollow(region, BlockVector3.at(x, y, minZ), outside); recurseHollow(region, BlockVector3.at(x, y, maxZ), outside); recurseHollow(region, BlockVector3.at(minX, y, z), outside); recurseHollow(region, BlockVector3.at(maxX, y, z), outside); recurseHollow(region, BlockVector3.at(x, minY, z), outside); recurseHollow(region, BlockVector3.at(x, maxY, z), outside); if (setBlock(position, pattern.apply(position))) { ++affected;
@Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { World world = (World) clicked.getExtent(); BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); final BlockType blockType = world.getBlock(blockPoint).getBlockType(); if (blockType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) { return true; } try (EditSession editSession = session.createEditSession(player)) { editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop); editSession.setBlock(blockPoint, BlockTypes.AIR.getDefaultState()); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } world.playEffect(clicked.toVector(), 2001, blockType.getLegacyId()); return true; }
/** * Closing an EditSession {@linkplain #flushSession() flushes its buffers}. */ @Override public void close() { flushSession(); }
BlockVector3 pt = min.add(x, y, z); int index = y * 16 * 16 + z * 16 + x; history[index] = editSession.getFullBlock(pt); editSession.smartSetBlock(pt, history[index]); } else { // Otherwise fool with history editSession.getChangeSet().add(new BlockChange(pt, history[index], editSession.getFullBlock(pt)));