3838import org .geysermc .geyser .translator .protocol .PacketTranslator ;
3939import org .geysermc .geyser .translator .protocol .Translator ;
4040
41+ import java .util .BitSet ;
42+
4143@ Translator (packet = ClientboundSectionBlocksUpdatePacket .class )
4244public class JavaSectionBlocksUpdateTranslator extends PacketTranslator <ClientboundSectionBlocksUpdatePacket > {
4345
@@ -51,25 +53,35 @@ public void translate(GeyserSession session, ClientboundSectionBlocksUpdatePacke
5153 }
5254 }
5355
56+ BitSet waterlogged = BlockRegistries .WATERLOGGED .get ();
57+
5458 UpdateSubChunkBlocksPacket updateSubChunkBlocksPacket = new UpdateSubChunkBlocksPacket ();
5559
5660 for (BlockChangeEntry entry : packet .getEntries ()) {
61+ session .getWorldCache ().removePrediction (entry .getPosition ());
62+
5763 int oldBlock = palette != null
5864 ? palette .get (entry .getPosition ().getX () & 0xF , entry .getPosition ().getY () & 0xF , entry .getPosition ().getZ () & 0xF )
5965 : session .getGeyser ().getWorldManager ().getBlockAt (session , entry .getPosition ());
6066 if (entry .getBlock () == oldBlock ) {
67+ // Skip unchanged blocks which may occur with older versions of Minecraft
6168 continue ;
6269 }
6370
71+ if (palette != null ) {
72+ palette .set (entry .getPosition ().getX () & 0xF , entry .getPosition ().getY () & 0xF , entry .getPosition ().getZ () & 0xF , entry .getBlock ());
73+ }
74+
6475 BlockState blockState = BlockState .of (entry .getBlock ());
6576 if (blockState .is (Blocks .AIR )) {
6677 ItemFrameEntity itemFrameEntity = ItemFrameEntity .getItemFrameEntity (session , entry .getPosition ());
67- if (itemFrameEntity != null ) {
78+ if (itemFrameEntity != null ) { // Item frame is still present and no block overrides that; refresh it
6879 itemFrameEntity .updateBlock (true );
6980 continue ;
7081 }
7182 }
7283 if (!(blockState .block () instanceof SkullBlock )) {
84+ // Skull is gone
7385 session .getSkullCache ().removeSkull (entry .getPosition ());
7486 }
7587
@@ -81,8 +93,8 @@ public void translate(GeyserSession session, ClientboundSectionBlocksUpdatePacke
8193 org .cloudburstmc .protocol .bedrock .data .BlockChangeEntry .MessageType .NONE
8294 ));
8395
84- boolean isWaterlogged = BlockRegistries . WATERLOGGED . get () .get (entry .getBlock ());
85- if (BlockRegistries . WATERLOGGED . get () .get (oldBlock ) != isWaterlogged ) {
96+ boolean isWaterlogged = waterlogged .get (entry .getBlock ());
97+ if (waterlogged .get (oldBlock ) != isWaterlogged ) {
8698 updateSubChunkBlocksPacket .getExtraBlocks ().add (new org .cloudburstmc .protocol .bedrock .data .BlockChangeEntry (
8799 entry .getPosition (),
88100 isWaterlogged ? session .getBlockMappings ().getBedrockWater () : session .getBlockMappings ().getBedrockAir (),
@@ -91,10 +103,6 @@ public void translate(GeyserSession session, ClientboundSectionBlocksUpdatePacke
91103 org .cloudburstmc .protocol .bedrock .data .BlockChangeEntry .MessageType .NONE
92104 ));
93105 }
94-
95- if (palette != null ) {
96- palette .set (entry .getPosition ().getX () & 0xF , entry .getPosition ().getY () & 0xF , entry .getPosition ().getZ () & 0xF , entry .getBlock ());
97- }
98106 }
99107
100108 session .sendUpstreamPacket (updateSubChunkBlocksPacket );
0 commit comments