Search in sources :

Example 1 with MaskIntersection

use of com.sk89q.worldedit.function.mask.MaskIntersection in project FastAsyncWorldEdit by IntellectualSites.

the class RegionCommands method stack.

@Command(name = "/stack", desc = "Repeat the contents of the selection")
@CommandPermissions("worldedit.region.stack")
@Preload(Preload.PreloadCheck.PRELOAD)
@Logging(ORIENTATION_REGION)
public int stack(Actor actor, World world, EditSession editSession, LocalSession session, @Selection Region region, @Arg(desc = "# of copies to stack", def = "1") @Confirm(Confirm.Processor.REGION) int count, @Arg(desc = "The direction to stack", def = Direction.AIM) @Direction(includeDiagonals = true) BlockVector3 direction, @Switch(name = 's', desc = "Shift the selection to the last stacked copy") 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 {
    // 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.stackCuboidRegion(region, direction, count, copyEntities, copyBiomes, combinedMask);
    if (moveSelection) {
        try {
            final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
            final BlockVector3 shiftVector = direction.multiply(size).multiply(count);
            region.shift(shiftVector);
            session.getRegionSelector(world).learnChanges();
            session.getRegionSelector(world).explainRegionAdjust(actor, session);
        } catch (RegionOperationException e) {
            actor.printError(TextComponent.of(e.getMessage()));
        }
    }
    actor.print(Caption.of("worldedit.stack.changed", 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) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Logging(com.sk89q.worldedit.command.util.Logging) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 2 with MaskIntersection

use of com.sk89q.worldedit.function.mask.MaskIntersection 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 3 with MaskIntersection

use of com.sk89q.worldedit.function.mask.MaskIntersection in project FastAsyncWorldEdit by IntellectualSites.

the class MaskTraverser method reset.

private void reset(Mask mask, Extent newExtent) {
    if (mask == null) {
        return;
    }
    if (mask instanceof ResettableMask) {
        ((ResettableMask) mask).reset();
    }
    Class<?> current = mask.getClass();
    while (current.getSuperclass() != null) {
        if (mask instanceof AbstractExtentMask) {
            AbstractExtentMask mask1 = (AbstractExtentMask) mask;
            mask1.setExtent(newExtent);
        } else {
            try {
                Field field = current.getDeclaredField("extent");
                field.setAccessible(true);
                field.set(mask, newExtent);
            } catch (NoSuchFieldException | IllegalAccessException ignored) {
            }
        }
        if (mask instanceof MaskIntersection) {
            MaskIntersection mask1 = (MaskIntersection) mask;
            try {
                Field field = mask1.getClass().getDeclaredField("masks");
                field.setAccessible(true);
                Collection<Mask> masks = (Collection<Mask>) field.get(mask);
                for (Mask next : masks) {
                    reset(next, newExtent);
                }
            } catch (NoSuchFieldException | IllegalAccessException ignored) {
            }
        }
        try {
            Field field = current.getDeclaredField("mask");
            field.setAccessible(true);
            Mask next = (Mask) field.get(mask);
            reset(next, newExtent);
        } catch (NoSuchFieldException | IllegalAccessException ignored) {
        }
        try {
            Field field = current.getDeclaredField("masks");
            field.setAccessible(true);
            Collection<Mask> masks = (Collection<Mask>) field.get(mask);
            for (Mask next : masks) {
                reset(next, newExtent);
            }
        } catch (NoSuchFieldException | IllegalAccessException ignored) {
        }
        current = current.getSuperclass();
    }
}
Also used : Field(java.lang.reflect.Field) AbstractExtentMask(com.sk89q.worldedit.function.mask.AbstractExtentMask) MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) ResettableMask(com.fastasyncworldedit.core.function.mask.ResettableMask) AbstractExtentMask(com.sk89q.worldedit.function.mask.AbstractExtentMask) Mask(com.sk89q.worldedit.function.mask.Mask) Collection(java.util.Collection) ResettableMask(com.fastasyncworldedit.core.function.mask.ResettableMask)

Example 4 with MaskIntersection

use of com.sk89q.worldedit.function.mask.MaskIntersection in project FastAsyncWorldEdit by IntellectualSites.

the class MaskTraverser method setNewExtent.

private void setNewExtent(Mask mask, Extent newExtent) {
    if (mask == null) {
        return;
    }
    Class<?> current = mask.getClass();
    while (current.getSuperclass() != null) {
        if (mask instanceof AbstractExtentMask) {
            AbstractExtentMask mask1 = (AbstractExtentMask) mask;
            mask1.setExtent(newExtent);
        } else {
            try {
                Field field = current.getDeclaredField("extent");
                field.setAccessible(true);
                field.set(mask, newExtent);
            } catch (NoSuchFieldException | IllegalAccessException ignored) {
            }
        }
        if (mask instanceof MaskIntersection) {
            MaskIntersection mask1 = (MaskIntersection) mask;
            try {
                Field field = mask1.getClass().getDeclaredField("masks");
                field.setAccessible(true);
                Collection<Mask> masks = (Collection<Mask>) field.get(mask);
                for (Mask next : masks) {
                    setNewExtent(next, newExtent);
                }
            } catch (NoSuchFieldException | IllegalAccessException ignored) {
            }
        }
        try {
            Field field = current.getDeclaredField("mask");
            field.setAccessible(true);
            Mask next = (Mask) field.get(mask);
            setNewExtent(next, newExtent);
        } catch (NoSuchFieldException | IllegalAccessException ignored) {
        }
        try {
            Field field = current.getDeclaredField("masks");
            field.setAccessible(true);
            Collection<Mask> masks = (Collection<Mask>) field.get(mask);
            for (Mask next : masks) {
                setNewExtent(next, newExtent);
            }
        } catch (NoSuchFieldException | IllegalAccessException ignored) {
        }
        current = current.getSuperclass();
    }
}
Also used : Field(java.lang.reflect.Field) AbstractExtentMask(com.sk89q.worldedit.function.mask.AbstractExtentMask) MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) ResettableMask(com.fastasyncworldedit.core.function.mask.ResettableMask) AbstractExtentMask(com.sk89q.worldedit.function.mask.AbstractExtentMask) Mask(com.sk89q.worldedit.function.mask.Mask) Collection(java.util.Collection)

Example 5 with MaskIntersection

use of com.sk89q.worldedit.function.mask.MaskIntersection in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method fixLiquid.

/**
 * Fix liquids so that they turn into stationary blocks and extend outward.
 *
 * @param origin the original position
 * @param radius the radius to fix
 * @param fluid  the type of the fluid
 * @return number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
public int fixLiquid(BlockVector3 origin, double radius, BlockType fluid) throws MaxChangedBlocksException {
    checkNotNull(origin);
    checkArgument(radius >= 0, "radius >= 0 required");
    // Our origins can only be liquids
    Mask liquidMask = new SingleBlockTypeMask(this, fluid);
    // But we will also visit air blocks
    MaskIntersection blockMask = new MaskUnion(liquidMask, Masks.negate(new ExistingBlockMask(this)));
    // There are boundaries that the routine needs to stay in
    Mask mask = new MaskIntersection(new BoundedHeightMask(minY, Math.min(origin.getBlockY(), maxY)), new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), blockMask);
    BlockReplace replace = new BlockReplace(this, fluid.getDefaultState());
    // FAWE start - provide extent for preloading, world min/maxY
    NonRisingVisitor visitor = new NonRisingVisitor(mask, replace, Integer.MAX_VALUE, minY, maxY, this);
    // Around the origin in a 3x3 block
    for (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) {
        if (liquidMask.test(position)) {
            visitor.visit(position);
        }
    }
    Operations.completeLegacy(visitor);
    return visitor.getAffected();
}
Also used : MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) SingleBlockTypeMask(com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask) NonRisingVisitor(com.sk89q.worldedit.function.visitor.NonRisingVisitor) BlockTypeMask(com.sk89q.worldedit.function.mask.BlockTypeMask) SingleBlockTypeMask(com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) BlockStateMask(com.sk89q.worldedit.function.mask.BlockStateMask) WallMakeMask(com.fastasyncworldedit.core.function.mask.WallMakeMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) BoundedHeightMask(com.sk89q.worldedit.function.mask.BoundedHeightMask) ResettableMask(com.fastasyncworldedit.core.function.mask.ResettableMask) Mask(com.sk89q.worldedit.function.mask.Mask) MaskUnion(com.fastasyncworldedit.core.function.mask.MaskUnion) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BoundedHeightMask(com.sk89q.worldedit.function.mask.BoundedHeightMask) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace) EllipsoidRegion(com.sk89q.worldedit.regions.EllipsoidRegion)

Aggregations

MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)14 Mask (com.sk89q.worldedit.function.mask.Mask)11 ResettableMask (com.fastasyncworldedit.core.function.mask.ResettableMask)7 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)7 RecursiveVisitor (com.sk89q.worldedit.function.visitor.RecursiveVisitor)6 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)6 SingleBlockTypeMask (com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask)5 WallMakeMask (com.fastasyncworldedit.core.function.mask.WallMakeMask)5 BlockStateMask (com.sk89q.worldedit.function.mask.BlockStateMask)5 BlockTypeMask (com.sk89q.worldedit.function.mask.BlockTypeMask)5 BoundedHeightMask (com.sk89q.worldedit.function.mask.BoundedHeightMask)5 RegionMask (com.sk89q.worldedit.function.mask.RegionMask)5 BlockReplace (com.sk89q.worldedit.function.block.BlockReplace)4 SolidBlockMask (com.sk89q.worldedit.function.mask.SolidBlockMask)4 EllipsoidRegion (com.sk89q.worldedit.regions.EllipsoidRegion)4 RadiusMask (com.fastasyncworldedit.core.function.mask.RadiusMask)3 MaskUnion (com.fastasyncworldedit.core.function.mask.MaskUnion)2 SurfaceMask (com.fastasyncworldedit.core.function.mask.SurfaceMask)2 BlockVectorSet (com.fastasyncworldedit.core.math.BlockVectorSet)2 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)2