use of com.sk89q.worldedit.function.block.BlockReplace in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method overlayCuboidBlocks.
/**
* Places a layer of blocks on top of ground blocks in the given region
* (as if it were a cuboid).
*
* @param region the region
* @param pattern the placed block pattern
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int overlayCuboidBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
checkNotNull(region);
checkNotNull(pattern);
BlockReplace replace = new BlockReplace(this, pattern);
RegionOffset offset = new RegionOffset(BlockVector3.UNIT_Y, replace);
// FAWE start
int minY = region.getMinimumPoint().getBlockY();
int maxY = Math.min(getMaximumPoint().getBlockY(), region.getMaximumPoint().getBlockY() + 1);
SurfaceRegionFunction surface = new SurfaceRegionFunction(this, offset, minY, maxY);
FlatRegionVisitor visitor = new FlatRegionVisitor(asFlatRegion(region), surface, this);
// FAWE end
Operations.completeBlindly(visitor);
return this.changes = visitor.getAffected();
}
use of com.sk89q.worldedit.function.block.BlockReplace in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method fillDirection.
/**
* Fills an area recursively in the X/Z directions.
*
* @param origin the location to start from
* @param pattern the block to fill with
* @param radius the radius of the spherical area to fill
* @param depth the maximum depth, starting from the origin
* @param direction the direction to fill
* @return the number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int fillDirection(final BlockVector3 origin, final Pattern pattern, final double radius, final int depth, BlockVector3 direction) throws MaxChangedBlocksException {
checkNotNull(origin);
checkNotNull(pattern);
checkArgument(radius >= 0, "radius >= 0");
checkArgument(depth >= 1, "depth >= 1");
if (direction.equals(BlockVector3.UNIT_MINUS_Y)) {
return fillXZ(origin, pattern, radius, depth, false);
}
Mask mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), Masks.negate(new ExistingBlockMask(EditSession.this)));
// Want to replace blocks
final BlockReplace replace = new BlockReplace(EditSession.this, pattern);
// Pick how we're going to visit blocks
RecursiveVisitor visitor = new DirectionalVisitor(mask, replace, origin, direction, (int) (radius * 2 + 1), minY, maxY);
// Start at the origin
visitor.visit(origin);
// Execute
Operations.completeBlindly(visitor);
return this.changes = visitor.getAffected();
}
use of com.sk89q.worldedit.function.block.BlockReplace in project FastAsyncWorldEdit by IntellectualSites.
the class Extent method replaceBlocks.
/**
* Replaces all the blocks matching a given mask, within a given region, to a block
* returned by a given pattern.
*
* @param region the region to replace the blocks within
* @param mask the mask that blocks must match
* @param pattern the pattern that provides the new blocks
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
default int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException {
checkNotNull(region);
checkNotNull(mask);
checkNotNull(pattern);
BlockReplace replace = new BlockReplace(this, pattern);
RegionMaskingFilter filter = new RegionMaskingFilter(this, mask, replace);
// FAWE start > add extent to RegionVisitor to allow chunk preloading
RegionVisitor visitor = new RegionVisitor(region, filter, this);
// FAWE end
Operations.completeLegacy(visitor);
return visitor.getAffected();
}
use of com.sk89q.worldedit.function.block.BlockReplace in project FastAsyncWorldEdit by IntellectualSites.
the class RecursivePickaxe method actPrimary.
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
World world = (World) clicked.getExtent();
final BlockVector3 pos = clicked.toBlockPoint();
BlockVector3 origin = clicked.toVector().toBlockPoint();
BlockType initialType = world.getBlock(origin).getBlockType();
if (initialType.getMaterial().isAir()) {
return false;
}
if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
return false;
}
try (EditSession editSession = session.createEditSession(player, "RecursivePickaxe")) {
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
// FAWE start
final int radius = (int) range;
final BlockReplace replace = new BlockReplace(editSession, (BlockTypes.AIR.getDefaultState()));
editSession.setMask(null);
RecursiveVisitor visitor = new RecursiveVisitor(new IdMask(editSession), replace, radius, editSession.getMinY(), editSession.getMaxY(), editSession);
// TODO: Fix below
// visitor.visit(pos);
// Operations.completeBlindly(visitor);
recurse(server, editSession, world, pos, origin, radius, initialType, visitor.getVisited());
// FAWE end
editSession.flushQueue();
session.remember(editSession);
}
return true;
}
use of com.sk89q.worldedit.function.block.BlockReplace in project FastAsyncWorldEdit by IntellectualSites.
the class FloodFillTool method actPrimary.
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
World world = (World) clicked.getExtent();
BlockVector3 origin = clicked.toVector().toBlockPoint();
BlockType initialType = world.getBlock(origin).getBlockType();
if (initialType.getMaterial().isAir()) {
return true;
}
if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
return true;
}
try (EditSession editSession = session.createEditSession(player, "FloodFillTool")) {
try {
// FAWE start - Respect masks
Mask mask = initialType.toMask(editSession);
BlockReplace function = new BlockReplace(editSession, pattern);
RecursiveVisitor visitor = new RecursiveVisitor(mask, function, range, editSession.getMinY(), editSession.getMaxY(), editSession);
visitor.visit(origin);
Operations.completeLegacy(visitor);
// FAWE end
} catch (MaxChangedBlocksException e) {
player.print(Caption.of("worldedit.tool.max-block-changes"));
} finally {
session.remember(editSession);
}
}
return true;
}
Aggregations