Search in sources :

Example 1 with IdMask

use of com.fastasyncworldedit.core.function.mask.IdMask in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method select.

@Command(name = "/sel", aliases = { ";", "/desel", "/deselect" }, desc = "Choose a region selector")
// FAWE start
@CommandPermissions("worldedit.analysis.sel")
public // FAWE end
void select(Actor actor, World world, LocalSession session, @Arg(desc = "Selector to switch to", def = "") SelectorChoice selector, @Switch(name = 'd', desc = "Set default selector") boolean setDefaultSelector) throws WorldEditException {
    if (selector == null) {
        session.getRegionSelector(world).clear();
        session.dispatchCUISelection(actor);
        actor.print(Caption.of("worldedit.select.cleared"));
        return;
    }
    final RegionSelector oldSelector = session.getRegionSelector(world);
    final RegionSelector newSelector;
    switch(selector) {
        case CUBOID:
            newSelector = new CuboidRegionSelector(oldSelector);
            actor.print(Caption.of("worldedit.select.cuboid.message"));
            break;
        case EXTEND:
            newSelector = new ExtendingCuboidRegionSelector(oldSelector);
            actor.print(Caption.of("worldedit.select.extend.message"));
            break;
        case POLY:
            {
                newSelector = new Polygonal2DRegionSelector(oldSelector);
                actor.print(Caption.of("worldedit.select.poly.message"));
                Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolygonVertexLimit();
                limit.ifPresent(integer -> actor.print(Caption.of("worldedit.select.poly.limit-message", TextComponent.of(integer))));
                break;
            }
        case ELLIPSOID:
            newSelector = new EllipsoidRegionSelector(oldSelector);
            actor.print(Caption.of("worldedit.select.ellipsoid.message"));
            break;
        case SPHERE:
            newSelector = new SphereRegionSelector(oldSelector);
            actor.print(Caption.of("worldedit.select.sphere.message"));
            break;
        case CYL:
            newSelector = new CylinderRegionSelector(oldSelector);
            actor.print(Caption.of("worldedit.select.cyl.message"));
            break;
        case CONVEX:
        case HULL:
        case POLYHEDRON:
            {
                newSelector = new ConvexPolyhedralRegionSelector(oldSelector);
                actor.print(Caption.of("worldedit.select.convex.message"));
                Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
                limit.ifPresent(integer -> actor.print(Caption.of("worldedit.select.convex.limit-message", TextComponent.of(integer))));
                break;
            }
        // FAWE start
        case POLYHEDRAL:
            newSelector = new PolyhedralRegionSelector(world);
            actor.print(Caption.of("fawe.selection.sel.convex.polyhedral"));
            Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
            limit.ifPresent(integer -> actor.print(Caption.of("fawe.selection.sel.max", integer)));
            actor.print(Caption.of("fawe.selection.sel.list"));
            break;
        case FUZZY:
        case MAGIC:
            Mask maskOpt = new IdMask(world);
            newSelector = new FuzzyRegionSelector(actor, world, maskOpt);
            actor.print(Caption.of("fawe.selection.sel.fuzzy"));
            actor.print(Caption.of("fawe.selection.sel.list"));
            break;
        // FAWE end
        case LIST:
        default:
            CommandListBox box = new CommandListBox("Selection modes", null, null);
            box.setHidingHelp(true);
            TextComponentProducer contents = box.getContents();
            contents.append(SubtleFormat.wrap("Select one of the modes below:")).newline();
            box.appendCommand("cuboid", Caption.of("worldedit.select.cuboid.description"), "//sel cuboid");
            box.appendCommand("extend", Caption.of("worldedit.select.extend.description"), "//sel extend");
            box.appendCommand("poly", Caption.of("worldedit.select.poly.description"), "//sel poly");
            box.appendCommand("ellipsoid", Caption.of("worldedit.select.ellipsoid.description"), "//sel ellipsoid");
            box.appendCommand("sphere", Caption.of("worldedit.select.sphere.description"), "//sel sphere");
            box.appendCommand("cyl", Caption.of("worldedit.select.cyl.description"), "//sel cyl");
            box.appendCommand("convex", Caption.of("worldedit.select.convex.description"), "//sel convex");
            // FAWE start
            box.appendCommand("polyhedral", Caption.of("fawe.selection.sel.polyhedral"), "//sel polyhedral");
            box.appendCommand("fuzzy[=<mask>]", Caption.of("fawe.selection.sel.fuzzy-instruction"), "//sel fuzzy[=<mask>]");
            box.setComponentsPerPage(box.getComponentsSize());
            // FAWE end
            actor.print(box.create(1));
            return;
    }
    if (setDefaultSelector) {
        RegionSelectorType found = null;
        for (RegionSelectorType type : RegionSelectorType.values()) {
            if (type.getSelectorClass() == newSelector.getClass()) {
                found = type;
                break;
            }
        }
        if (found != null) {
            session.setDefaultRegionSelector(found);
            actor.print(Caption.of("worldedit.select.default-set", TextComponent.of(found.name())));
        } else {
            throw new RuntimeException("Something unexpected happened. Please report this.");
        }
    }
    session.setRegionSelector(world, newSelector);
    session.dispatchCUISelection(actor);
}
Also used : EditSession(com.sk89q.worldedit.EditSession) ChunkStore(com.sk89q.worldedit.world.storage.ChunkStore) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Player(com.sk89q.worldedit.entity.Player) World(com.sk89q.worldedit.world.World) Caption(com.fastasyncworldedit.core.configuration.Caption) BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) Arg(org.enginehub.piston.annotation.param.Arg) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) ExtendingCuboidRegionSelector(com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector) Component(com.sk89q.worldedit.util.formatting.text.Component) RegionOperationException(com.sk89q.worldedit.regions.RegionOperationException) SelectionWand(com.sk89q.worldedit.command.tool.SelectionWand) CommandContainer(org.enginehub.piston.annotation.CommandContainer) TextColor(com.sk89q.worldedit.util.formatting.text.format.TextColor) NavigationWand(com.sk89q.worldedit.command.tool.NavigationWand) SelectorChoice(com.sk89q.worldedit.command.argument.SelectorChoice) Operations(com.sk89q.worldedit.function.operation.Operations) Location(com.sk89q.worldedit.util.Location) URI(java.net.URI) POSITION(com.sk89q.worldedit.command.util.Logging.LogMode.POSITION) MultiDirection(com.sk89q.worldedit.internal.annotation.MultiDirection) Polygonal2DRegionSelector(com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockType(com.sk89q.worldedit.world.block.BlockType) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions) Locatable(com.sk89q.worldedit.extension.platform.Locatable) ConvexPolyhedralRegionSelector(com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector) SubtleFormat(com.sk89q.worldedit.util.formatting.component.SubtleFormat) CHUNK_SHIFTS_Y(com.sk89q.worldedit.world.storage.ChunkStore.CHUNK_SHIFTS_Y) InvalidComponentException(com.sk89q.worldedit.util.formatting.component.InvalidComponentException) ArgFlag(org.enginehub.piston.annotation.param.ArgFlag) TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) CommandListBox(com.sk89q.worldedit.util.formatting.component.CommandListBox) List(java.util.List) Stream(java.util.stream.Stream) StopExecutionException(org.enginehub.piston.exception.StopExecutionException) CommandPermissionsConditionGenerator(com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) ActorSelectorLimits(com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits) Optional(java.util.Optional) Countable(com.sk89q.worldedit.util.Countable) RegionSelector(com.sk89q.worldedit.regions.RegionSelector) BlockDistributionCounter(com.sk89q.worldedit.function.block.BlockDistributionCounter) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) Switch(org.enginehub.piston.annotation.param.Switch) Logging(com.sk89q.worldedit.command.util.Logging) HoverEvent(com.sk89q.worldedit.util.formatting.text.event.HoverEvent) CHUNK_SHIFTS(com.sk89q.worldedit.world.storage.ChunkStore.CHUNK_SHIFTS) EllipsoidRegionSelector(com.sk89q.worldedit.regions.selector.EllipsoidRegionSelector) Strings(com.google.common.base.Strings) WorldEditException(com.sk89q.worldedit.WorldEditException) RegionSelectorType(com.sk89q.worldedit.regions.selector.RegionSelectorType) PolyhedralRegionSelector(com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector) ClickEvent(com.sk89q.worldedit.util.formatting.text.event.ClickEvent) CylinderRegionSelector(com.sk89q.worldedit.regions.selector.CylinderRegionSelector) WorldEdit(com.sk89q.worldedit.WorldEdit) Region(com.sk89q.worldedit.regions.Region) SphereRegionSelector(com.sk89q.worldedit.regions.selector.SphereRegionSelector) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) ItemTypes(com.sk89q.worldedit.world.item.ItemTypes) REGION(com.sk89q.worldedit.command.util.Logging.LogMode.REGION) RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) File(java.io.File) Actor(com.sk89q.worldedit.extension.platform.Actor) Direction(com.sk89q.worldedit.internal.annotation.Direction) IdMask(com.fastasyncworldedit.core.function.mask.IdMask) FuzzyRegionSelector(com.fastasyncworldedit.core.regions.selector.FuzzyRegionSelector) Command(org.enginehub.piston.annotation.Command) LocalSession(com.sk89q.worldedit.LocalSession) Mask(com.sk89q.worldedit.function.mask.Mask) BlockState(com.sk89q.worldedit.world.block.BlockState) ItemType(com.sk89q.worldedit.world.item.ItemType) CommandListBox(com.sk89q.worldedit.util.formatting.component.CommandListBox) TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) Optional(java.util.Optional) Polygonal2DRegionSelector(com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector) IdMask(com.fastasyncworldedit.core.function.mask.IdMask) Mask(com.sk89q.worldedit.function.mask.Mask) CylinderRegionSelector(com.sk89q.worldedit.regions.selector.CylinderRegionSelector) ExtendingCuboidRegionSelector(com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) ExtendingCuboidRegionSelector(com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector) EllipsoidRegionSelector(com.sk89q.worldedit.regions.selector.EllipsoidRegionSelector) FuzzyRegionSelector(com.fastasyncworldedit.core.regions.selector.FuzzyRegionSelector) ExtendingCuboidRegionSelector(com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector) Polygonal2DRegionSelector(com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector) ConvexPolyhedralRegionSelector(com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector) RegionSelector(com.sk89q.worldedit.regions.RegionSelector) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) EllipsoidRegionSelector(com.sk89q.worldedit.regions.selector.EllipsoidRegionSelector) PolyhedralRegionSelector(com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector) CylinderRegionSelector(com.sk89q.worldedit.regions.selector.CylinderRegionSelector) SphereRegionSelector(com.sk89q.worldedit.regions.selector.SphereRegionSelector) FuzzyRegionSelector(com.fastasyncworldedit.core.regions.selector.FuzzyRegionSelector) ConvexPolyhedralRegionSelector(com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector) IdMask(com.fastasyncworldedit.core.function.mask.IdMask) ConvexPolyhedralRegionSelector(com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector) PolyhedralRegionSelector(com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector) SphereRegionSelector(com.sk89q.worldedit.regions.selector.SphereRegionSelector) RegionSelectorType(com.sk89q.worldedit.regions.selector.RegionSelectorType) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 2 with IdMask

