Fix fuzzy region

Dieser Commit ist enthalten in:
dordsor21 2021-09-21 14:31:03 +01:00
Ursprung 69ae4a7121
Commit d0056870be
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
4 geänderte Dateien mit 20 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -47,13 +47,17 @@ public class FuzzyRegion extends AbstractRegion {
return set.size(); 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 -> { RecursiveVisitor search = new RecursiveVisitor(mask, p -> {
setMinMax(p.getBlockX(), p.getBlockY(), p.getBlockZ()); setMinMax(p.getBlockX(), p.getBlockY(), p.getBlockZ());
return true; return true;
}, 256, extent.getMinY(), extent.getMaxY()); }, 256, extent.getMinY(), extent.getMaxY(), extent);
search.setVisited(set); search.setVisited(set);
search.visit(BlockVector3.at(x, y, z)); mask.test(position);
search.visit(position);
Operations.completeBlindly(search); Operations.completeBlindly(search);
} }

Datei anzeigen

@ -9,7 +9,6 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
@ -26,17 +25,17 @@ import java.util.stream.IntStream;
public class FuzzyRegionSelector extends PassthroughExtent implements RegionSelector { public class FuzzyRegionSelector extends PassthroughExtent implements RegionSelector {
private final Player player; private final Actor actor;
private FuzzyRegion region; private FuzzyRegion region;
private final ArrayList<BlockVector3> positions; private final ArrayList<BlockVector3> 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) super(WorldEdit.getInstance().newEditSessionBuilder().world(world)
.actor(player) .actor(actor)
.changeSetNull() .changeSetNull()
.checkMemory(false) .checkMemory(false)
.build()); .build());
this.player = player; this.actor = actor;
this.region = new FuzzyRegion(world, getExtent(), mask); this.region = new FuzzyRegion(world, getExtent(), mask);
this.positions = new ArrayList<>(); this.positions = new ArrayList<>();
new MaskTraverser(mask).reset(getExtent()); new MaskTraverser(mask).reset(getExtent());
@ -51,7 +50,7 @@ public class FuzzyRegionSelector extends PassthroughExtent implements RegionSele
@Override @Override
public void setWorld(@Nullable World world) { public void setWorld(@Nullable World world) {
EditSession extent = WorldEdit.getInstance().newEditSessionBuilder().world(world) EditSession extent = WorldEdit.getInstance().newEditSessionBuilder().world(world)
.actor(player) .actor(actor)
.changeSetNull() .changeSetNull()
.checkMemory(false) .checkMemory(false)
.build(); .build();
@ -72,7 +71,7 @@ public class FuzzyRegionSelector extends PassthroughExtent implements RegionSele
positions.clear(); positions.clear();
positions.add(position); positions.add(position);
this.region = new FuzzyRegion(getWorld(), getExtent(), getMask()); this.region = new FuzzyRegion(getWorld(), getExtent(), getMask());
this.region.select(position.getBlockX(), position.getBlockY(), position.getBlockZ()); this.region.select(position);
return true; return true;
} }
@ -80,18 +79,18 @@ public class FuzzyRegionSelector extends PassthroughExtent implements RegionSele
public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) {
this.positions.add(position); this.positions.add(position);
new MaskTraverser(getMask()).reset(getExtent()); new MaskTraverser(getMask()).reset(getExtent());
this.region.select(position.getBlockX(), position.getBlockY(), position.getBlockZ()); this.region.select(position);
return true; return true;
} }
@Override @Override
public void explainPrimarySelection(Actor actor, LocalSession session, BlockVector3 position) { 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 @Override
public void explainSecondarySelection(Actor actor, LocalSession session, BlockVector3 position) { 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 @Override

Datei anzeigen

@ -717,8 +717,7 @@ public class SelectionCommands {
case FUZZY: case FUZZY:
case MAGIC: case MAGIC:
Mask maskOpt = new IdMask(world); Mask maskOpt = new IdMask(world);
//TODO Make FuzzyRegionSelector accept actors newSelector = new FuzzyRegionSelector(actor, world, maskOpt);
newSelector = new FuzzyRegionSelector((Player) actor, world, maskOpt);
actor.print(Caption.of("fawe.selection.sel.fuzzy")); actor.print(Caption.of("fawe.selection.sel.fuzzy"));
actor.print(Caption.of("fawe.selection.sel.list")); actor.print(Caption.of("fawe.selection.sel.list"));
break; break;

Datei anzeigen

@ -210,7 +210,9 @@ public abstract class BreadthFirstSearch implements Operation {
* Add the given location to the list of locations to visit, provided * Add the given location to the list of locations to visit, provided
* that it has not been visited. The position passed to this method * that it has not been visited. The position passed to this method
* will still be visited even if it fails * 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.
* *
* <p>This method should be used before the search begins, because if * <p>This method should be used before the search begins, because if
* the position <em>does</em> fail the test, and the search has already * the position <em>does</em> fail the test, and the search has already