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:
wizjany
2019-04-03 20:57:51 -04:00
committed by Matthew Miller
parent 26511bcc25
commit af1af43ac1
7 changed files with 214 additions and 11 deletions

View File

@ -0,0 +1,73 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.biome;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.FlatRegionFunction;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.world.biome.BiomeType;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Copies the biome from one extent to another.
*/
public class ExtentBiomeCopy implements FlatRegionFunction {
private final Extent source;
private final Extent destination;
private final BlockVector2 from;
private final BlockVector2 to;
private final Transform transform;
/**
* Make a new biome copy.
*
* @param source the source extent
* @param from the source offset
* @param destination the destination extent
* @param to the destination offset
* @param transform a transform to apply to positions (after source offset, before destination offset)
*/
public ExtentBiomeCopy(Extent source, BlockVector2 from, Extent destination, BlockVector2 to, Transform transform) {
checkNotNull(source);
checkNotNull(from);
checkNotNull(destination);
checkNotNull(to);
checkNotNull(transform);
this.source = source;
this.from = from;
this.destination = destination;
this.to = to;
this.transform = transform;
}
@Override
public boolean apply(BlockVector2 position) throws WorldEditException {
BiomeType biome = source.getBiome(position);
BlockVector2 orig = position.subtract(from);
BlockVector2 transformed = transform.apply(orig.toVector3(0)).toVector2().toBlockPoint();
return destination.setBiome(transformed.add(to), biome);
}
}

View File

@ -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;
}