From 56ef7864153e998a865995b4147d1181833bfa03 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Tue, 16 Apr 2019 23:47:29 -0700 Subject: [PATCH] Don't touch the Direction tag, as possibly only Facing changed. --- .../Pre13HangingCompatibilityHandler.java | 34 ++++++++++++++----- .../function/entity/ExtentEntityCopy.java | 17 +++++----- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/Pre13HangingCompatibilityHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/Pre13HangingCompatibilityHandler.java index 85a181c83..845d3beb2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/Pre13HangingCompatibilityHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/Pre13HangingCompatibilityHandler.java @@ -2,24 +2,40 @@ package com.sk89q.worldedit.extent.clipboard.io.legacycompat; import com.sk89q.jnbt.ByteTag; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.CompoundTagBuilder; import com.sk89q.worldedit.internal.helper.MCDirections; +import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.world.entity.EntityType; public class Pre13HangingCompatibilityHandler implements EntityNBTCompatibilityHandler { @Override - public boolean isAffectedEntity(EntityType type, CompoundTag entityTag) { - return entityTag.getValue().get("Facing") instanceof ByteTag; + public boolean isAffectedEntity(EntityType type, CompoundTag tag) { + boolean hasLegacyDirection = tag.containsKey("Dir"); + boolean hasFacing = tag.containsKey("Facing"); + return hasLegacyDirection || hasFacing; } @Override - public CompoundTag updateNBT(EntityType type, CompoundTag entityTag) { - int newFacing = MCDirections.toHanging( - MCDirections.fromPre13Hanging(entityTag.getByte("Facing")) - ); - return entityTag.createBuilder() - .putByte("Facing", (byte) newFacing) - .build(); + public CompoundTag updateNBT(EntityType type, CompoundTag tag) { + boolean hasLegacyDirection = tag.containsKey("Dir"); + boolean hasFacing = tag.containsKey("Facing"); + int d; + if (hasLegacyDirection) { + d = MCDirections.fromLegacyHanging((byte) tag.asInt("Dir")); + } else { + d = tag.asInt("Facing"); + } + + Direction newDirection = MCDirections.fromPre13Hanging(d); + + byte hangingByte = (byte) MCDirections.toHanging(newDirection); + + CompoundTagBuilder builder = tag.createBuilder(); + builder.putByte("Direction", hangingByte); + builder.putByte("Facing", hangingByte); + builder.putByte("Dir", MCDirections.toLegacyHanging(MCDirections.toHanging(newDirection))); + return builder.build(); } } 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 7205c1212..1521655f6 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 @@ -144,25 +144,24 @@ public class ExtentEntityCopy implements EntityFunction { .putInt("TileZ", newTilePosition.getBlockZ()); if (hasDirection || hasLegacyDirection || hasFacing) { - int d; + Direction direction; if (hasDirection) { - d = tag.asInt("Direction"); + direction = MCDirections.fromPre13Hanging(tag.asInt("Direction")); } else if (hasLegacyDirection) { - d = MCDirections.fromLegacyHanging((byte) tag.asInt("Dir")); + direction = MCDirections.fromPre13Hanging( + MCDirections.fromLegacyHanging((byte) tag.asInt("Dir")) + ); } else { - d = tag.asInt("Facing"); + direction = MCDirections.fromHanging(tag.asInt("Facing")); } - Direction direction = MCDirections.fromHanging(d); - 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("Direction", (byte) MCDirections.toPre13Hanging(newDirection)); + builder.putByte("Facing", (byte) MCDirections.toHanging(newDirection)); builder.putByte("Dir", MCDirections.toLegacyHanging(MCDirections.toHanging(newDirection))); } }