Skip to content

Commit

Permalink
Fix paintings not getting rotated correctly
Browse files Browse the repository at this point in the history
Co-authored-by: Octavia Togami <[email protected]>
  • Loading branch information
aurorasmiles and octylFractal committed May 10, 2024
1 parent 6686552 commit a695bb8
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private BaseEntity transformNbtData(BaseEntity state) {
.putInt("TileY", newTilePosition.y())
.putInt("TileZ", newTilePosition.z());

if (tag.value().get("Facing") instanceof LinNumberTag<?> tagFacing) {
if (tryGetFacingData(tag) instanceof FacingTagData(String facingKey, LinNumberTag<?> tagFacing)) {
boolean isPainting = state.getType() == EntityTypes.PAINTING; // Paintings have different facing values
Direction direction = isPainting
? MCDirections.fromHorizontalHanging(tagFacing.value().intValue())
Expand All @@ -202,7 +202,7 @@ private BaseEntity transformNbtData(BaseEntity state) {
? MCDirections.toHorizontalHanging(newDirection)
: MCDirections.toHanging(newDirection)
);
builder.putByte("Facing", facingValue);
builder.putByte(facingKey, facingValue);
}
}
}
Expand All @@ -213,4 +213,17 @@ private BaseEntity transformNbtData(BaseEntity state) {

return state;
}

private record FacingTagData(String facingKey, LinNumberTag<?> tagFacing) {
}

private static FacingTagData tryGetFacingData(LinCompoundTag tag) {
if (tag.value().get("Facing") instanceof LinNumberTag<?> tagFacingCapital) {
return new FacingTagData("Facing", tagFacingCapital);
} else if (tag.value().get("facing") instanceof LinNumberTag<?> tagFacingLower) {
return new FacingTagData("facing", tagFacingLower);
} else {
return null;
}
}
}

0 comments on commit a695bb8

Please sign in to comment.