Search in sources :

Example 6 with MaskTraverser

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

the class RegionCommands method move.

@Command(name = "/move", aliases = { "/mv" }, desc = "Move the contents of the selection")
@CommandPermissions("worldedit.region.move")
@Logging(ORIENTATION_REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public int move(Actor actor, World world, EditSession editSession, LocalSession session, @Selection Region region, @Arg(desc = "# of blocks to move", def = "1") int count, @Arg(desc = "The direction to move", def = Direction.AIM) @Direction(includeDiagonals = true) BlockVector3 direction, @Arg(desc = "The pattern of blocks to leave", def = "air") Pattern replace, @Switch(name = 's', desc = "Shift the selection to the target location") boolean moveSelection, @Switch(name = 'a', desc = "Ignore air blocks") boolean ignoreAirBlocks, @Switch(name = 'e', desc = "Also copy entities") boolean copyEntities, @Switch(name = 'b', desc = "Also copy biomes") boolean copyBiomes, @ArgFlag(name = 'm', desc = "Set the include mask, non-matching blocks become air") Mask mask) throws WorldEditException {
    checkCommandArgument(count >= 1, "Count must be >= 1");
    // FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
    new MaskTraverser(mask).setNewExtent(editSession);
    // FAWE end
    Mask combinedMask;
    if (ignoreAirBlocks) {
        if (mask == null) {
            combinedMask = new ExistingBlockMask(editSession);
        } else {
            combinedMask = new MaskIntersection(mask, new ExistingBlockMask(editSession));
        }
    } else {
        combinedMask = mask;
    }
    int affected = editSession.moveRegion(region, direction, count, copyEntities, copyBiomes, combinedMask, replace);
    if (moveSelection) {
        try {
            region.shift(direction.multiply(count));
            session.getRegionSelector(world).learnChanges();
            session.getRegionSelector(world).explainRegionAdjust(actor, session);
        } catch (RegionOperationException e) {
            actor.printError(TextComponent.of(e.getMessage()));
        }
    }
    actor.print(Caption.of("worldedit.move.moved", TextComponent.of(affected)));
    return affected;
}
Also used : MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) SolidBlockMask(com.sk89q.worldedit.function.mask.SolidBlockMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) Mask(com.sk89q.worldedit.function.mask.Mask) RegionOperationException(com.sk89q.worldedit.regions.RegionOperationException) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) 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 7 with MaskTraverser

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

the class BrushTool method trace.

private Vector3 trace(EditSession editSession, Player player, int range, boolean useLastBlock) {
    Mask mask = traceMask == null ? new SolidBlockMask(editSession) : traceMask;
    new MaskTraverser(mask).reset(editSession);
    MaskedTargetBlock tb = new MaskedTargetBlock(mask, player, range, 0.2);
    return tb.getMaskedTargetBlock(useLastBlock);
}
Also used : MaskedTargetBlock(com.fastasyncworldedit.core.function.mask.MaskedTargetBlock) SolidBlockMask(com.sk89q.worldedit.function.mask.SolidBlockMask) Mask(com.sk89q.worldedit.function.mask.Mask) SolidBlockMask(com.sk89q.worldedit.function.mask.SolidBlockMask) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser)

Example 8 with MaskTraverser

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

the class PasteBuilder method build.

// FAWE end
/**
 * Build the operation.
 *
 * @return the operation
 */
public Operation build() {
    // FAWE start
    Extent extent = clipboard;
    if (!transform.isIdentity()) {
        extent = new BlockTransformExtent(extent, transform);
    }
    // FAWE end
    ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(), targetExtent, to);
    copy.setTransform(transform);
    // FAWE start
    copy.setCopyingEntities(copyEntities);
    copy.setCopyingBiomes(copyBiomes && clipboard.hasBiomes());
    if (this.canApply != null) {
        copy.setFilterFunction(this.canApply);
    }
    // FAWE end
    if (ignoreAirBlocks) {
        // FAWE start - respect clipboard
        sourceMask = MaskIntersection.of(sourceMask, new ExistingBlockMask(clipboard));
    }
    if (targetExtent instanceof EditSession) {
        Mask esSourceMask = ((EditSession) targetExtent).getSourceMask();
        if (esSourceMask == Masks.alwaysFalse()) {
            return null;
        }
        if (esSourceMask != null) {
            new MaskTraverser(esSourceMask).reset(extent);
            ((EditSession) targetExtent).setSourceMask(null);
            sourceMask = MaskIntersection.of(sourceMask, esSourceMask);
        }
    }
    // FAWE end
    if (sourceMask != null && sourceMask != Masks.alwaysTrue()) {
        copy.setSourceMask(sourceMask);
    }
    copy.setCopyingEntities(copyEntities);
    copy.setCopyingBiomes(copyBiomes && clipboard.hasBiomes());
    return copy;
}
Also used : BlockTransformExtent(com.sk89q.worldedit.extent.transform.BlockTransformExtent) Extent(com.sk89q.worldedit.extent.Extent) BlockTransformExtent(com.sk89q.worldedit.extent.transform.BlockTransformExtent) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) Mask(com.sk89q.worldedit.function.mask.Mask) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) EditSession(com.sk89q.worldedit.EditSession) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy)