use of com.fastasyncworldedit.core.function.mask.IdMask in project FastAsyncWorldEdit by IntellectualSites.

the class SplineBrush method build.

@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws WorldEditException {
    Mask mask = editSession.getMask();
    if (mask == null) {
        mask = new IdMask(editSession);
    } else {
        mask = new MaskIntersection(mask, new IdMask(editSession));
    }
    boolean newPos = !position.equals(this.position);
    this.position = position;
    if (newPos) {
        if (positionSets.size() >= MAX_POINTS) {
            throw FaweCache.MAX_CHECKS;
        }
        final ArrayList<BlockVector3> points = new ArrayList<>();
        if (size > 0) {
            DFSRecursiveVisitor visitor = new DFSRecursiveVisitor(mask, p -> {
                points.add(p);
                return true;
            }, (int) size, 1);
            List<BlockVector3> directions = visitor.getDirections();
            for (int x = -1; x <= 1; x++) {
                for (int y = -1; y <= 1; y++) {
                    for (int z = -1; z <= 1; z++) {
                        if (x != 0 || y != 0 || z != 0) {
                            BlockVector3 pos = BlockVector3.at(x, y, z);
                            if (!directions.contains(pos)) {
                                directions.add(pos);
                            }
                        }
                    }
                }
            }
            directions.sort((o1, o2) -> (int) Math.signum(o1.lengthSq() - o2.lengthSq()));
            visitor.visit(position);
            Operations.completeBlindly(visitor);
            if (points.size() > numSplines) {
                numSplines = points.size();
            }
        } else {
            points.add(position);
        }
        this.positionSets.add(points);
        player.print(Caption.of("fawe.worldedit.brush.spline.primary.2"));
        return;
    }
    if (positionSets.size() < 2) {
        player.print(Caption.of("fawe.worldedit.brush.brush.spline.secondary.error"));
        return;
    }
    List<Vector3> centroids = new ArrayList<>();
    for (List<BlockVector3> points : positionSets) {
        centroids.add(getCentroid(points));
    }
    double tension = 0;
    double bias = 0;
    double continuity = 0;
    final List<Node> nodes = new ArrayList<>(centroids.size());
    for (Vector3 nodevector : centroids) {
        final Node n = new Node(nodevector);
        n.setTension(tension);
        n.setBias(bias);
        n.setContinuity(continuity);
        nodes.add(n);
    }
    for (int i = 0; i < numSplines; i++) {
        List<BlockVector3> currentSpline = new ArrayList<>();
        for (ArrayList<BlockVector3> points : positionSets) {
            int listSize = points.size();
            int index = (int) (i * listSize / (double) numSplines);
            currentSpline.add(points.get(index));
        }
        editSession.drawSpline(pattern, currentSpline, 0, 0, 0, 10, 0, true);
    }
    player.print(Caption.of("fawe.worldedit.brush.spline.secondary"));
    positionSets.clear();
    numSplines = 0;
}
Also used : DFSRecursiveVisitor(com.fastasyncworldedit.core.function.visitor.DFSRecursiveVisitor) MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) Node(com.sk89q.worldedit.math.interpolation.Node) IdMask(com.fastasyncworldedit.core.function.mask.IdMask) Mask(com.sk89q.worldedit.function.mask.Mask) ArrayList(java.util.ArrayList) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) MutableVector3(com.fastasyncworldedit.core.math.MutableVector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3) IdMask(com.fastasyncworldedit.core.function.mask.IdMask)

