mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Converted //drain to visitors.
This commit is contained in:
parent
3ad5c9016a
commit
cc8a89f415
@ -1301,67 +1301,37 @@ public class EditSession implements Extent {
|
|||||||
/**
|
/**
|
||||||
* Drain nearby pools of water or lava.
|
* Drain nearby pools of water or lava.
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param origin the origin to drain from, which will search a 3x3 area
|
||||||
* @param radius
|
* @param radius the radius of the removal, where a value should be 0 or greater
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int drainArea(Vector pos, double radius)
|
public int drainArea(Vector origin, double radius) throws MaxChangedBlocksException {
|
||||||
throws MaxChangedBlocksException {
|
checkNotNull(origin);
|
||||||
int affected = 0;
|
checkArgument(radius >= 0, "radius >= 0 required");
|
||||||
|
|
||||||
HashSet<BlockVector> visited = new HashSet<BlockVector>();
|
MaskIntersection mask = new MaskIntersection(
|
||||||
Stack<BlockVector> queue = new Stack<BlockVector>();
|
new BoundedHeightMask(0, getWorld().getMaxY()),
|
||||||
|
new RegionMask(new EllipsoidRegion(null, origin, new Vector(radius, radius, radius))),
|
||||||
|
new BlockMask(this,
|
||||||
|
new BaseBlock(BlockID.STATIONARY_LAVA, -1),
|
||||||
|
new BaseBlock(BlockID.LAVA, -1),
|
||||||
|
new BaseBlock(BlockID.STATIONARY_WATER, -1),
|
||||||
|
new BaseBlock(BlockID.WATER, -1)));
|
||||||
|
|
||||||
for (int x = pos.getBlockX() - 1; x <= pos.getBlockX() + 1; ++x) {
|
BlockReplace replace = new BlockReplace(this, new BlockPattern(new BaseBlock(BlockID.AIR)));
|
||||||
for (int z = pos.getBlockZ() - 1; z <= pos.getBlockZ() + 1; ++z) {
|
RecursiveVisitor visitor = new RecursiveVisitor(mask, replace);
|
||||||
for (int y = pos.getBlockY() - 1; y <= pos.getBlockY() + 1; ++y) {
|
|
||||||
queue.push(new BlockVector(x, y, z));
|
// Around the origin in a 3x3 block
|
||||||
}
|
for (BlockVector position : CuboidRegion.fromCenter(origin, 1)) {
|
||||||
|
if (mask.test(position)) {
|
||||||
|
visitor.visit(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!queue.empty()) {
|
OperationHelper.completeLegacy(visitor);
|
||||||
BlockVector cur = queue.pop();
|
|
||||||
|
|
||||||
int type = getBlockType(cur);
|
return visitor.getAffected();
|
||||||
|
|
||||||
// Check block type
|
|
||||||
if (type != BlockID.WATER && type != BlockID.STATIONARY_WATER
|
|
||||||
&& type != BlockID.LAVA && type != BlockID.STATIONARY_LAVA) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't want to revisit
|
|
||||||
if (visited.contains(cur)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
visited.add(cur);
|
|
||||||
|
|
||||||
// Check radius
|
|
||||||
if (pos.distance(cur) > radius) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int x = cur.getBlockX() - 1; x <= cur.getBlockX() + 1; ++x) {
|
|
||||||
for (int z = cur.getBlockZ() - 1; z <= cur.getBlockZ() + 1; ++z) {
|
|
||||||
for (int y = cur.getBlockY() - 1; y <= cur.getBlockY() + 1; ++y) {
|
|
||||||
BlockVector newPos = new BlockVector(x, y, z);
|
|
||||||
|
|
||||||
if (!cur.equals(newPos)) {
|
|
||||||
queue.push(newPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setBlock(cur, new BaseBlock(BlockID.AIR))) {
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return affected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user