21w37a Block Entities change and what it means for API.
See original GitHub issueHi, 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:
- Created 2 years ago
- Reactions:3
- Comments:10 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Haven’t seen it that it was removed, nice.
I have to say that
((ServerWorld) world).getChunkManager().markForUpdate(pos);
is definitely not intuitive.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 implementingtoUpdatePacket()
) That changed when I added((ServerWorld) world).getChunkManager().markForUpdate(pos);
tomarkDirty()
. 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 simplifytoUpdatePacket()
to the following:Thus if you do
updateListeners()
ormarkForUpdate()
when some changed data needs to be sent to the client, and implement bothtoUpdatePacket()
andtoInitialChunkDataNbt()
, your block entity’s data shouldn’t desync from the client.(Edited to remove reference to
updateListeners()
, as that is for when theVoxelShape
changes and pathfinding entities need to be updated as to that fact. That’s expensive, and in fact was the very reasonBlockEntityClientSyncable
existed in the first place.)