|
1 | 1 | package com.ldtteam.structurize.component; |
2 | 2 |
|
| 3 | +import com.ldtteam.structurize.api.Log; |
3 | 4 | import com.ldtteam.structurize.api.RotationMirror; |
4 | 5 | import com.ldtteam.structurize.blueprints.v1.Blueprint; |
5 | 6 | import com.mojang.serialization.Codec; |
@@ -67,22 +68,41 @@ public CapturedBlock(final BlockState blockState, |
67 | 68 | */ |
68 | 69 | public CapturedBlock applyRotationMirror(final RotationMirror rotationMirror, final Level level) |
69 | 70 | { |
| 71 | + final BlockState rotatedState = rotationMirror.applyToBlockState(blockState); |
| 72 | + |
| 73 | + // No BE data: just rotate the state. |
70 | 74 | if (serializedBE.isEmpty()) |
71 | 75 | { |
72 | | - return new CapturedBlock(rotationMirror.applyToBlockState(blockState), serializedBE, itemStack); |
| 76 | + return new CapturedBlock(rotatedState, serializedBE, itemStack); |
73 | 77 | } |
74 | 78 |
|
| 79 | + // If the rotated state does not host a BE, drop any BE tag (prevents renderer/loader issues). |
| 80 | + if (!rotatedState.hasBlockEntity()) |
| 81 | + { |
| 82 | + Log.getLogger().warn("Block {} is not empty, but has no block entity.", rotatedState); |
| 83 | + return new CapturedBlock(rotatedState, Optional.empty(), itemStack); |
| 84 | + } |
| 85 | + |
| 86 | + // Rotate/migrate the BE tag using the Blueprint rotation logic |
75 | 87 | final Blueprint blueprint = new Blueprint((short) 1, (short) 1, (short) 1, level.registryAccess()); |
76 | | - blueprint.addBlockState(BlockPos.ZERO, blockState); |
| 88 | + blueprint.addBlockState(BlockPos.ZERO, rotatedState); |
77 | 89 | blueprint.getTileEntities()[0][0][0] = serializedBE.get(); |
78 | 90 | blueprint.setCachePrimaryOffset(BlockPos.ZERO); |
79 | 91 | blueprint.setRotationMirrorRelative(rotationMirror, level); |
80 | 92 |
|
81 | | - return new CapturedBlock(blueprint.getPalette()[blueprint.getPalleteSize()], |
82 | | - Optional.of(blueprint.getTileEntities()[0][0][0]), |
83 | | - itemStack); |
| 93 | + final CompoundTag rotatedTag = blueprint.getTileEntities()[0][0][0]; |
| 94 | + Optional<CompoundTag> beTag = Optional.ofNullable(rotatedTag); |
| 95 | + |
| 96 | + // Drop invalid/empty BE tags. |
| 97 | + if (beTag.isEmpty() || beTag.get().isEmpty() || !beTag.get().contains("id")) |
| 98 | + { |
| 99 | + beTag = Optional.empty(); |
| 100 | + } |
| 101 | + |
| 102 | + return new CapturedBlock(rotatedState, beTag, itemStack); |
84 | 103 | } |
85 | 104 |
|
| 105 | + |
86 | 106 | public boolean hasBlockEntity() |
87 | 107 | { |
88 | 108 | return serializedBE.isPresent() && !serializedBE.get().isEmpty(); |
|
0 commit comments