Example 9 with MaskTraverser

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

the class FuzzyRegionSelector method selectSecondary.

@Override
public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) {
    this.positions.add(position);
    new MaskTraverser(getMask()).reset(getExtent());
    this.region.select(position);
    return true;
}
Also used : MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser)

Example 10 with MaskTraverser

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

the class ForwardExtentCopy method resume.

@Override
public Operation resume(RunContext run) throws WorldEditException {
    // FAWE start
    if (currentTransform == null) {
        currentTransform = transform;
    }
    // FAWE end
    if (lastBiomeVisitor != null) {
        affectedBiomeCols += lastBiomeVisitor.getAffected();
        lastBiomeVisitor = null;
    }
    if (lastEntityVisitor != null) {
        affectedEntities += lastEntityVisitor.getAffected();
        lastEntityVisitor = null;
    }
    // FAWE start
    Extent finalDest = destination;
    BlockVector3 translation = to.subtract(from);
    if (!translation.equals(BlockVector3.ZERO)) {
        finalDest = new BlockTranslateExtent(finalDest, translation.getBlockX(), translation.getBlockY(), translation.getBlockZ());
    }
    // FAWE end
    // FAWE start - RegionVisitor > ExtentBlockCopy
    RegionFunction copy;
    RegionVisitor blockCopy = null;
    PositionTransformExtent transExt = null;
    if (!currentTransform.isIdentity()) {
        if (!(currentTransform instanceof AffineTransform) || ((AffineTransform) currentTransform).isOffAxis()) {
            transExt = new PositionTransformExtent(source, currentTransform.inverse());
            transExt.setOrigin(from);
            copy = new SimpleBlockCopy(transExt, finalDest);
            if (this.filterFunction != null) {
                copy = new IntersectRegionFunction(filterFunction, copy);
            }
            if (sourceFunction != null) {
                copy = CombinedRegionFunction.combine(copy, sourceFunction);
            }
            if (sourceMask != Masks.alwaysTrue()) {
                new MaskTraverser(sourceMask).reset(transExt);
                copy = new RegionMaskingFilter(source, sourceMask, copy);
            }
            if (copyingBiomes && (source.isWorld() || region instanceof FlatRegion)) {
                copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest));
            }
            blockCopy = new BackwardsExtentBlockCopy(region, from, transform, copy);
        } else {
            transExt = new PositionTransformExtent(finalDest, currentTransform);
            transExt.setOrigin(from);
            finalDest = transExt;
        }
    }
    if (blockCopy == null) {
        RegionFunction maskFunc = null;
        if (sourceFunction != null) {
            BlockVector3 disAbs = translation.abs();
            BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
            boolean overlap = (disAbs.getBlockX() < size.getBlockX() && disAbs.getBlockY() < size.getBlockY() && disAbs.getBlockZ() < size.getBlockZ());
            RegionFunction copySrcFunc = sourceFunction;
            if (overlap && translation.length() != 0) {
                int x = translation.getBlockX();
                int y = translation.getBlockY();
                int z = translation.getBlockZ();
                maskFunc = position -> {
                    BlockVector3 bv = BlockVector3.at(position.getBlockX() + x, position.getBlockY() + y, position.getBlockZ() + z);
                    if (region.contains(bv)) {
                        return sourceFunction.apply(bv);
                    }
                    return false;
                };
                copySrcFunc = position -> {
                    BlockVector3 bv = BlockVector3.at(position.getBlockX() - x, position.getBlockY() - y, position.getBlockZ() - z);
                    if (!region.contains(bv)) {
                        return sourceFunction.apply(position);
                    }
                    return false;
                };
            }
            copy = new CombinedBlockCopy(source, finalDest, copySrcFunc);
        } else {
            copy = new SimpleBlockCopy(source, finalDest);
        }
        if (this.filterFunction != null) {
            copy = new IntersectRegionFunction(filterFunction, copy);
        }
        if (sourceMask != Masks.alwaysTrue()) {
            if (maskFunc != null) {
                copy = new RegionMaskTestFunction(sourceMask, copy, maskFunc);
            } else {
                copy = new RegionMaskingFilter(source, sourceMask, copy);
            }
        }
        if (copyingBiomes && (source.isWorld() || region instanceof FlatRegion)) {
            copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest));
        }
        ExtentTraverser<ParallelQueueExtent> queueTraverser = new ExtentTraverser<>(finalDest).find(ParallelQueueExtent.class);
        Extent preloader = queueTraverser != null ? queueTraverser.get() : source;
        blockCopy = new RegionVisitor(region, copy, preloader);
    }
    List<? extends Entity> entities;
    if (copyingEntities) {
        // filter players since they can't be copied
        entities = source.getEntities(region);
        entities.removeIf(entity -> {
            EntityProperties properties = entity.getFacet(EntityProperties.class);
            return properties != null && !properties.isPasteable();
        });
    } else {
        entities = Collections.emptyList();
    }
    for (int i = 0; i < repetitions; i++) {
        Operations.completeBlindly(blockCopy);
        if (!entities.isEmpty()) {
            ExtentEntityCopy entityCopy = new ExtentEntityCopy(source, from.toVector3(), destination, to.toVector3(), currentTransform);
            entityCopy.setRemoving(removingEntities);
            List<? extends Entity> entities2 = Lists.newArrayList(source.getEntities(region));
            entities2.removeIf(entity -> {
                EntityProperties properties = entity.getFacet(EntityProperties.class);
                return properties != null && !properties.isPasteable();
            });
            EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy);
            Operations.completeBlindly(entityVisitor);
            affectedEntities += entityVisitor.getAffected();
        }
        if (transExt != null) {
            currentTransform = currentTransform.combine(transform);
            transExt.setTransform(currentTransform);
        }
    }
    affectedBlocks += blockCopy.getAffected();
    // FAWE end
    return null;
}
Also used : PositionTransformExtent(com.fastasyncworldedit.core.extent.PositionTransformExtent) ParallelQueueExtent(com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent) BlockTranslateExtent(com.fastasyncworldedit.core.extent.BlockTranslateExtent) Extent(com.sk89q.worldedit.extent.Extent) RegionMaskTestFunction(com.fastasyncworldedit.core.function.RegionMaskTestFunction) EntityVisitor(com.sk89q.worldedit.function.visitor.EntityVisitor) SimpleBlockCopy(com.fastasyncworldedit.core.function.block.SimpleBlockCopy) CombinedBlockCopy(com.fastasyncworldedit.core.function.block.CombinedBlockCopy) RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) ExtentEntityCopy(com.sk89q.worldedit.function.entity.ExtentEntityCopy) BiomeCopy(com.fastasyncworldedit.core.function.block.BiomeCopy) PositionTransformExtent(com.fastasyncworldedit.core.extent.PositionTransformExtent) EntityProperties(com.sk89q.worldedit.entity.metadata.EntityProperties) ParallelQueueExtent(com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent) RegionMaskingFilter(com.sk89q.worldedit.function.RegionMaskingFilter) RegionFunction(com.sk89q.worldedit.function.RegionFunction) CombinedRegionFunction(com.sk89q.worldedit.function.CombinedRegionFunction) IntersectRegionFunction(com.fastasyncworldedit.core.function.visitor.IntersectRegionFunction) FlatRegion(com.sk89q.worldedit.regions.FlatRegion) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) BlockVector3(com.sk89q.worldedit.math.BlockVector3) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) IntersectRegionFunction(com.fastasyncworldedit.core.function.visitor.IntersectRegionFunction) BlockTranslateExtent(com.fastasyncworldedit.core.extent.BlockTranslateExtent)

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