Fix rotation of item frames

This commit is contained in:
FrozenBrain 2016-01-01 21:56:34 +01:00 committed by wizjany
parent 15d10bee30
commit 1a3ae37b73

View File

@ -131,6 +131,7 @@ public class ExtentEntityCopy implements EntityFunction {
boolean hasTilePosition = tag.containsKey("TileX") && tag.containsKey("TileY") && tag.containsKey("TileZ"); boolean hasTilePosition = tag.containsKey("TileX") && tag.containsKey("TileY") && tag.containsKey("TileZ");
boolean hasDirection = tag.containsKey("Direction"); boolean hasDirection = tag.containsKey("Direction");
boolean hasLegacyDirection = tag.containsKey("Dir"); boolean hasLegacyDirection = tag.containsKey("Dir");
boolean hasFacing = tag.containsKey("Facing");
if (hasTilePosition) { if (hasTilePosition) {
Vector tilePosition = new Vector(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ")); Vector tilePosition = new Vector(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ"));
@ -141,15 +142,25 @@ public class ExtentEntityCopy implements EntityFunction {
.putInt("TileY", newTilePosition.getBlockY()) .putInt("TileY", newTilePosition.getBlockY())
.putInt("TileZ", newTilePosition.getBlockZ()); .putInt("TileZ", newTilePosition.getBlockZ());
if (hasDirection || hasLegacyDirection) { if (hasDirection || hasLegacyDirection || hasFacing) {
int d = hasDirection ? tag.asInt("Direction") : MCDirections.fromLegacyHanging((byte) tag.asInt("Dir")); int d;
if (hasDirection) {
d = tag.asInt("Direction");
} else if (hasLegacyDirection) {
d = MCDirections.fromLegacyHanging((byte) tag.asInt("Dir"));
} else {
d = tag.asInt("Facing");
}
Direction direction = MCDirections.fromHanging(d); Direction direction = MCDirections.fromHanging(d);
if (direction != null) { if (direction != null) {
Vector vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector.ZERO)).normalize(); Vector vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector.ZERO)).normalize();
Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL); Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL);
builder.putByte("Direction", (byte) MCDirections.toHanging(newDirection)); byte hangingByte = (byte) MCDirections.toHanging(newDirection);
builder.putByte("Direction", hangingByte);
builder.putByte("Facing", hangingByte);
builder.putByte("Dir", MCDirections.toLegacyHanging(MCDirections.toHanging(newDirection))); builder.putByte("Dir", MCDirections.toLegacyHanging(MCDirections.toHanging(newDirection)));
} }
} }