Skip to content

Commit 73c068b

Browse files
authored
Rotation Crash on TagSubstitutionBlock (#814)
1 parent 6231260 commit 73c068b

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/main/java/com/ldtteam/structurize/component/CapturedBlock.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.ldtteam.structurize.component;
22

3+
import com.ldtteam.structurize.api.Log;
34
import com.ldtteam.structurize.api.RotationMirror;
45
import com.ldtteam.structurize.blueprints.v1.Blueprint;
56
import com.mojang.serialization.Codec;
@@ -67,22 +68,41 @@ public CapturedBlock(final BlockState blockState,
6768
*/
6869
public CapturedBlock applyRotationMirror(final RotationMirror rotationMirror, final Level level)
6970
{
71+
final BlockState rotatedState = rotationMirror.applyToBlockState(blockState);
72+
73+
// No BE data: just rotate the state.
7074
if (serializedBE.isEmpty())
7175
{
72-
return new CapturedBlock(rotationMirror.applyToBlockState(blockState), serializedBE, itemStack);
76+
return new CapturedBlock(rotatedState, serializedBE, itemStack);
7377
}
7478

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
7587
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);
7789
blueprint.getTileEntities()[0][0][0] = serializedBE.get();
7890
blueprint.setCachePrimaryOffset(BlockPos.ZERO);
7991
blueprint.setRotationMirrorRelative(rotationMirror, level);
8092

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);
84103
}
85104

105+
86106
public boolean hasBlockEntity()
87107
{
88108
return serializedBE.isPresent() && !serializedBE.get().isEmpty();

0 commit comments

Comments
 (0)