mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-13 14:58:35 +00:00
Allow copy/pasting biomes.
Copy takes a -b flag to copy biomes. Paste takes a -b flag to paste biomes (if available). This allows flexibility to create/load schematics with/without biomes (when schematic biome support is added). Also added a -m mask flag to paste to set a source mask, and a -e flag to skip pasting entities if they are loaded.
This commit is contained in:
@ -28,17 +28,24 @@ import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.entity.metadata.EntityProperties;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.CombinedRegionFunction;
|
||||
import com.sk89q.worldedit.function.FlatRegionFunction;
|
||||
import com.sk89q.worldedit.function.FlatRegionMaskingFilter;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.RegionMaskingFilter;
|
||||
import com.sk89q.worldedit.function.biome.ExtentBiomeCopy;
|
||||
import com.sk89q.worldedit.function.block.ExtentBlockCopy;
|
||||
import com.sk89q.worldedit.function.entity.ExtentEntityCopy;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Mask2D;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.function.visitor.EntityVisitor;
|
||||
import com.sk89q.worldedit.function.visitor.FlatRegionVisitor;
|
||||
import com.sk89q.worldedit.function.visitor.RegionVisitor;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.transform.Identity;
|
||||
import com.sk89q.worldedit.math.transform.Transform;
|
||||
import com.sk89q.worldedit.regions.FlatRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.util.List;
|
||||
@ -61,6 +68,7 @@ public class ForwardExtentCopy implements Operation {
|
||||
private Mask sourceMask = Masks.alwaysTrue();
|
||||
private boolean removingEntities;
|
||||
private boolean copyingEntities = true; // default to true for backwards compatibility, sort of
|
||||
private boolean copyingBiomes;
|
||||
private RegionFunction sourceFunction = null;
|
||||
private Transform transform = new Identity();
|
||||
private Transform currentTransform = null;
|
||||
@ -222,6 +230,27 @@ public class ForwardExtentCopy implements Operation {
|
||||
this.removingEntities = removingEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether biomes should be copied along with blocks.
|
||||
*
|
||||
* @return true if copying biomes
|
||||
*/
|
||||
public boolean isCopyingBiomes() {
|
||||
return copyingBiomes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether biomes should be copies along with blocks.
|
||||
*
|
||||
* @param copyingBiomes true if copying
|
||||
*/
|
||||
public void setCopyingBiomes(boolean copyingBiomes) {
|
||||
if (copyingBiomes && !(region instanceof FlatRegion)) {
|
||||
throw new UnsupportedOperationException("Can't copy biomes from region that doesn't implement FlatRegion");
|
||||
}
|
||||
this.copyingBiomes = copyingBiomes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of affected objects.
|
||||
*
|
||||
@ -254,6 +283,25 @@ public class ForwardExtentCopy implements Operation {
|
||||
|
||||
lastVisitor = blockVisitor;
|
||||
|
||||
if (!copyingBiomes && !copyingEntities) {
|
||||
return new DelegateOperation(this, blockVisitor);
|
||||
}
|
||||
|
||||
List<Operation> ops = Lists.newArrayList(blockVisitor);
|
||||
|
||||
if (copyingBiomes && region instanceof FlatRegion) { // double-check here even though we checked before
|
||||
ExtentBiomeCopy biomeCopy = new ExtentBiomeCopy(source, from.toBlockVector2(),
|
||||
destination, to.toBlockVector2(), currentTransform);
|
||||
Mask2D biomeMask = sourceMask.toMask2D();
|
||||
if (biomeMask != null) {
|
||||
FlatRegionMaskingFilter filteredBiomeCopy = new FlatRegionMaskingFilter(biomeMask, biomeCopy);
|
||||
FlatRegionVisitor biomeVisitor = new FlatRegionVisitor(((FlatRegion) region), filteredBiomeCopy);
|
||||
ops.add(biomeVisitor);
|
||||
} else {
|
||||
ops.add(new FlatRegionVisitor(((FlatRegion) region), biomeCopy));
|
||||
}
|
||||
}
|
||||
|
||||
if (copyingEntities) {
|
||||
ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), destination, to.toVector3(), currentTransform);
|
||||
entityCopy.setRemoving(removingEntities);
|
||||
@ -263,10 +311,10 @@ public class ForwardExtentCopy implements Operation {
|
||||
return properties != null && !properties.isPasteable();
|
||||
});
|
||||
EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy);
|
||||
return new DelegateOperation(this, new OperationQueue(blockVisitor, entityVisitor));
|
||||
} else {
|
||||
return new DelegateOperation(this, blockVisitor);
|
||||
ops.add(entityVisitor);
|
||||
}
|
||||
|
||||
return new DelegateOperation(this, new OperationQueue(ops));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user