mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-13 14:58:35 +00:00
Merge master again
This commit is contained in:
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.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);
|
||||
}
|
||||
}
|
@ -130,8 +130,6 @@ public class ExtentEntityCopy implements EntityFunction {
|
||||
if (tag != null) {
|
||||
// Handle hanging entities (paintings, item frames, etc.)
|
||||
boolean hasTilePosition = tag.containsKey("TileX") && tag.containsKey("TileY") && tag.containsKey("TileZ");
|
||||
boolean hasDirection = tag.containsKey("Direction");
|
||||
boolean hasLegacyDirection = tag.containsKey("Dir");
|
||||
boolean hasFacing = tag.containsKey("Facing");
|
||||
|
||||
if (hasTilePosition) {
|
||||
@ -143,27 +141,15 @@ public class ExtentEntityCopy implements EntityFunction {
|
||||
.putInt("TileY", newTilePosition.getBlockY())
|
||||
.putInt("TileZ", newTilePosition.getBlockZ());
|
||||
|
||||
if (hasDirection || hasLegacyDirection || hasFacing) {
|
||||
int d;
|
||||
if (hasDirection) {
|
||||
d = tag.asInt("Direction");
|
||||
} else if (hasLegacyDirection) {
|
||||
d = MCDirections.fromLegacyHanging((byte) tag.asInt("Dir"));
|
||||
} else {
|
||||
d = tag.asInt("Facing");
|
||||
}
|
||||
|
||||
Direction direction = MCDirections.fromHanging(d);
|
||||
if (hasFacing) {
|
||||
Direction direction = MCDirections.fromHanging(tag.asInt("Facing"));
|
||||
|
||||
if (direction != null) {
|
||||
Vector3 vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector3.ZERO)).normalize();
|
||||
Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL);
|
||||
|
||||
if (newDirection != null) {
|
||||
byte hangingByte = (byte) MCDirections.toHanging(newDirection);
|
||||
builder.putByte("Direction", hangingByte);
|
||||
builder.putByte("Facing", hangingByte);
|
||||
builder.putByte("Dir", MCDirections.toLegacyHanging(MCDirections.toHanging(newDirection)));
|
||||
builder.putByte("Facing", (byte) MCDirections.toHanging(newDirection));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,17 +28,23 @@ 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.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,11 +67,18 @@ 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;
|
||||
|
||||
private RegionVisitor lastVisitor;
|
||||
private int affected;
|
||||
private FlatRegionVisitor lastBiomeVisitor;
|
||||
private EntityVisitor lastEntityVisitor;
|
||||
|
||||
private int affectedBlocks;
|
||||
private int affectedBiomeCols;
|
||||
private int affectedEntities;
|
||||
|
||||
/**
|
||||
* Create a new copy using the region's lowest minimum point as the
|
||||
@ -222,21 +235,50 @@ 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.
|
||||
*
|
||||
* @return the number of affected
|
||||
*/
|
||||
public int getAffected() {
|
||||
return affected;
|
||||
return affectedBlocks + affectedBiomeCols + affectedEntities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
if (lastVisitor != null) {
|
||||
affected += lastVisitor.getAffected();
|
||||
affectedBlocks += lastVisitor.getAffected();
|
||||
lastVisitor = null;
|
||||
}
|
||||
if (lastBiomeVisitor != null) {
|
||||
affectedBiomeCols += lastBiomeVisitor.getAffected();
|
||||
lastBiomeVisitor = null;
|
||||
}
|
||||
if (lastEntityVisitor != null) {
|
||||
affectedEntities += lastEntityVisitor.getAffected();
|
||||
lastEntityVisitor = null;
|
||||
}
|
||||
|
||||
if (repetitions > 0) {
|
||||
repetitions--;
|
||||
@ -254,6 +296,23 @@ 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();
|
||||
FlatRegionFunction biomeFunction = biomeMask == null ? biomeCopy
|
||||
: new FlatRegionMaskingFilter(biomeMask, biomeCopy);
|
||||
FlatRegionVisitor biomeVisitor = new FlatRegionVisitor(((FlatRegion) region), biomeFunction);
|
||||
ops.add(biomeVisitor);
|
||||
lastBiomeVisitor = biomeVisitor;
|
||||
}
|
||||
|
||||
if (copyingEntities) {
|
||||
ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), destination, to.toVector3(), currentTransform);
|
||||
entityCopy.setRemoving(removingEntities);
|
||||
@ -263,10 +322,11 @@ 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);
|
||||
lastEntityVisitor = entityVisitor;
|
||||
}
|
||||
|
||||
return new DelegateOperation(this, new OperationQueue(ops));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -278,6 +338,24 @@ public class ForwardExtentCopy implements Operation {
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append(affectedBlocks).append(" block(s)");
|
||||
if (affectedBiomeCols > 0) {
|
||||
if (affectedEntities > 0) {
|
||||
msg.append(", ");
|
||||
} else {
|
||||
msg.append(" and ");
|
||||
}
|
||||
msg.append(affectedBiomeCols).append(" biome(s)");
|
||||
}
|
||||
if (affectedEntities > 0) {
|
||||
if (affectedBiomeCols > 0) {
|
||||
msg.append(",");
|
||||
}
|
||||
msg.append(" and ").append(affectedEntities).append(" entities(s)");
|
||||
}
|
||||
msg.append(" affected.");
|
||||
messages.add(msg.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user