Fix some cases of empty tags being needed

This commit is contained in:
Camotoy 2024-04-23 16:14:18 -04:00
parent abea0131e4
commit c54624fb26
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 14 additions and 6 deletions

View file

@ -43,12 +43,16 @@ public abstract class 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)

View file

@ -393,10 +393,9 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
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
@ -421,8 +420,13 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
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...)