use of com.fastasyncworldedit.core.extent.PositionTransformExtent 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;
}
Aggregations