From d0056870be2589806e3a769962714597029137b9 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Tue, 21 Sep 2021 14:31:03 +0100 Subject: [PATCH] Fix fuzzy region --- .../core/regions/FuzzyRegion.java | 10 +++++++--- .../regions/selector/FuzzyRegionSelector.java | 19 +++++++++---------- .../worldedit/command/SelectionCommands.java | 3 +-- .../function/visitor/BreadthFirstSearch.java | 4 +++- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/regions/FuzzyRegion.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/regions/FuzzyRegion.java index 5fc7c543f..15565ceed 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/regions/FuzzyRegion.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/regions/FuzzyRegion.java @@ -47,13 +47,17 @@ public class FuzzyRegion extends AbstractRegion { return set.size(); } - public void select(int x, int y, int z) { + /** + * Add to the selection from the given position. + */ + public void select(BlockVector3 position) { RecursiveVisitor search = new RecursiveVisitor(mask, p -> { setMinMax(p.getBlockX(), p.getBlockY(), p.getBlockZ()); return true; - }, 256, extent.getMinY(), extent.getMaxY()); + }, 256, extent.getMinY(), extent.getMaxY(), extent); search.setVisited(set); - search.visit(BlockVector3.at(x, y, z)); + mask.test(position); + search.visit(position); Operations.completeBlindly(search); } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/regions/selector/FuzzyRegionSelector.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/regions/selector/FuzzyRegionSelector.java index 1dce2fd54..0ea04e976 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/regions/selector/FuzzyRegionSelector.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/regions/selector/FuzzyRegionSelector.java @@ -9,7 +9,6 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; @@ -26,17 +25,17 @@ import java.util.stream.IntStream; public class FuzzyRegionSelector extends PassthroughExtent implements RegionSelector { - private final Player player; + private final Actor actor; private FuzzyRegion region; private final ArrayList positions; - public FuzzyRegionSelector(Player player, @Nullable World world, Mask mask) { + public FuzzyRegionSelector(Actor actor, @Nullable World world, Mask mask) { super(WorldEdit.getInstance().newEditSessionBuilder().world(world) - .actor(player) + .actor(actor) .changeSetNull() .checkMemory(false) .build()); - this.player = player; + this.actor = actor; this.region = new FuzzyRegion(world, getExtent(), mask); this.positions = new ArrayList<>(); new MaskTraverser(mask).reset(getExtent()); @@ -51,7 +50,7 @@ public class FuzzyRegionSelector extends PassthroughExtent implements RegionSele @Override public void setWorld(@Nullable World world) { EditSession extent = WorldEdit.getInstance().newEditSessionBuilder().world(world) - .actor(player) + .actor(actor) .changeSetNull() .checkMemory(false) .build(); @@ -72,7 +71,7 @@ public class FuzzyRegionSelector extends PassthroughExtent implements RegionSele positions.clear(); positions.add(position); this.region = new FuzzyRegion(getWorld(), getExtent(), getMask()); - this.region.select(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + this.region.select(position); return true; } @@ -80,18 +79,18 @@ public class FuzzyRegionSelector extends PassthroughExtent implements RegionSele public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { this.positions.add(position); new MaskTraverser(getMask()).reset(getExtent()); - this.region.select(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + this.region.select(position); return true; } @Override public void explainPrimarySelection(Actor actor, LocalSession session, BlockVector3 position) { - player.print(Caption.of("fawe.worldedit.selector.selector.fuzzy.pos1", position, "(" + region.getVolume() + ")")); + actor.print(Caption.of("fawe.worldedit.selector.selector.fuzzy.pos1", position, "(" + region.getVolume() + ")")); } @Override public void explainSecondarySelection(Actor actor, LocalSession session, BlockVector3 position) { - player.print(Caption.of("fawe.worldedit.selector.selector.fuzzy.pos2", position, "(" + region.getVolume() + ")")); + actor.print(Caption.of("fawe.worldedit.selector.selector.fuzzy.pos2", position, "(" + region.getVolume() + ")")); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java index f5e8758e9..aaa87839e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java @@ -717,8 +717,7 @@ public class SelectionCommands { case FUZZY: case MAGIC: Mask maskOpt = new IdMask(world); - //TODO Make FuzzyRegionSelector accept actors - newSelector = new FuzzyRegionSelector((Player) actor, world, maskOpt); + newSelector = new FuzzyRegionSelector(actor, world, maskOpt); actor.print(Caption.of("fawe.selection.sel.fuzzy")); actor.print(Caption.of("fawe.selection.sel.list")); break; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java index 95ac8e0f8..7966f1217 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java @@ -210,7 +210,9 @@ public abstract class BreadthFirstSearch implements Operation { * Add the given location to the list of locations to visit, provided * that it has not been visited. The position passed to this method * will still be visited even if it fails - * {@link #isVisitable(BlockVector3, BlockVector3)}. + * {@link #isVisitable(BlockVector3, BlockVector3)} as + * {@link #isVisitable(BlockVector3, BlockVector3)} is never actually + * called. * *

This method should be used before the search begins, because if * the position does fail the test, and the search has already