use of com.sk89q.worldedit.function.mask.MaskIntersection in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method addSourceMask.
public void addSourceMask(Mask mask) {
checkNotNull(mask);
Mask existing = getSourceMask();
if (existing != null) {
if (existing instanceof MaskIntersection) {
Collection<Mask> masks = new HashSet<>(((MaskIntersection) existing).getMasks());
masks.add(mask);
mask = new MaskIntersection(masks);
} else {
mask = new MaskIntersection(existing, mask);
}
mask = mask.optimize();
}
setSourceMask(mask);
}
use of com.sk89q.worldedit.function.mask.MaskIntersection in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method drainArea.
/**
* Drain nearby pools of water or lava, optionally removed waterlogged states from blocks.
*
* @param origin the origin to drain from, which will search a 3x3 area
* @param radius the radius of the removal, where a value should be 0 or greater
* @param waterlogged true to make waterlogged blocks non-waterlogged as well
* @param plants true to remove underwater plants
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int drainArea(BlockVector3 origin, double radius, boolean waterlogged, boolean plants) throws MaxChangedBlocksException {
checkNotNull(origin);
checkArgument(radius >= 0, "radius >= 0 required");
// FAWE start - liquidmask
Mask liquidMask;
if (plants) {
liquidMask = new BlockTypeMask(this, BlockTypes.LAVA, BlockTypes.WATER, BlockTypes.BUBBLE_COLUMN, BlockTypes.KELP_PLANT, BlockTypes.KELP, BlockTypes.SEAGRASS, BlockTypes.TALL_SEAGRASS);
} else {
liquidMask = new BlockMaskBuilder().addTypes(BlockTypes.WATER, BlockTypes.LAVA, BlockTypes.BUBBLE_COLUMN).build(this);
}
// FAWE end
if (waterlogged) {
Map<String, String> stateMap = new HashMap<>();
stateMap.put("waterlogged", "true");
// FAWE start
liquidMask = new MaskUnion(liquidMask, new BlockStateMask(this, stateMap, true));
// FAWE end
}
Mask mask = new MaskIntersection(new BoundedHeightMask(minY, maxY), new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), // FAWE start
liquidMask);
// FAWE end
BlockReplace replace;
if (waterlogged) {
replace = new BlockReplace(this, new WaterloggedRemover(this));
} else {
replace = new BlockReplace(this, BlockTypes.AIR.getDefaultState());
}
// FAWE start - provide extent for preloading, min/max y
RecursiveVisitor visitor = new RecursiveVisitor(mask, replace, (int) (radius * 2 + 1), minY, maxY, this);
// Around the origin in a 3x3 block
for (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) {
if (mask.test(position)) {
visitor.visit(position);
}
}
Operations.completeLegacy(visitor);
// FAWE start
return this.changes = visitor.getAffected();
// FAWE end
}
use of com.sk89q.worldedit.function.mask.MaskIntersection 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.mask.MaskIntersection in project FastAsyncWorldEdit by IntellectualSites.
the class BrushTool method act.
public boolean act(BrushAction action, Player player, LocalSession session) {
switch(action) {
case PRIMARY:
setContext(primary);
break;
case SECONDARY:
setContext(secondary);
break;
default:
throw new IllegalStateException("Unexpected value: " + action);
}
BrushSettings current = getContext();
Brush brush = current.getBrush();
if (brush == null) {
return false;
}
if (!current.canUse(player)) {
player.print(Caption.of("fawe.error.no-perm", StringMan.join(current.getPermissions(), ",")));
return false;
}
try (EditSession editSession = session.createEditSession(player, current.toString())) {
Location target = player.getBlockTrace(getRange(), true, traceMask);
if (target == null) {
editSession.cancel();
player.print(Caption.of("worldedit.tool.no-block"));
return true;
}
BlockBag bag = session.getBlockBag(player);
Request.request().setEditSession(editSession);
Mask mask = current.getMask();
if (mask != null) {
Mask existingMask = editSession.getMask();
if (existingMask == null) {
editSession.setMask(mask);
} else if (existingMask instanceof MaskIntersection) {
((MaskIntersection) existingMask).add(mask);
} else {
MaskIntersection newMask = new MaskIntersection(existingMask);
newMask.add(mask);
editSession.setMask(newMask);
}
}
Mask sourceMask = current.getSourceMask();
if (sourceMask != null) {
editSession.addSourceMask(sourceMask);
}
ResettableExtent transform = current.getTransform();
if (transform != null) {
editSession.addTransform(transform);
}
try {
new PatternTraverser(current).reset(editSession);
double size = current.getSize();
WorldEdit.getInstance().checkMaxBrushRadius(size);
brush.build(editSession, target.toBlockPoint(), current.getMaterial(), size);
} catch (MaxChangedBlocksException e) {
player.print(Caption.of("worldedit.tool.max-block-changes"));
} finally {
session.remember(editSession);
if (bag != null) {
bag.flushChanges();
}
}
} finally {
Request.reset();
}
return true;
}
Aggregations