From 096a9e4f9f91e0797af90887559d4b219f16f699 Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Fri, 28 Jun 2019 22:11:24 +0200 Subject: [PATCH] Paintings are very special (#492) Fixes WORLDEDIT-3429 --- .../function/entity/ExtentEntityCopy.java | 16 +++++++++++++--- .../internal/helper/MCDirections.java | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java index 3c882a18a..cb35b3cea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java @@ -35,6 +35,7 @@ import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction.Flag; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.entity.EntityTypes; /** * Copies entities provided to the function to the provided destination @@ -91,9 +92,18 @@ public class ExtentEntityCopy implements EntityFunction { if (state != null) { Location newLocation; Location location = entity.getLocation(); + // If the entity has stored the location in the NBT data, we use that location + CompoundTag tag = state.getNbtData(); + boolean hasTilePosition = tag != null && tag.containsKey("TileX") && tag.containsKey("TileY") && tag.containsKey("TileZ"); + if (hasTilePosition) { + location = location.setPosition(Vector3.at(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ")).add(0.5, 0.5, 0.5)); + } Vector3 pivot = from.round().add(0.5, 0.5, 0.5); Vector3 newPosition = transform.apply(location.toVector().subtract(pivot)); + if (hasTilePosition) { + newPosition = newPosition.subtract(0.5, 0.5, 0.5); + } Vector3 newDirection; newDirection = transform.isIdentity() ? @@ -142,14 +152,15 @@ public class ExtentEntityCopy implements EntityFunction { .putInt("TileZ", newTilePosition.getBlockZ()); if (hasFacing) { - Direction direction = MCDirections.fromHanging(tag.asInt("Facing")); + boolean isPainting = state.getType() == EntityTypes.PAINTING; // Paintings have different facing values + Direction direction = isPainting ? MCDirections.fromHorizontalHanging(tag.asInt("Facing")) : 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) { - builder.putByte("Facing", (byte) MCDirections.toHanging(newDirection)); + builder.putByte("Facing", (byte) (isPainting ? MCDirections.toHorizontalHanging(newDirection) : MCDirections.toHanging(newDirection))); } } } @@ -160,5 +171,4 @@ public class ExtentEntityCopy implements EntityFunction { return state; } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/helper/MCDirections.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/helper/MCDirections.java index 959e30ae4..1aabf26b1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/helper/MCDirections.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/helper/MCDirections.java @@ -68,6 +68,10 @@ public final class MCDirections { } public static Direction fromPre13Hanging(int i) { + return fromHorizontalHanging(i); + } + + public static Direction fromHorizontalHanging(int i) { switch (i) { case 0: return Direction.SOUTH; @@ -82,6 +86,21 @@ public final class MCDirections { } } + public static int toHorizontalHanging(Direction direction) { + switch (direction) { + case SOUTH: + return 0; + case WEST: + return 1; + case NORTH: + return 2; + case EAST: + return 3; + default: + return 0; + } + } + public static int fromLegacyHanging(byte i) { switch (i) { case 0: return 2;