Skip to content

Commit

Permalink
Fix some cases of empty tags being needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Apr 24, 2024
1 parent abea013 commit c54624f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ protected BlockEntityTranslator() {
public abstract void translateTag(NbtMapBuilder builder, CompoundTag tag, int blockState);

public NbtMap getBlockEntityTag(GeyserSession session, BlockEntityType type, int x, int y, int z, CompoundTag tag, int blockState) {
NbtMapBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId(type), x, y, z);
NbtMapBuilder tagBuilder = getConstantBedrockTag(type, x, y, z);
translateTag(tagBuilder, tag, blockState);
return tagBuilder.build();
}

protected NbtMapBuilder getConstantBedrockTag(String bedrockId, int x, int y, int z) {
public static NbtMapBuilder getConstantBedrockTag(BlockEntityType type, int x, int y, int z) {
return getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId(type), x, y, z);
}

public static NbtMapBuilder getConstantBedrockTag(String bedrockId, int x, int y, int z) {
return NbtMap.builder()
.putInt("x", x)
.putInt("y", y)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,9 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke
for (BlockEntityInfo blockEntity : blockEntities) {
BlockEntityType type = blockEntity.getType();
CompoundTag tag = blockEntity.getNbt();
if (type == null || tag == null) {
if (type == null) {
// As an example: ViaVersion will send -1 if it cannot find the block entity type
// Vanilla Minecraft gracefully handles this
// Since 1.20.5: tags sent here can be null, at which point the block entity is not translated
continue;
}
int x = blockEntity.getX(); // Relative to chunk
Expand All @@ -421,8 +420,13 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke
continue;
}

BlockEntityTranslator blockEntityTranslator = BlockEntityUtils.getBlockEntityTranslator(type);
bedrockBlockEntities.add(blockEntityTranslator.getBlockEntityTag(session, type, x + chunkBlockX, y, z + chunkBlockZ, tag, blockState));
if (tag != null) {
BlockEntityTranslator blockEntityTranslator = BlockEntityUtils.getBlockEntityTranslator(type);
bedrockBlockEntities.add(blockEntityTranslator.getBlockEntityTag(session, type, x + chunkBlockX, y, z + chunkBlockZ, tag, blockState));
} else {
// Since 1.20.5, tags can be null, but Bedrock still needs a default tag to render the item
bedrockBlockEntities.add(BlockEntityTranslator.getConstantBedrockTag(type, x + chunkBlockX, y, z + chunkBlockZ).build());
}

// Check for custom skulls
// TODO: The tag layout follows new format (profille, etc...)
Expand Down

0 comments on commit c54624f

Please sign in to comment.