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
}
Aggregations