From 806916d6e8698f368d913f69c4c3d38c4580570b Mon Sep 17 00:00:00 2001 From: Aurora <21148213+aurorasmiles@users.noreply.github.com> Date: Sun, 20 Sep 2020 16:33:07 +0200 Subject: [PATCH] Fix entity rotation (#642) * fix entity rotation fixes #577 Co-authored-by: wea_ondara --- .../function/entity/ExtentEntityCopy.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 d6308af88..36ce61663 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 @@ -39,6 +39,9 @@ import com.sk89q.worldedit.world.entity.EntityTypes; import java.util.UUID; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.jnbt.FloatTag; +import com.sk89q.jnbt.ListTag; +import java.util.Arrays; /** * Copies entities provided to the function to the provided destination @@ -201,6 +204,7 @@ public class ExtentEntityCopy implements EntityFunction { // Handle hanging entities (paintings, item frames, etc.) boolean hasTilePosition = tag.containsKey("TileX") && tag.containsKey("TileY") && tag.containsKey("TileZ"); boolean hasFacing = tag.containsKey("Facing"); + boolean hasRotation = tag.containsKey("Rotation"); if (hasTilePosition) { Vector3 tilePosition = Vector3.at(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ")); @@ -225,6 +229,22 @@ public class ExtentEntityCopy implements EntityFunction { } } + if (hasRotation) { + ListTag orgrot = state.getNbtData().getListTag("Rotation"); + Vector3 orgDirection = new Location(source, 0, 0, 0, orgrot.getFloat(0), orgrot.getFloat(1)).getDirection(); + Vector3 newDirection = transform.apply(orgDirection).subtract(transform.apply(Vector3.ZERO)).normalize(); + builder.put("Rotation", new ListTag(FloatTag.class, Arrays.asList(new FloatTag((float) newDirection.toYaw()), new FloatTag((float) newDirection.toPitch())))); + } + + return new BaseEntity(state.getType(), builder.build()); + } else if (hasRotation) { //armor stands do not have a tile pos + CompoundTagBuilder builder = tag.createBuilder(); + + ListTag orgrot = state.getNbtData().getListTag("Rotation"); + Vector3 orgDirection = new Location(source, 0, 0, 0, orgrot.getFloat(0), orgrot.getFloat(1)).getDirection(); + Vector3 newDirection = transform.apply(orgDirection).subtract(transform.apply(Vector3.ZERO)).normalize(); + builder.put("Rotation", new ListTag(FloatTag.class, Arrays.asList(new FloatTag((float) newDirection.toYaw()), new FloatTag((float) newDirection.toPitch())))); + return new BaseEntity(state.getType(), builder.build()); } }