Search in sources :

Example 11 with MaskTraverser

use of com.fastasyncworldedit.core.util.MaskTraverser in project FastAsyncWorldEdit by IntellectualSites.

the class ClipboardCommands method copy.

@Command(name = "/copy", aliases = "/cp", desc = "Copy the selection to the clipboard")
@CommandPermissions("worldedit.clipboard.copy")
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public void copy(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Switch(name = 'e', desc = "Also copy entities") boolean copyEntities, @Switch(name = 'b', desc = "Also copy biomes") boolean copyBiomes, // FAWE start
@Switch(name = 'c', desc = "Set the origin of the clipboard to the center of the region, at the region's lowest " + "y-level.") boolean centerClipboard, @ArgFlag(name = 'm', desc = "Set the include mask, non-matching blocks become air", def = "") Mask mask) throws WorldEditException {
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 max = region.getMaximumPoint();
    long volume = ((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1);
    FaweLimit limit = actor.getLimit();
    if (volume >= limit.MAX_CHECKS) {
        throw FaweCache.MAX_CHECKS;
    }
    session.setClipboard(null);
    Clipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
    clipboard.setOrigin(centerClipboard ? region.getCenter().toBlockPoint().withY(region.getMinimumY()) : session.getPlacementPosition(actor));
    ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
    copy.setCopyingEntities(copyEntities);
    copy.setCopyingBiomes(copyBiomes);
    Mask sourceMask = editSession.getSourceMask();
    Region[] regions = editSession.getAllowedRegions();
    Region allowedRegion;
    if (regions == null || regions.length == 0) {
        allowedRegion = new NullRegion();
    } else {
        allowedRegion = new RegionIntersection(regions);
    }
    final Mask firstSourceMask = mask != null ? mask : sourceMask;
    final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize();
    if (finalMask != Masks.alwaysTrue()) {
        copy.setSourceMask(finalMask);
    }
    if (sourceMask != null) {
        editSession.setSourceMask(null);
        new MaskTraverser(sourceMask).reset(editSession);
        editSession.setSourceMask(null);
    }
    try {
        Operations.completeLegacy(copy);
    } catch (Throwable e) {
        throw e;
    } finally {
        clipboard.flush();
    }
    session.setClipboard(new ClipboardHolder(clipboard));
    copy.getStatusMessages().forEach(actor::print);
// FAWE end
}
Also used : BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) ClipboardMask(com.sk89q.worldedit.internal.annotation.ClipboardMask) Mask(com.sk89q.worldedit.function.mask.Mask) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) NullRegion(com.sk89q.worldedit.regions.NullRegion) RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) FaweLimit(com.fastasyncworldedit.core.limit.FaweLimit) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) ReadOnlyClipboard(com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 12 with MaskTraverser

use of com.fastasyncworldedit.core.util.MaskTraverser in project FastAsyncWorldEdit by IntellectualSites.

the class ClipboardCommands method cut.

/*
    @Command(
        name = "/lazycut",
        desc = "Lazily cut the selection to the clipboard"
    )
    @CommandPermissions("worldedit.clipboard.lazycut")
    public void lazyCut(Actor actor, LocalSession session, EditSession editSession,
                        @Selection final Region region,
                        @Switch(name = 'e', desc = "Skip copy entities")
                            boolean skipEntities,
                        @ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "")
                            Mask maskOpt,
                        @Switch(name = 'b', desc = "Also copy biomes")
                            boolean copyBiomes) throws WorldEditException {
        BlockVector3 min = region.getMinimumPoint();
        BlockVector3 max = region.getMaximumPoint();
        long volume = ((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1);
        FaweLimit limit = actor.getLimit();
        if (volume >= limit.MAX_CHECKS) {
            throw FaweCache.MAX_CHECKS;
        }
        if (volume >= limit.MAX_CHANGES) {
            throw FaweCache.MAX_CHANGES;
        }
        session.setClipboard(null);

        ReadOnlyClipboard lazyClipboard = new WorldCutClipboard(editSession, region, !skipEntities, copyBiomes);
        clipboard.setOrigin(session.getPlacementPosition(actor));
        session.setClipboard(new ClipboardHolder(lazyClipboard));
        actor.print(Caption.of("fawe.worldedit.cut.command.cut.lazy", region.getArea()));
    }*/
// FAWE end
@Command(name = "/cut", desc = "Cut the selection to the clipboard", descFooter = "WARNING: Cutting and pasting entities cannot be undone!")
@CommandPermissions("worldedit.clipboard.cut")
@Logging(REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public void cut(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "Pattern to leave in place of the selection", def = "air") Pattern leavePattern, @Switch(name = 'e', desc = "Also cut entities") boolean copyEntities, @Switch(name = 'b', desc = "Also copy biomes, source biomes are unaffected") boolean copyBiomes, @ArgFlag(name = 'm', desc = "Set the exclude mask, non-matching blocks become air") Mask mask) throws WorldEditException {
    // FAWE start - Inject limits & respect source mask
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 max = region.getMaximumPoint();
    long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1));
    FaweLimit limit = actor.getLimit();
    if (volume >= limit.MAX_CHECKS) {
        throw FaweCache.MAX_CHECKS;
    }
    if (volume >= limit.MAX_CHANGES) {
        throw FaweCache.MAX_CHANGES;
    }
    session.setClipboard(null);
    BlockArrayClipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
    clipboard.setOrigin(session.getPlacementPosition(actor));
    ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
    copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
    copy.setCopyingEntities(copyEntities);
    copy.setRemovingEntities(true);
    copy.setCopyingBiomes(copyBiomes);
    Mask sourceMask = editSession.getSourceMask();
    Region[] regions = editSession.getAllowedRegions();
    Region allowedRegion;
    if (regions == null || regions.length == 0) {
        allowedRegion = new NullRegion();
    } else {
        allowedRegion = new RegionIntersection(regions);
    }
    final Mask firstSourceMask = mask != null ? mask : sourceMask;
    final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize();
    if (finalMask != Masks.alwaysTrue()) {
        copy.setSourceMask(finalMask);
    }
    if (sourceMask != null) {
        editSession.setSourceMask(null);
        new MaskTraverser(sourceMask).reset(editSession);
        editSession.setSourceMask(null);
    }
    try {
        Operations.completeLegacy(copy);
    } catch (Throwable e) {
        throw e;
    } finally {
        clipboard.flush();
    }
    session.setClipboard(new ClipboardHolder(clipboard));
    if (!actor.hasPermission("fawe.tips")) {
        actor.print(Caption.of("fawe.tips.tip.lazycut"));
    }
    copy.getStatusMessages().forEach(actor::print);
