Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/main/java/com/ldtteam/structurize/component/CapturedBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,40 @@ public CapturedBlock(final BlockState blockState,
*/
public CapturedBlock applyRotationMirror(final RotationMirror rotationMirror, final Level level)
{
final BlockState rotatedState = rotationMirror.applyToBlockState(blockState);

// No BE data: just rotate the state.
if (serializedBE.isEmpty())
{
return new CapturedBlock(rotationMirror.applyToBlockState(blockState), serializedBE, itemStack);
return new CapturedBlock(rotatedState, serializedBE, itemStack);
}

// If the rotated state cannot host a BE, drop any BE tag (prevents renderer/loader issues).
if (!rotatedState.hasBlockEntity())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it happen that we get serializedBE not empty but it has no block entity?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I saw when debugging was that for this specific decoration the block entity was reported as "present but blank" - showed up as "{}" when dumping the logs. Not sure how that comes about... but wanted to guard against it.

{
return new CapturedBlock(rotatedState, Optional.empty(), itemStack);
}

// Rotate/migrate the BE tag using the Blueprint rotation logic
final Blueprint blueprint = new Blueprint((short) 1, (short) 1, (short) 1, level.registryAccess());
blueprint.addBlockState(BlockPos.ZERO, blockState);
blueprint.addBlockState(BlockPos.ZERO, rotatedState);
blueprint.getTileEntities()[0][0][0] = serializedBE.get();
blueprint.setCachePrimaryOffset(BlockPos.ZERO);
blueprint.setRotationMirrorRelative(rotationMirror, level);

return new CapturedBlock(blueprint.getPalette()[blueprint.getPalleteSize()],
Optional.of(blueprint.getTileEntities()[0][0][0]),
itemStack);
final CompoundTag rotatedTag = blueprint.getTileEntities()[0][0][0];
Optional<CompoundTag> beTag = Optional.ofNullable(rotatedTag);

// Drop invalid/empty BE tags.
if (beTag.isEmpty() || beTag.get().isEmpty() || !beTag.get().contains("id"))
{
beTag = Optional.empty();
}

return new CapturedBlock(rotatedState, beTag, itemStack);
}


public boolean hasBlockEntity()
{
return serializedBE.isPresent() && !serializedBE.get().isEmpty();
Expand Down