Don't touch the Direction tag, as possibly only Facing changed.

Dieser Commit ist enthalten in:
Kenzie Togami 2019-04-16 23:47:29 -07:00 committet von Matthew Miller
Ursprung efc4ebe309
Commit 56ef786415
2 geänderte Dateien mit 33 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -2,24 +2,40 @@ package com.sk89q.worldedit.extent.clipboard.io.legacycompat;
import com.sk89q.jnbt.ByteTag; import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.CompoundTagBuilder;
import com.sk89q.worldedit.internal.helper.MCDirections; import com.sk89q.worldedit.internal.helper.MCDirections;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityType;
public class Pre13HangingCompatibilityHandler implements EntityNBTCompatibilityHandler { public class Pre13HangingCompatibilityHandler implements EntityNBTCompatibilityHandler {
@Override @Override
public boolean isAffectedEntity(EntityType type, CompoundTag entityTag) { public boolean isAffectedEntity(EntityType type, CompoundTag tag) {
return entityTag.getValue().get("Facing") instanceof ByteTag; boolean hasLegacyDirection = tag.containsKey("Dir");
boolean hasFacing = tag.containsKey("Facing");
return hasLegacyDirection || hasFacing;
} }
@Override @Override
public CompoundTag updateNBT(EntityType type, CompoundTag entityTag) { public CompoundTag updateNBT(EntityType type, CompoundTag tag) {
int newFacing = MCDirections.toHanging( boolean hasLegacyDirection = tag.containsKey("Dir");
MCDirections.fromPre13Hanging(entityTag.getByte("Facing")) boolean hasFacing = tag.containsKey("Facing");
); int d;
return entityTag.createBuilder() if (hasLegacyDirection) {
.putByte("Facing", (byte) newFacing) d = MCDirections.fromLegacyHanging((byte) tag.asInt("Dir"));
.build(); } 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();
} }
} }

Datei anzeigen

@ -144,25 +144,24 @@ public class ExtentEntityCopy implements EntityFunction {
.putInt("TileZ", newTilePosition.getBlockZ()); .putInt("TileZ", newTilePosition.getBlockZ());
if (hasDirection || hasLegacyDirection || hasFacing) { if (hasDirection || hasLegacyDirection || hasFacing) {
int d; Direction direction;
if (hasDirection) { if (hasDirection) {
d = tag.asInt("Direction"); direction = MCDirections.fromPre13Hanging(tag.asInt("Direction"));
} else if (hasLegacyDirection) { } else if (hasLegacyDirection) {
d = MCDirections.fromLegacyHanging((byte) tag.asInt("Dir")); direction = MCDirections.fromPre13Hanging(
MCDirections.fromLegacyHanging((byte) tag.asInt("Dir"))
);
} else { } else {
d = tag.asInt("Facing"); direction = MCDirections.fromHanging(tag.asInt("Facing"));
} }
Direction direction = MCDirections.fromHanging(d);
if (direction != null) { if (direction != null) {
Vector3 vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector3.ZERO)).normalize(); Vector3 vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector3.ZERO)).normalize();
Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL); Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL);
if (newDirection != null) { if (newDirection != null) {
byte hangingByte = (byte) MCDirections.toHanging(newDirection); builder.putByte("Direction", (byte) MCDirections.toPre13Hanging(newDirection));
builder.putByte("Direction", hangingByte); builder.putByte("Facing", (byte) MCDirections.toHanging(newDirection));
builder.putByte("Facing", hangingByte);
builder.putByte("Dir", MCDirections.toLegacyHanging(MCDirections.toHanging(newDirection))); builder.putByte("Dir", MCDirections.toLegacyHanging(MCDirections.toHanging(newDirection)));
} }
} }