Permalink
Browse files

Added a few more commands to the ones in the task queue test. Now it'…

…s all liquid commands.
  • Loading branch information...
me4502 committed Aug 24, 2018
1 parent 5d5a8da commit 0e633e8111d6524886818d8a2d48a0fddc2a6af0
@@ -613,30 +613,30 @@ public int countBlocks(Region region, Set<BlockStateHolder> searchBlocks) {
/**
* Fills an area recursively in the X/Z directions.
*
* @param actor the actor, if present
* @param origin the location to start from
* @param block 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 recursive whether a breadth-first search should be performed
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int fillXZ(Vector origin, BlockStateHolder block, double radius, int depth, boolean recursive) throws MaxChangedBlocksException {
return fillXZ(origin, new BlockPattern(block), radius, depth, recursive);
public Task<Integer> fillXZ(@Nullable Actor actor, Vector origin, BlockStateHolder block, double radius, int depth, boolean recursive) {
return fillXZ(actor, origin, new BlockPattern(block), radius, depth, recursive);
}
/**
* Fills an area recursively in the X/Z directions.
*
* @param actor the actor, if present
* @param origin the origin to start the fill from
* @param pattern the pattern to fill with
* @param radius the radius of the spherical area to fill, with 0 as the smallest radius
* @param depth the maximum depth, starting from the origin, with 1 as the smallest depth
* @param recursive whether a breadth-first search should be performed
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int fillXZ(Vector origin, Pattern pattern, double radius, int depth, boolean recursive) throws MaxChangedBlocksException {
public Task<Integer> fillXZ(@Nullable Actor actor, Vector origin, Pattern pattern, double radius, int depth, boolean recursive) {
checkNotNull(origin);
checkNotNull(pattern);
checkArgument(radius >= 0, "radius >= 0");
@@ -664,9 +664,14 @@ public int fillXZ(Vector origin, Pattern pattern, double radius, int depth, bool
visitor.visit(origin);
// Execute
Operations.completeLegacy(visitor);
Task<Integer> task = Operations.<Integer>completeQueued(visitor, actor, this)
.withSupplier(visitor::getAffected);
return visitor.getAffected();
if (actor != null) {
task.addActorConsumers(actor);
}
return task;
}
/**
@@ -1127,8 +1132,7 @@ public int moveCuboidRegion(Region region, Vector dir, int distance, boolean cop
.withSupplier(visitor::getAffected);
if (actor != null) {
task.withStatusConsumer(actor::print);
task.onExcept(e -> actor.printError(e.getMessage()));
task.addActorConsumers(actor);
}
return task;
@@ -1137,13 +1141,14 @@ public int moveCuboidRegion(Region region, Vector dir, int distance, boolean cop
/**
* Fix liquids so that they turn into stationary blocks and extend outward.
*
* @param actor the actor, if present
* @param origin the original position
* @param radius the radius to fix
* @param fluid the type of the fluid
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int fixLiquid(Vector origin, double radius, BlockType fluid) throws MaxChangedBlocksException {
public Task<Integer> fixLiquid(@Nullable Actor actor, Vector origin, double radius, BlockType fluid) throws MaxChangedBlocksException {
checkNotNull(origin);
checkArgument(radius >= 0, "radius >= 0 required");
@@ -1170,9 +1175,14 @@ public int fixLiquid(Vector origin, double radius, BlockType fluid) throws MaxCh
}
}
Operations.completeLegacy(visitor);
Task<Integer> task = Operations.<Integer>completeQueued(visitor, actor, this)
.withSupplier(visitor::getAffected);
return visitor.getAffected();
if (actor != null) {
task.addActorConsumers(actor);
}
return task;
}
/**
@@ -1656,14 +1666,23 @@ public int makeForest(Vector basePosition, int size, double density, TreeGenerat
/**
* Get the block distribution inside a region.
*
* @param actor the actor, if present
* @param region a region
* @param fuzzy If it should ignore states
* @return the results
*/
public List<Countable<BlockStateHolder>> getBlockDistribution(Region region, boolean fuzzy) {
public Task<List<Countable<BlockStateHolder>>> getBlockDistribution(@Nullable Actor actor, Region region, boolean fuzzy) {
BlockDistributionCounter count = new BlockDistributionCounter(this, fuzzy);
RegionVisitor visitor = new RegionVisitor(region, count);
Operations.completeBlindly(visitor);
return count.getDistribution();
Task<List<Countable<BlockStateHolder>>> task = Operations.<List<Countable<BlockStateHolder>>>completeQueued(visitor, actor, this)
.withSupplier(count::getDistribution);
if (actor != null) {
task.addActorConsumers(actor);
}
return task;
}
public int makeShape(final Region region, final Vector zero, final Vector unit, final Pattern pattern, final String expressionString, final boolean hollow) throws ExpressionException, MaxChangedBlocksException {
@@ -350,7 +350,7 @@ public void stack(Player player, EditSession editSession, LocalSession session,
public void regenerateChunk(Player player, LocalSession session, EditSession editSession, @Selection Region region) throws WorldEditException {
Mask mask = session.getMask();
try {
session.setMask((Mask) null);
session.setMask(null);
player.getWorld().regenerate(region, editSession);
} finally {
session.setMask(mask);
@@ -58,7 +58,6 @@
import com.sk89q.worldedit.util.formatting.component.CommandListBox;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.storage.ChunkStore;
@@ -662,40 +661,40 @@ public void distr(Player player, LocalSession session, EditSession editSession,
int size;
boolean useData = args.hasFlag('d');
List<Countable<BlockStateHolder>> distribution;
if (args.hasFlag('c')) {
// TODO: Update for new clipboard
throw new CommandException("Needs to be re-written again");
} else {
distribution = editSession.getBlockDistribution(session.getSelection(player.getWorld()), !useData);
size = session.getSelection(player.getWorld()).getArea();
}
if (distribution.isEmpty()) { // *Should* always be false
player.printError("No blocks counted.");
return;
}
editSession.getBlockDistribution(player, session.getSelection(player.getWorld()), !useData)
.withConsumer(distribution -> {
if (distribution.isEmpty()) { // *Should* always be false
player.printError("No blocks counted.");
return;
}
player.print("# total blocks: " + size);
for (Countable<BlockStateHolder> c : distribution) {
String name = c.getID().getBlockType().getName();
String str;
if (useData) {
str = String.format("%-7s (%.3f%%) %s #%s",
String.valueOf(c.getAmount()),
c.getAmount() / (double) size * 100,
name,
c.getID().getAsString());
} else {
str = String.format("%-7s (%.3f%%) %s #%s",
String.valueOf(c.getAmount()),
c.getAmount() / (double) size * 100,
name,
c.getID().getBlockType().getId());
}
player.print(str);
player.print("# total blocks: " + size);
for (Countable<BlockStateHolder> c : distribution) {
String name = c.getID().getBlockType().getName();
String str;
if (useData) {
str = String.format("%-7s (%.3f%%) %s #%s",
String.valueOf(c.getAmount()),
c.getAmount() / (double) size * 100,
name,
c.getID().getAsString());
} else {
str = String.format("%-7s (%.3f%%) %s #%s",
String.valueOf(c.getAmount()),
c.getAmount() / (double) size * 100,
name,
c.getID().getBlockType().getId());
}
player.print(str);
}
});
}
}
@@ -104,8 +104,8 @@ public void fill(Player player, LocalSession session, EditSession editSession, C
int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1;
Vector pos = session.getPlacementPosition(player);
int affected = editSession.fillXZ(pos, pattern, radius, depth, false);
player.print(affected + " block(s) have been created.");
editSession.fillXZ(player, pos, pattern, radius, depth, false)
.withConsumer(affected -> player.print(affected + " block(s) have been created."));
}
@Command(
@@ -130,13 +130,8 @@ public void fillr(Player player, LocalSession session, EditSession editSession,
int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : Integer.MAX_VALUE;
Vector pos = session.getPlacementPosition(player);
int affected = 0;
if (pattern instanceof BlockPattern) {
affected = editSession.fillXZ(pos, ((BlockPattern) pattern).getBlock(), radius, depth, true);
} else {
affected = editSession.fillXZ(pos, pattern, radius, depth, true);
}
player.print(affected + " block(s) have been created.");
editSession.fillXZ(player, pos, pattern, radius, depth, true)
.withConsumer(affected -> player.print(affected + " block(s) have been created."));
}
@Command(
@@ -170,8 +165,8 @@ public void fixLava(Player player, LocalSession session, EditSession editSession
double radius = Math.max(0, args.getDouble(0));
we.checkMaxRadius(radius);
int affected = editSession.fixLiquid(session.getPlacementPosition(player), radius, BlockTypes.LAVA);
player.print(affected + " block(s) have been changed.");
editSession.fixLiquid(player, session.getPlacementPosition(player), radius, BlockTypes.LAVA)
.withConsumer(affected -> player.print(affected + " block(s) have been changed."));
}
@Command(
@@ -187,8 +182,8 @@ public void fixWater(Player player, LocalSession session, EditSession editSessio
double radius = Math.max(0, args.getDouble(0));
we.checkMaxRadius(radius);
int affected = editSession.fixLiquid(session.getPlacementPosition(player), radius, BlockTypes.WATER);
player.print(affected + " block(s) have been changed.");
editSession.fixLiquid(player, session.getPlacementPosition(player), radius, BlockTypes.WATER)
.withConsumer(affected -> player.print(affected + " block(s) have been changed."));
}
@Command(
@@ -22,6 +22,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.RunContext;
@@ -114,6 +115,19 @@ public Task(Operation... operation) {
return this;
}
/**
* Adds exception and status consumers to this actor.
*
* @param actor The actor
* @return The task, for chaining
*/
public Task<T> addActorConsumers(Actor actor) {
checkNotNull(actor);
onExcept(e -> actor.printError(e.getMessage()));
withStatusConsumer(actor::print);
return this;
}
/**
* Resume the task with a given context.
*

0 comments on commit 0e633e8

Please sign in to comment.