use of com.sk89q.worldedit.regions.FlatRegion in project FastAsyncWorldEdit by IntellectualSites.
the class ForwardExtentCopy method resume.
@Override
public Operation resume(RunContext run) throws WorldEditException {
// FAWE start
if (currentTransform == null) {
currentTransform = transform;
}
// FAWE end
if (lastBiomeVisitor != null) {
affectedBiomeCols += lastBiomeVisitor.getAffected();
lastBiomeVisitor = null;
}
if (lastEntityVisitor != null) {
affectedEntities += lastEntityVisitor.getAffected();
lastEntityVisitor = null;
}
// FAWE start
Extent finalDest = destination;
BlockVector3 translation = to.subtract(from);
if (!translation.equals(BlockVector3.ZERO)) {
finalDest = new BlockTranslateExtent(finalDest, translation.getBlockX(), translation.getBlockY(), translation.getBlockZ());
}
// FAWE end
// FAWE start - RegionVisitor > ExtentBlockCopy
RegionFunction copy;
RegionVisitor blockCopy = null;
PositionTransformExtent transExt = null;
if (!currentTransform.isIdentity()) {
if (!(currentTransform instanceof AffineTransform) || ((AffineTransform) currentTransform).isOffAxis()) {
transExt = new PositionTransformExtent(source, currentTransform.inverse());
transExt.setOrigin(from);
copy = new SimpleBlockCopy(transExt, finalDest);
if (this.filterFunction != null) {
copy = new IntersectRegionFunction(filterFunction, copy);
}
if (sourceFunction != null) {
copy = CombinedRegionFunction.combine(copy, sourceFunction);
}
if (sourceMask != Masks.alwaysTrue()) {
new MaskTraverser(sourceMask).reset(transExt);
copy = new RegionMaskingFilter(source, sourceMask, copy);
}
if (copyingBiomes && (source.isWorld() || region instanceof FlatRegion)) {
copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest));
}
blockCopy = new BackwardsExtentBlockCopy(region, from, transform, copy);
} else {
transExt = new PositionTransformExtent(finalDest, currentTransform);
transExt.setOrigin(from);
finalDest = transExt;
}
}
if (blockCopy == null) {
RegionFunction maskFunc = null;
if (sourceFunction != null) {
BlockVector3 disAbs = translation.abs();
BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
boolean overlap = (disAbs.getBlockX() < size.getBlockX() && disAbs.getBlockY() < size.getBlockY() && disAbs.getBlockZ() < size.getBlockZ());
RegionFunction copySrcFunc = sourceFunction;
if (overlap && translation.length() != 0) {
int x = translation.getBlockX();
int y = translation.getBlockY();
int z = translation.getBlockZ();
maskFunc = position -> {
BlockVector3 bv = BlockVector3.at(position.getBlockX() + x, position.getBlockY() + y, position.getBlockZ() + z);
if (region.contains(bv)) {
return sourceFunction.apply(bv);
}
return false;
};
copySrcFunc = position -> {
BlockVector3 bv = BlockVector3.at(position.getBlockX() - x, position.getBlockY() - y, position.getBlockZ() - z);
if (!region.contains(bv)) {
return sourceFunction.apply(position);
}
return false;
};
}
copy = new CombinedBlockCopy(source, finalDest, copySrcFunc);
} else {
copy = new SimpleBlockCopy(source, finalDest);
}
if (this.filterFunction != null) {
copy = new IntersectRegionFunction(filterFunction, copy);
}
if (sourceMask != Masks.alwaysTrue()) {
if (maskFunc != null) {
copy = new RegionMaskTestFunction(sourceMask, copy, maskFunc);
} else {
copy = new RegionMaskingFilter(source, sourceMask, copy);
}
}
if (copyingBiomes && (source.isWorld() || region instanceof FlatRegion)) {
copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest));
}
ExtentTraverser<ParallelQueueExtent> queueTraverser = new ExtentTraverser<>(finalDest).find(ParallelQueueExtent.class);
Extent preloader = queueTraverser != null ? queueTraverser.get() : source;
blockCopy = new RegionVisitor(region, copy, preloader);
}
List<? extends Entity> entities;
if (copyingEntities) {
// filter players since they can't be copied
entities = source.getEntities(region);
entities.removeIf(entity -> {
EntityProperties properties = entity.getFacet(EntityProperties.class);
return properties != null && !properties.isPasteable();
});
} else {
entities = Collections.emptyList();
}
for (int i = 0; i < repetitions; i++) {
Operations.completeBlindly(blockCopy);
if (!entities.isEmpty()) {
ExtentEntityCopy entityCopy = new ExtentEntityCopy(source, from.toVector3(), destination, to.toVector3(), currentTransform);
entityCopy.setRemoving(removingEntities);
List<? extends Entity> entities2 = Lists.newArrayList(source.getEntities(region));
entities2.removeIf(entity -> {
EntityProperties properties = entity.getFacet(EntityProperties.class);
return properties != null && !properties.isPasteable();
});
EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy);
Operations.completeBlindly(entityVisitor);
affectedEntities += entityVisitor.getAffected();
}
if (transExt != null) {
currentTransform = currentTransform.combine(transform);
transExt.setTransform(currentTransform);
}
}
affectedBlocks += blockCopy.getAffected();
// FAWE end
return null;
}
use of com.sk89q.worldedit.regions.FlatRegion in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method naturalizeCuboidBlocks.
/**
* Turns the first 3 layers into dirt/grass and the bottom layers
* into rock, like a natural Minecraft mountain.
*
* @param region the region to affect
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int naturalizeCuboidBlocks(Region region) throws MaxChangedBlocksException {
checkNotNull(region);
Naturalizer naturalizer = new Naturalizer(this);
FlatRegion flatRegion = Regions.asFlatRegion(region);
// FAWE start - provide extent for preloading
LayerVisitor visitor = new LayerVisitor(flatRegion, minimumBlockY(region), maximumBlockY(region), naturalizer, this);
// FAWE end
Operations.completeBlindly(visitor);
return this.changes = naturalizer.getAffected();
}
use of com.sk89q.worldedit.regions.FlatRegion 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
}
use of com.sk89q.worldedit.regions.FlatRegion in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method fall.
public <B extends BlockStateHolder<B>> int fall(final Region region, boolean fullHeight, final B replace) {
FlatRegion flat = asFlatRegion(region);
final int startPerformY = region.getMinimumPoint().getBlockY();
final int startCheckY = fullHeight ? getMinY() : startPerformY;
final int endY = region.getMaximumPoint().getBlockY();
RegionVisitor visitor = new RegionVisitor(flat, pos -> {
int x = pos.getX();
int z = pos.getZ();
int freeSpot = startCheckY;
for (int y = startCheckY; y <= endY; y++) {
if (y < startPerformY) {
if (!getBlockType(x, y, z).getMaterial().isAir()) {
freeSpot = y + 1;
}
continue;
}
BlockType block = getBlockType(x, y, z);
if (!block.getMaterial().isAir()) {
if (freeSpot != y) {
setBlock(x, freeSpot, z, block);
setBlock(x, y, z, replace);
}
freeSpot++;
}
}
return true;
}, this);
Operations.completeBlindly(visitor);
return this.changes;
}
use of com.sk89q.worldedit.regions.FlatRegion in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method makePumpkinPatches.
// FAWE start - support density
public int makePumpkinPatches(BlockVector3 position, int apothem, double density) throws MaxChangedBlocksException {
// We want to generate pumpkins
GardenPatchGenerator generator = new GardenPatchGenerator(this);
generator.setPlant(GardenPatchGenerator.getPumpkinPattern());
// In a region of the given radius
FlatRegion region = new CuboidRegion(// Causes clamping of Y range
getWorld(), position.add(-apothem, -5, -apothem), position.add(apothem, 10, apothem));
GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), generator);
LayerVisitor visitor = new LayerVisitor(region, minimumBlockY(region), maximumBlockY(region), ground, this);
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
Operations.completeLegacy(visitor);
return this.changes = ground.getAffected();
}
Aggregations