Changes to NBT-handling in operations and extents, changes to match the widely supported setBlock functionality, minor code cleanup

This commit is contained in:
IronApollo
2019-03-25 13:31:12 -04:00
parent 16c22b75da
commit 3236bdd78e
57 changed files with 347 additions and 417 deletions

View File

@ -79,20 +79,12 @@ public class ExtentBlockCopy implements RegionFunction {
}
@Override
//<<<<<<< HEAD
public boolean apply(BlockVector3 position) throws WorldEditException {
BlockVector3 orig = position.subtract(from);
BlockVector3 transformed = transform.apply(orig.toVector3()).toBlockPoint();
//=======
// public boolean apply(BlockVector3 position) throws WorldEditException {
// BaseBlock block = source.getFullBlock(position);
// BlockVector3 orig = position.subtract(from);
// BlockVector3 transformed = transform.apply(orig.toVector3()).toBlockPoint();
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
// Apply transformations to NBT data if necessary
BlockStateHolder block = transformNbtData(source.getBlock(position));
BaseBlock block = transformNbtData(source.getFullBlock(position));
return destination.setBlock(transformed.add(to), block);
}
@ -103,8 +95,9 @@ public class ExtentBlockCopy implements RegionFunction {
* @param state the existing state
* @return a new state or the existing one
*/
private BlockState transformNbtData(BlockState state) {
private BaseBlock transformNbtData(BaseBlock state) {
CompoundTag tag = state.getNbtData();
if (tag != null) {
// Handle blocks which store their rotation in NBT
if (tag.containsKey("Rot")) {
@ -113,30 +106,20 @@ public class ExtentBlockCopy implements RegionFunction {
Direction direction = MCDirections.fromRotation(rot);
if (direction != null) {
//<<<<<<< HEAD
// Vector applyAbsolute = transform.apply(direction.toVector());
// Vector applyOrigin = transform.apply(Vector.ZERO);
// applyAbsolute.mutX(applyAbsolute.getX() - applyOrigin.getX());
// applyAbsolute.mutY(applyAbsolute.getY() - applyOrigin.getY());
// applyAbsolute.mutZ(applyAbsolute.getZ() - applyOrigin.getZ());
//=======
Vector3 vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector3.ZERO)).normalize();
Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL | Flag.ORDINAL | Flag.SECONDARY_ORDINAL);
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
// Direction newDirection = Direction.findClosest(applyAbsolute, Flag.CARDINAL | Flag.ORDINAL | Flag.SECONDARY_ORDINAL);
//<<<<<<< HEAD
if (newDirection != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection)));
//=======
// return state.toBaseBlock(builder.build());
//>>>>>>> f54d6afb... Make BaseBlock more memory efficient, and make it clear in the API that it's not intended to be used for every single block.
CompoundTagBuilder builder = tag.createBuilder();
builder.putByte("Rot", (byte) MCDirections.toRotation(newDirection));
return state.toBaseBlock(builder.build());
}
}
}
}
return state;
}

View File

@ -40,6 +40,7 @@ import com.sk89q.worldedit.function.CombinedRegionFunction;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.RegionMaskTestFunction;
import com.sk89q.worldedit.function.RegionMaskingFilter;
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.Masks;