Example 3 with IdMask

use of com.fastasyncworldedit.core.function.mask.IdMask in project FastAsyncWorldEdit by IntellectualSites.

the class BrushCommands method recursiveBrush.

@Command(name = "recursive", aliases = { "recurse", "r" }, desc = "Set all connected blocks", descFooter = "Set all connected blocks\n" + "Note: Set a mask to recurse along specific blocks")
@CommandPermissions("worldedit.brush.recursive")
public void recursiveBrush(InjectedValueAccess context, EditSession editSession, @Arg(desc = "Pattern") Pattern fill, @Arg(desc = "The radius to sample for blending", def = "5") Expression radius, @Switch(name = 'd', desc = "Apply in depth first order") boolean depthFirst) throws WorldEditException {
    worldEdit.checkMaxBrushRadius(radius);
    set(context, new RecurseBrush(depthFirst), "worldedit.brush.recursive").setSize(radius).setFill(fill).setMask(new IdMask(editSession));
}
Also used : IdMask(com.fastasyncworldedit.core.function.mask.IdMask) RecurseBrush(com.fastasyncworldedit.core.command.tool.brush.RecurseBrush) ScatterCommand(com.fastasyncworldedit.core.command.tool.brush.ScatterCommand) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 4 with IdMask

use of com.fastasyncworldedit.core.function.mask.IdMask in project FastAsyncWorldEdit by IntellectualSites.

