Search in sources :

Example 1 with BlockTypeMask

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

the class UtilityCommands method extinguish.

@Command(name = "extinguish", aliases = { "/ex", "/ext", "/extinguish", "ex", "ext" }, desc = "Extinguish nearby fire")
@CommandPermissions("worldedit.extinguish")
@Logging(PLACEMENT)
public int extinguish(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The radius of the square to remove in", def = "") Integer radius) throws WorldEditException {
    LocalConfiguration config = we.getConfiguration();
    int defaultRadius = config.maxRadius != -1 ? Math.min(40, config.maxRadius) : 40;
    int size = radius != null ? Math.max(1, radius) : defaultRadius;
    we.checkMaxRadius(size);
    Mask mask = new BlockTypeMask(editSession, BlockTypes.FIRE);
    int affected = editSession.removeNear(session.getPlacementPosition(actor), mask, size);
    actor.print(Caption.of("worldedit.extinguish.removed", TextComponent.of(affected)));
    return affected;
}
Also used : BlockTypeMask(com.sk89q.worldedit.function.mask.BlockTypeMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) Mask(com.sk89q.worldedit.function.mask.Mask) BlockTypeMask(com.sk89q.worldedit.function.mask.BlockTypeMask) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 2 with BlockTypeMask

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

the class EditSession method drainArea.

/**
 * Drain nearby pools of water or lava, optionally removed waterlogged states from blocks.
 *
 * @param origin      the origin to drain from, which will search a 3x3 area
 * @param radius      the radius of the removal, where a value should be 0 or greater
 * @param waterlogged true to make waterlogged blocks non-waterlogged as well
 * @param plants      true to remove underwater plants
 * @return number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
public int drainArea(BlockVector3 origin, double radius, boolean waterlogged, boolean plants) throws MaxChangedBlocksException {
    checkNotNull(origin);
    checkArgument(radius >= 0, "radius >= 0 required");
    // FAWE start - liquidmask
    Mask liquidMask;
    if (plants) {
        liquidMask = new BlockTypeMask(this, BlockTypes.LAVA, BlockTypes.WATER, BlockTypes.BUBBLE_COLUMN, BlockTypes.KELP_PLANT, BlockTypes.KELP, BlockTypes.SEAGRASS, BlockTypes.TALL_SEAGRASS);
    } else {
        liquidMask = new BlockMaskBuilder().addTypes(BlockTypes.WATER, BlockTypes.LAVA, BlockTypes.BUBBLE_COLUMN).build(this);
    }
    // FAWE end
    if (waterlogged) {
        Map<String, String> stateMap = new HashMap<>();
        stateMap.put("waterlogged", "true");
        // FAWE start
        liquidMask = new MaskUnion(liquidMask, new BlockStateMask(this, stateMap, true));
    // FAWE end
    }
    Mask mask = new MaskIntersection(new BoundedHeightMask(minY, maxY), new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), // FAWE start
    liquidMask);
    // FAWE end
    BlockReplace replace;
    if (waterlogged) {
        replace = new BlockReplace(this, new WaterloggedRemover(this));
    } else {
        replace = new BlockReplace(this, BlockTypes.AIR.getDefaultState());
    }
    // FAWE start - provide extent for preloading, min/max y
    RecursiveVisitor visitor = new RecursiveVisitor(mask, replace, (int) (radius * 2 + 1), minY, maxY, this);
    // Around the origin in a 3x3 block
    for (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) {
        if (mask.test(position)) {
            visitor.visit(position);
        }
    }
    Operations.completeLegacy(visitor);
    // FAWE start
    return this.changes = visitor.getAffected();
// FAWE end
}
Also used : MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) HashMap(java.util.HashMap) 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) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) BlockStateMask(com.sk89q.worldedit.function.mask.BlockStateMask) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) WaterloggedRemover(com.sk89q.worldedit.function.pattern.WaterloggedRemover) 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) BlockMaskBuilder(com.fastasyncworldedit.core.function.mask.BlockMaskBuilder) BlockTypeMask(com.sk89q.worldedit.function.mask.BlockTypeMask) SingleBlockTypeMask(com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask) EllipsoidRegion(com.sk89q.worldedit.regions.EllipsoidRegion)

Aggregations

BlockTypeMask (com.sk89q.worldedit.function.mask.BlockTypeMask)2 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)2 Mask (com.sk89q.worldedit.function.mask.Mask)2 BlockMaskBuilder (com.fastasyncworldedit.core.function.mask.BlockMaskBuilder)1 MaskUnion (com.fastasyncworldedit.core.function.mask.MaskUnion)1 ResettableMask (com.fastasyncworldedit.core.function.mask.ResettableMask)1 SingleBlockTypeMask (com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask)1 WallMakeMask (com.fastasyncworldedit.core.function.mask.WallMakeMask)1 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)1 LocalConfiguration (com.sk89q.worldedit.LocalConfiguration)1 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)1 Logging (com.sk89q.worldedit.command.util.Logging)1 BlockReplace (com.sk89q.worldedit.function.block.BlockReplace)1 BlockStateMask (com.sk89q.worldedit.function.mask.BlockStateMask)1 BoundedHeightMask (com.sk89q.worldedit.function.mask.BoundedHeightMask)1 MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)1 RegionMask (com.sk89q.worldedit.function.mask.RegionMask)1 WaterloggedRemover (com.sk89q.worldedit.function.pattern.WaterloggedRemover)1 RecursiveVisitor (com.sk89q.worldedit.function.visitor.RecursiveVisitor)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1