Search in sources :

Example 6 with BlockReplace

use of com.sk89q.worldedit.function.block.BlockReplace in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method overlayCuboidBlocks.

/**
 * Places a layer of blocks on top of ground blocks in the given region
 * (as if it were a cuboid).
 *
 * @param region  the region
 * @param pattern the placed block pattern
 * @return number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
public int overlayCuboidBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
    checkNotNull(region);
    checkNotNull(pattern);
    BlockReplace replace = new BlockReplace(this, pattern);
    RegionOffset offset = new RegionOffset(BlockVector3.UNIT_Y, replace);
    // FAWE start
    int minY = region.getMinimumPoint().getBlockY();
    int maxY = Math.min(getMaximumPoint().getBlockY(), region.getMaximumPoint().getBlockY() + 1);
    SurfaceRegionFunction surface = new SurfaceRegionFunction(this, offset, minY, maxY);
    FlatRegionVisitor visitor = new FlatRegionVisitor(asFlatRegion(region), surface, this);
    // FAWE end
    Operations.completeBlindly(visitor);
    return this.changes = visitor.getAffected();
}
Also used : SurfaceRegionFunction(com.fastasyncworldedit.core.function.SurfaceRegionFunction) FlatRegionVisitor(com.sk89q.worldedit.function.visitor.FlatRegionVisitor) RegionOffset(com.sk89q.worldedit.function.util.RegionOffset) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace)

Example 7 with BlockReplace

use of com.sk89q.worldedit.function.block.BlockReplace in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method fillDirection.

/**
 * Fills an area recursively in the X/Z directions.
 *
 * @param origin    the location to start from
 * @param pattern   the block to fill with
 * @param radius    the radius of the spherical area to fill
 * @param depth     the maximum depth, starting from the origin
 * @param direction the direction to fill
 * @return the number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
public int fillDirection(final BlockVector3 origin, final Pattern pattern, final double radius, final int depth, BlockVector3 direction) throws MaxChangedBlocksException {
    checkNotNull(origin);
    checkNotNull(pattern);
    checkArgument(radius >= 0, "radius >= 0");
    checkArgument(depth >= 1, "depth >= 1");
    if (direction.equals(BlockVector3.UNIT_MINUS_Y)) {
        return fillXZ(origin, pattern, radius, depth, false);
    }
    Mask mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), Masks.negate(new ExistingBlockMask(EditSession.this)));
    // Want to replace blocks
    final BlockReplace replace = new BlockReplace(EditSession.this, pattern);
    // Pick how we're going to visit blocks
    RecursiveVisitor visitor = new DirectionalVisitor(mask, replace, origin, direction, (int) (radius * 2 + 1), minY, maxY);
    // Start at the origin
    visitor.visit(origin);
    // Execute
    Operations.completeBlindly(visitor);
    return this.changes = visitor.getAffected();
}
Also used : MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) DirectionalVisitor(com.fastasyncworldedit.core.function.visitor.DirectionalVisitor) 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) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace) EllipsoidRegion(com.sk89q.worldedit.regions.EllipsoidRegion)

Example 8 with BlockReplace

use of com.sk89q.worldedit.function.block.BlockReplace in project FastAsyncWorldEdit by IntellectualSites.

the class Extent method replaceBlocks.

/**
 * Replaces all the blocks matching a given mask, within a given region, to a block
 * returned by a given pattern.
 *
 * @param region  the region to replace the blocks within
 * @param mask    the mask that blocks must match
 * @param pattern the pattern that provides the new blocks
 * @return number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
default int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException {
    checkNotNull(region);
    checkNotNull(mask);
    checkNotNull(pattern);
    BlockReplace replace = new BlockReplace(this, pattern);
    RegionMaskingFilter filter = new RegionMaskingFilter(this, mask, replace);
    // FAWE start > add extent to RegionVisitor to allow chunk preloading
    RegionVisitor visitor = new RegionVisitor(region, filter, this);
    // FAWE end
    Operations.completeLegacy(visitor);
    return visitor.getAffected();
}
Also used : RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace) RegionMaskingFilter(com.sk89q.worldedit.function.RegionMaskingFilter)

Example 9 with BlockReplace

use of com.sk89q.worldedit.function.block.BlockReplace in project FastAsyncWorldEdit by IntellectualSites.

the class RecursivePickaxe method actPrimary.

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
    World world = (World) clicked.getExtent();
    final BlockVector3 pos = clicked.toBlockPoint();
    BlockVector3 origin = clicked.toVector().toBlockPoint();
    BlockType initialType = world.getBlock(origin).getBlockType();
    if (initialType.getMaterial().isAir()) {
        return false;
    }
    if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
        return false;
    }
    try (EditSession editSession = session.createEditSession(player, "RecursivePickaxe")) {
        editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
        // FAWE start
        final int radius = (int) range;
        final BlockReplace replace = new BlockReplace(editSession, (BlockTypes.AIR.getDefaultState()));
        editSession.setMask(null);
        RecursiveVisitor visitor = new RecursiveVisitor(new IdMask(editSession), replace, radius, editSession.getMinY(), editSession.getMaxY(), editSession);
        // TODO: Fix below
        // visitor.visit(pos);
        // Operations.completeBlindly(visitor);
        recurse(server, editSession, world, pos, origin, radius, initialType, visitor.getVisited());
        // FAWE end
        editSession.flushQueue();
        session.remember(editSession);
    }
    return true;
}
Also used : IdMask(com.fastasyncworldedit.core.function.mask.IdMask) BlockType(com.sk89q.worldedit.world.block.BlockType) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) EditSession(com.sk89q.worldedit.EditSession) World(com.sk89q.worldedit.world.World) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace)

Example 10 with BlockReplace

use of com.sk89q.worldedit.function.block.BlockReplace in project FastAsyncWorldEdit by IntellectualSites.

the class FloodFillTool method actPrimary.

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
    World world = (World) clicked.getExtent();
    BlockVector3 origin = clicked.toVector().toBlockPoint();
    BlockType initialType = world.getBlock(origin).getBlockType();
    if (initialType.getMaterial().isAir()) {
        return true;
    }
    if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
        return true;
    }
    try (EditSession editSession = session.createEditSession(player, "FloodFillTool")) {
        try {
            // FAWE start - Respect masks
            Mask mask = initialType.toMask(editSession);
            BlockReplace function = new BlockReplace(editSession, pattern);
            RecursiveVisitor visitor = new RecursiveVisitor(mask, function, range, editSession.getMinY(), editSession.getMaxY(), editSession);
            visitor.visit(origin);
            Operations.completeLegacy(visitor);
        // FAWE end
        } catch (MaxChangedBlocksException e) {
            player.print(Caption.of("worldedit.tool.max-block-changes"));
        } finally {
            session.remember(editSession);
        }
    }
    return true;
}
Also used : BlockType(com.sk89q.worldedit.world.block.BlockType) Mask(com.sk89q.worldedit.function.mask.Mask) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) EditSession(com.sk89q.worldedit.EditSession) World(com.sk89q.worldedit.world.World) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Aggregations

BlockReplace (com.sk89q.worldedit.function.block.BlockReplace)10 Mask (com.sk89q.worldedit.function.mask.Mask)7 RegionMask (com.sk89q.worldedit.function.mask.RegionMask)6 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)6 ResettableMask (com.fastasyncworldedit.core.function.mask.ResettableMask)5 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 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)5 RecursiveVisitor (com.sk89q.worldedit.function.visitor.RecursiveVisitor)5 EllipsoidRegion (com.sk89q.worldedit.regions.EllipsoidRegion)5 MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)4 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)3 MaskUnion (com.fastasyncworldedit.core.function.mask.MaskUnion)2 EditSession (com.sk89q.worldedit.EditSession)2 ForwardExtentCopy (com.sk89q.worldedit.function.operation.ForwardExtentCopy)2 NullRegion (com.sk89q.worldedit.regions.NullRegion)2 Region (com.sk89q.worldedit.regions.Region)2