Search in sources :

Example 1 with ExistingPattern

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

Aggregations

ResettableMask (com.fastasyncworldedit.core.function.mask.ResettableMask)1 SingleBlockTypeMask (com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask)1 WallMakeMask (com.fastasyncworldedit.core.function.mask.WallMakeMask)1 ExistingPattern (com.fastasyncworldedit.core.function.pattern.ExistingPattern)1 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)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 RegionMask (com.sk89q.worldedit.function.mask.RegionMask)1 ForwardExtentCopy (com.sk89q.worldedit.function.operation.ForwardExtentCopy)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 CylinderRegion (com.sk89q.worldedit.regions.CylinderRegion)1 EllipsoidRegion (com.sk89q.worldedit.regions.EllipsoidRegion)1 FlatRegion (com.sk89q.worldedit.regions.FlatRegion)1 NullRegion (com.sk89q.worldedit.regions.NullRegion)1 Region (com.sk89q.worldedit.regions.Region)1