// FAWE end
}
Also used : BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) ClipboardMask(com.sk89q.worldedit.internal.annotation.ClipboardMask) Mask(com.sk89q.worldedit.function.mask.Mask) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) NullRegion(com.sk89q.worldedit.regions.NullRegion) RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) FaweLimit(com.fastasyncworldedit.core.limit.FaweLimit) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) Logging(com.sk89q.worldedit.command.util.Logging) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 13 with MaskTraverser

use of com.fastasyncworldedit.core.util.MaskTraverser in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method count.

@Command(name = "/count", desc = "Counts the number of blocks matching a mask")
@CommandPermissions("worldedit.analysis.count")
public int count(Actor actor, World world, LocalSession session, EditSession editSession, @Arg(desc = "The mask of blocks to match") Mask mask) throws WorldEditException {
    // FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
    new MaskTraverser(mask).setNewExtent(editSession);
    // FAWE end
    int count = editSession.countBlocks(session.getSelection(world), mask);
    actor.print(Caption.of("worldedit.count.counted", TextComponent.of(count)));
    return count;
}
Also used : MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 14 with MaskTraverser

use of com.fastasyncworldedit.core.util.MaskTraverser in project FastAsyncWorldEdit by IntellectualSites.

the class UtilityCommands method removeNear.

