Search in sources :

Example 1 with SingleBlockTypeMask

use of com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask 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)

Example 2 with SingleBlockTypeMask

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

the class BrushCommands method extinguishBrush.

@Command(name = "extinguish", aliases = { "ex" }, desc = "Shortcut fire extinguisher brush")
@CommandPermissions("worldedit.brush.ex")
public void extinguishBrush(InjectedValueAccess context, EditSession editSession, @Arg(desc = "The radius to extinguish", def = "5") Expression radius) throws WorldEditException {
    worldEdit.checkMaxBrushRadius(radius);
    set(context, new SphereBrush(), "worldedit.brush.ex").setSize(radius).setFill(BlockTypes.AIR.getDefaultState()).setMask(new SingleBlockTypeMask(editSession, BlockTypes.FIRE));
}
Also used : SingleBlockTypeMask(com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask) HollowSphereBrush(com.sk89q.worldedit.command.tool.brush.HollowSphereBrush) SphereBrush(com.sk89q.worldedit.command.tool.brush.SphereBrush) SurfaceSphereBrush(com.fastasyncworldedit.core.command.tool.brush.SurfaceSphereBrush) ScatterCommand(com.fastasyncworldedit.core.command.tool.brush.ScatterCommand) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 3 with SingleBlockTypeMask

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

the class BlockMask method tryOptimize.

@Override
public Mask tryOptimize() {
    int setStates = 0;
    BlockState setState = null;
    BlockState unsetState = null;
    int totalStates = 0;
    int setTypes = 0;
    BlockType setType = null;
    int totalTypes = 0;
    for (BlockType type : BlockTypesCache.values) {
        if (type != null) {
            totalTypes++;
            boolean hasAll = true;
            List<BlockState> all = type.getAllStates();
            for (BlockState state : all) {
                totalStates++;
                hasAll &= test(state);
            }
            if (hasAll) {
                setTypes++;
                setType = type;
                setStates += all.size();
                setState = type.getDefaultState();
            } else {
                for (BlockState state : all) {
                    if (test(state)) {
                        setStates++;
                        setState = state;
                    } else {
                        unsetState = state;
                    }
                }
            }
        }
    }
    if (setStates == 0) {
        return Masks.alwaysFalse();
    }
    if (setStates == totalStates) {
        return Masks.alwaysTrue();
    }
    if (setStates == 1) {
        return new SingleBlockStateMask(getExtent(), setState);
    }
    if (setStates == totalStates - 1) {
        return new InverseSingleBlockStateMask(getExtent(), unsetState);
    }
    if (setTypes == 1) {
        return new SingleBlockTypeMask(getExtent(), setType);
    }
    if (setTypes == totalTypes - 1) {
        throw new IllegalArgumentException("unsetType cannot be null when passed to InverseSingleBlockTypeMask");
    }
    return null;
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) BlockType(com.sk89q.worldedit.world.block.BlockType) SingleBlockTypeMask(com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask) SingleBlockStateMask(com.fastasyncworldedit.core.function.mask.SingleBlockStateMask)

Aggregations

SingleBlockTypeMask (com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask)3 ScatterCommand (com.fastasyncworldedit.core.command.tool.brush.ScatterCommand)1 SurfaceSphereBrush (com.fastasyncworldedit.core.command.tool.brush.SurfaceSphereBrush)1 MaskUnion (com.fastasyncworldedit.core.function.mask.MaskUnion)1 ResettableMask (com.fastasyncworldedit.core.function.mask.ResettableMask)1 SingleBlockStateMask (com.fastasyncworldedit.core.function.mask.SingleBlockStateMask)1 WallMakeMask (com.fastasyncworldedit.core.function.mask.WallMakeMask)1 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)1 HollowSphereBrush (com.sk89q.worldedit.command.tool.brush.HollowSphereBrush)1 SphereBrush (com.sk89q.worldedit.command.tool.brush.SphereBrush)1 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)1 BlockReplace (com.sk89q.worldedit.function.block.BlockReplace)1 BlockStateMask (com.sk89q.worldedit.function.mask.BlockStateMask)1 BlockTypeMask (com.sk89q.worldedit.function.mask.BlockTypeMask)1 BoundedHeightMask (com.sk89q.worldedit.function.mask.BoundedHeightMask)1 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)1 Mask (com.sk89q.worldedit.function.mask.Mask)1 MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)1 RegionMask (com.sk89q.worldedit.function.mask.RegionMask)1 NonRisingVisitor (com.sk89q.worldedit.function.visitor.NonRisingVisitor)1