question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

21w37a Block Entities change and what it means for API.

See original GitHub issue

Hi, so basically this is to explore some of the changes in 21w37a to block entities and what it could lead to for the API.

Serialization changed quite a bit, the writeNbt method now returns void and is protected, other public methods should be used, one is basically a proxy, another one adds the id key with the BE type identifier, and another one adds in addition to the id key the x, y, and z fields.

But that’s not the most important changes, the most important change is toUpdatePacket, the return type changed to Packet<?> and the BlockEntityUpdateS2CPacket changed a lot since now it takes a BlockEntityType parameter (got unhardcoded a lot).

All of these changes basically makes BlockEntityClientSerializable obselete. I would recommend:

  • make BlockEntityClientSerializable deprecated, implementation-wise remove the “hack” to the packet.
  • in docs: tell mods to use the BlockEntityUpdateS2CPacket, it has a function to create an instance from the BE.
  • offer the sync method as a helper method outside of BlockEntityClientSerializable

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
LambdAuroracommented, Sep 19, 2021

Haven’t seen it that it was removed, nice.

I have to say that ((ServerWorld) world).getChunkManager().markForUpdate(pos); is definitely not intuitive.

2reactions
Pinaz993commented, Dec 16, 2021

For all who were as lost as I was when attempting to make a block entity sync to the client: I would like to share what I did that worked.

For a while, I was only able to make the data sync when the BlockState changed. (This was after implementing toUpdatePacket()) That changed when I added ((ServerWorld) world).getChunkManager().markForUpdate(pos); to markDirty(). This marks the block position as one that has a block entity to be synced with the client soon, usually within a tick.

However, this will NOT sync your block entity data when the chunk loads. For that, you must turn to toInitialChunkDataNbt() I mistakenly thought that this was data to be sent when the block is first initialized, as in when a new one is placed. (Don’t ask me how I made that mistake. I haven’t a clue.) This is data to be sent when the chunk is loaded. This happens either when the server is loading the chunk into memory from saved data, or when the client is requesting a chunk that is already loaded into memory.

As a bonus, (and as mentioned above), once you implement toInitialChunkDataNbt(), you can simplify toUpdatePacket() to the following:

    @Nullable
    @Override
    public Packet<ClientPlayPacketListener> toUpdatePacket() {
        return BlockEntityUpdateS2CPacket.create(this);
    }

Thus if you do updateListeners() or markForUpdate() when some changed data needs to be sent to the client, and implement both toUpdatePacket() and toInitialChunkDataNbt(), your block entity’s data shouldn’t desync from the client.

(Edited to remove reference to updateListeners(), as that is for when the VoxelShape changes and pathfinding entities need to be updated as to that fact. That’s expensive, and in fact was the very reason BlockEntityClientSyncable existed in the first place.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

tutorial:blockentity [Fabric Wiki]
A BlockEntity is primarily used to store data within blocks. ... In this tutorial, the ID of the block entity is tutorial:demo_block_entity ...
Read more >
Java Edition 21w37a - Minecraft Wiki - Fandom
Reverted change allowing plants to be placed on snow blocks. This reversion results in the lack of vegetation in the grove biome. Items....
Read more >
Block API overview - Drupal
Blocks are defined as plugins, which makes them configuration entities. In order for a configuration entity to be translatable, a schema ...
Read more >
InventoryTabs 0.8.0-1.19.x - Inventory Tabs (updated) - Modrinth
Client side mod to access nearby blocks without leaving your inventory! ... Excluded bed and redstone comparator block entities from showing ...
Read more >
What's New in Minecraft Snapshot 21w37a? ALL ... - YouTube
The first real snapshot for Minecraft 1.18 has arrived - Caves and Cliffs Part II is heating up! Snapshot 21w37a brings you all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found