@Command(name = "removenear", aliases = { "/removenear" }, desc = "Remove blocks near you.")
@CommandPermissions("worldedit.removenear")
@Logging(PLACEMENT)
public int removeNear(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The mask of blocks to remove") Mask mask, @Arg(desc = "The radius of the square to remove from", def = "50") int radius) throws WorldEditException {
    // FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
    new MaskTraverser(mask).setNewExtent(editSession);
    // FAWE end
    radius = Math.max(1, radius);
    we.checkMaxRadius(radius);
    int affected = editSession.removeNear(session.getPlacementPosition(actor), mask, radius);
    actor.print(Caption.of("worldedit.removenear.removed", TextComponent.of(affected)));
    return affected;
}
Also used : MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 15 with MaskTraverser

use of com.fastasyncworldedit.core.util.MaskTraverser in project FastAsyncWorldEdit by IntellectualSites.

the class RegionCommands method smooth.

@Command(name = "/smooth", desc = "Smooth the elevation in the selection", descFooter = "Example: '//smooth 1 grass_block,dirt,stone' would only smooth natural surface terrain.")
@CommandPermissions("worldedit.region.smooth")
@Logging(REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public int smooth(Actor actor, EditSession editSession, @Selection Region region, @Arg(desc = "# of iterations to perform", def = "1") int iterations, @Arg(desc = "The mask of blocks to use as the height map", def = "") Mask mask) throws WorldEditException {
    // FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
    new MaskTraverser(mask).setNewExtent(editSession);
    // FAWE end
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 max = region.getMaximumPoint();
    long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1));
    FaweLimit limit = actor.getLimit();
    if (volume >= limit.MAX_CHECKS) {
        throw FaweCache.MAX_CHECKS;
    }
    int affected;
    try {
        HeightMap heightMap = new HeightMap(editSession, region, mask);
        HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
        affected = heightMap.applyFilter(filter, iterations);
        actor.print(Caption.of("worldedit.smooth.changed", TextComponent.of(affected)));
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    return affected;
}
Also used : HeightMapFilter(com.sk89q.worldedit.math.convolution.HeightMapFilter) HeightMap(com.sk89q.worldedit.math.convolution.HeightMap) SnowHeightMap(com.sk89q.worldedit.math.convolution.SnowHeightMap) FaweLimit(com.fastasyncworldedit.core.limit.FaweLimit) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) BlockVector3(com.sk89q.worldedit.math.BlockVector3) GaussianKernel(com.sk89q.worldedit.math.convolution.GaussianKernel) Logging(com.sk89q.worldedit.command.util.Logging) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

MaskTraverser (com.fastasyncworldedit.core.util.MaskTraverser)20 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)12 Command (org.enginehub.piston.annotation.Command)12 Logging (com.sk89q.worldedit.command.util.Logging)10 Preload (com.sk89q.worldedit.command.util.annotation.Preload)9 Mask (com.sk89q.worldedit.function.mask.Mask)9 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)8 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)8 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)6 RegionMask (com.sk89q.worldedit.function.mask.RegionMask)4 SolidBlockMask (com.sk89q.worldedit.function.mask.SolidBlockMask)4 FaweLimit (com.fastasyncworldedit.core.limit.FaweLimit)3 ForwardExtentCopy (com.sk89q.worldedit.function.operation.ForwardExtentCopy)3 Region (com.sk89q.worldedit.regions.Region)3 MultiClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder)2 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)2 ResettableMask (com.fastasyncworldedit.core.function.mask.ResettableMask)2 SingleBlockTypeMask (com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask)2 WallMakeMask (com.fastasyncworldedit.core.function.mask.WallMakeMask)2 ExtentTraverser (com.fastasyncworldedit.core.util.ExtentTraverser)2