Search in sources :

Example 6 with RegionIntersection

use of com.sk89q.worldedit.regions.RegionIntersection in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method moveRegion.

/**
 * Move the blocks in a region a certain direction.
 *
 * @param region       the region to move
 * @param offset       the offset. Is directional.
 * @param multiplier   the number to multiply the offset by
 * @param moveEntities true to move entities
 * @param copyBiomes   true to copy biomes (source biome is unchanged)
 * @param mask         source mask for the operation (only matching blocks are moved)
 * @param replacement  the replacement pattern to fill in after moving, or null to use air
 * @return number of blocks moved
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 * @throws IllegalArgumentException  thrown if the region is not a flat region, but copyBiomes is true
 */
public int moveRegion(Region region, BlockVector3 offset, int multiplier, boolean moveEntities, boolean copyBiomes, Mask mask, Pattern replacement) throws MaxChangedBlocksException {
    checkNotNull(region);
    checkNotNull(offset);
    checkArgument(multiplier >= 1, "distance >= 1 required");
    checkArgument(!copyBiomes || region instanceof FlatRegion, "can't copy biomes from non-flat region");
    // FAWE start - add up distance
    BlockVector3 to = region.getMinimumPoint().add(offset.multiply(multiplier));
    final BlockVector3 displace = offset.multiply(multiplier);
    final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
    BlockVector3 disAbs = displace.abs();
    if (disAbs.getBlockX() < size.getBlockX() && disAbs.getBlockY() < size.getBlockY() && disAbs.getBlockZ() < size.getBlockZ()) {
        // Buffer if overlapping
        enableQueue();
    }
    ForwardExtentCopy copy = new ForwardExtentCopy(this, region, this, to);
    if (replacement == null) {
        replacement = BlockTypes.AIR.getDefaultState();
    }
    BlockReplace remove = replacement instanceof ExistingPattern ? null : new BlockReplace(this, replacement);
    // Remove
    copy.setSourceFunction(remove);
    copy.setCopyingEntities(moveEntities);
    copy.setRemovingEntities(moveEntities);
    copy.setCopyingBiomes(copyBiomes);
    copy.setRepetitions(1);
    final Region allowedRegion;
    if (allowedRegions == null || allowedRegions.length == 0) {
        allowedRegion = new NullRegion();
    } else {
        allowedRegion = new RegionIntersection(allowedRegions);
    }
    Mask sourceMask = this.getSourceMask();
    mask = MaskIntersection.of(sourceMask, mask, new RegionMask(allowedRegion)).optimize();
    if (mask != Masks.alwaysTrue()) {
        copy.setSourceMask(mask);
        if (sourceMask != null && sourceMask.equals(mask)) {
            setSourceMask(null);
        }
    }
    Operations.completeBlindly(copy);
    return this.changes = copy.getAffected();
// FAWE end
}
Also used : ExistingPattern(com.fastasyncworldedit.core.function.pattern.ExistingPattern) RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) FlatRegion(com.sk89q.worldedit.regions.FlatRegion) Regions.asFlatRegion(com.sk89q.worldedit.regions.Regions.asFlatRegion) 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) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) CylinderRegion(com.sk89q.worldedit.regions.CylinderRegion) EllipsoidRegion(com.sk89q.worldedit.regions.EllipsoidRegion) FlatRegion(com.sk89q.worldedit.regions.FlatRegion) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) Regions.asFlatRegion(com.sk89q.worldedit.regions.Regions.asFlatRegion) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) NullRegion(com.sk89q.worldedit.regions.NullRegion)

Example 7 with RegionIntersection

use of com.sk89q.worldedit.regions.RegionIntersection in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method stackCuboidRegion.

// FAWE start
/**
 * Stack a cuboid region.
 *
 * @param region       the region to stack
 * @param offset       how far to move the contents each stack. Is directional.
 * @param count        the number of times to stack
 * @param copyEntities true to copy entities
 * @param copyBiomes   true to copy biomes
 * @param mask         source mask for the operation (only matching blocks are copied)
 * @return number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
public int stackCuboidRegion(Region region, BlockVector3 offset, int count, boolean copyEntities, boolean copyBiomes, Mask mask) throws MaxChangedBlocksException {
    checkNotNull(region);
    checkNotNull(offset);
    checkArgument(count >= 1, "count >= 1 required");
    BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
    BlockVector3 to = region.getMinimumPoint();
    ForwardExtentCopy copy = new ForwardExtentCopy(this, region, this, to);
    copy.setRepetitions(count);
    copy.setTransform(new AffineTransform().translate(offset.multiply(size)));
    copy.setCopyingEntities(copyEntities);
    copy.setCopyingBiomes(copyBiomes);
    final Region allowedRegion;
    if (allowedRegions == null || allowedRegions.length == 0) {
        allowedRegion = new NullRegion();
    } else {
        allowedRegion = new RegionIntersection(allowedRegions);
    }
    mask = MaskIntersection.of(getSourceMask(), mask, new RegionMask(allowedRegion)).optimize();
    if (mask != Masks.alwaysTrue()) {
        setSourceMask(null);
        copy.setSourceMask(mask);
    }
    Operations.completeLegacy(copy);
    return this.changes = copy.getAffected();
}
Also used : RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) CylinderRegion(com.sk89q.worldedit.regions.CylinderRegion) EllipsoidRegion(com.sk89q.worldedit.regions.EllipsoidRegion) FlatRegion(com.sk89q.worldedit.regions.FlatRegion) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) Regions.asFlatRegion(com.sk89q.worldedit.regions.Regions.asFlatRegion) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) NullRegion(com.sk89q.worldedit.regions.NullRegion)

Aggregations

BlockVector3 (com.sk89q.worldedit.math.BlockVector3)7 RegionIntersection (com.sk89q.worldedit.regions.RegionIntersection)7 Region (com.sk89q.worldedit.regions.Region)5 RegionMask (com.sk89q.worldedit.function.mask.RegionMask)4 ForwardExtentCopy (com.sk89q.worldedit.function.operation.ForwardExtentCopy)4 NullRegion (com.sk89q.worldedit.regions.NullRegion)4 Mask (com.sk89q.worldedit.function.mask.Mask)3 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)3 MultiClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder)2 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)2 FaweLimit (com.fastasyncworldedit.core.limit.FaweLimit)2 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)2 MaskTraverser (com.fastasyncworldedit.core.util.MaskTraverser)2 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)2 Preload (com.sk89q.worldedit.command.util.annotation.Preload)2 BlockReplace (com.sk89q.worldedit.function.block.BlockReplace)2 CylinderRegion (com.sk89q.worldedit.regions.CylinderRegion)2 EllipsoidRegion (com.sk89q.worldedit.regions.EllipsoidRegion)2 FlatRegion (com.sk89q.worldedit.regions.FlatRegion)2