the class RecursivePickaxe method actPrimary.

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
    World world = (World) clicked.getExtent();
    final BlockVector3 pos = clicked.toBlockPoint();
    BlockVector3 origin = clicked.toVector().toBlockPoint();
    BlockType initialType = world.getBlock(origin).getBlockType();
    if (initialType.getMaterial().isAir()) {
        return false;
    }
    if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
        return false;
    }
    try (EditSession editSession = session.createEditSession(player, "RecursivePickaxe")) {
        editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
        // FAWE start
        final int radius = (int) range;
        final BlockReplace replace = new BlockReplace(editSession, (BlockTypes.AIR.getDefaultState()));
        editSession.setMask(null);
        RecursiveVisitor visitor = new RecursiveVisitor(new IdMask(editSession), replace, radius, editSession.getMinY(), editSession.getMaxY(), editSession);
        // TODO: Fix below
        // visitor.visit(pos);
        // Operations.completeBlindly(visitor);
        recurse(server, editSession, world, pos, origin, radius, initialType, visitor.getVisited());
        // FAWE end
        editSession.flushQueue();
        session.remember(editSession);
    }
    return true;
}
Also used : IdMask(com.fastasyncworldedit.core.function.mask.IdMask) BlockType(com.sk89q.worldedit.world.block.BlockType) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) EditSession(com.sk89q.worldedit.EditSession) World(com.sk89q.worldedit.world.World) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace)

Aggregations

IdMask (com.fastasyncworldedit.core.function.mask.IdMask)4 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)3 EditSession (com.sk89q.worldedit.EditSession)2 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 Mask (com.sk89q.worldedit.function.mask.Mask)2 RecurseBrush (com.fastasyncworldedit.core.command.tool.brush.RecurseBrush)1 ScatterCommand (com.fastasyncworldedit.core.command.tool.brush.ScatterCommand)1 Caption (com.fastasyncworldedit.core.configuration.Caption)1 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)1 DFSRecursiveVisitor (com.fastasyncworldedit.core.function.visitor.DFSRecursiveVisitor)1 MutableVector3 (com.fastasyncworldedit.core.math.MutableVector3)1 FuzzyRegionSelector (com.fastasyncworldedit.core.regions.selector.FuzzyRegionSelector)1 PolyhedralRegionSelector (com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector)1 MaskTraverser (com.fastasyncworldedit.core.util.MaskTraverser)1 Strings (com.google.common.base.Strings)1 LocalSession (com.sk89q.worldedit.LocalSession)1 WorldEdit (com.sk89q.worldedit.WorldEdit)1 WorldEditException (com.sk89q.worldedit.WorldEditException)1 BaseItemStack (com.sk89q.worldedit.blocks.BaseItemStack)1 SelectorChoice (com.sk89q.worldedit.command.argument.SelectorChoice)1