11package net .hollowcube .polar ;
22
33import com .github .luben .zstd .Zstd ;
4+ import it .unimi .dsi .fastutil .ints .Int2ObjectMap ;
45import it .unimi .dsi .fastutil .objects .Object2IntMap ;
56import it .unimi .dsi .fastutil .objects .Object2IntOpenHashMap ;
67import net .minestom .server .MinecraftServer ;
910import net .minestom .server .coordinate .CoordConversion ;
1011import net .minestom .server .instance .InstanceContainer ;
1112import net .minestom .server .instance .Section ;
13+ import net .minestom .server .instance .block .Block ;
1214import net .minestom .server .network .NetworkBuffer ;
1315import net .minestom .server .utils .validate .Check ;
1416import net .minestom .server .world .biome .Biome ;
@@ -131,7 +133,7 @@ private void readChunk(@NotNull NetworkBuffer buffer, int minSection, int maxSec
131133 // Load block data
132134 synchronized (chunk ) {
133135 for (int sectionY = minSection ; sectionY <= maxSection ; sectionY ++) {
134- readSection (buffer , chunk .getSection (sectionY ));
136+ readSection (buffer , chunk .getSection (sectionY ), sectionY , chunkEntries );
135137 }
136138
137139 // Load block entities
@@ -168,7 +170,7 @@ private void readChunk(@NotNull NetworkBuffer buffer, int minSection, int maxSec
168170 }
169171 }
170172
171- private void readSection (@ NotNull NetworkBuffer buffer , @ NotNull Section section ) {
173+ private void readSection (@ NotNull NetworkBuffer buffer , @ NotNull Section section , int sectionY , @ Nullable Int2ObjectMap < Block > chunkEntires ) {
172174 if (buffer .read (BOOLEAN )) return ; // Empty section
173175
174176 int [] blockPalette = readBlockPalette (buffer );
@@ -188,7 +190,15 @@ private void readSection(@NotNull NetworkBuffer buffer, @NotNull Section section
188190 for (int z = 0 ; z < CHUNK_SECTION_SIZE ; z ++) {
189191 for (int x = 0 ; x < CHUNK_SECTION_SIZE ; x ++) {
190192 int index = y * CHUNK_SECTION_SIZE * CHUNK_SECTION_SIZE + z * CHUNK_SECTION_SIZE + x ;
191- section .blockPalette ().set (x , y , z , blockPalette [blockData [index ]]);
193+ int blockStateId = blockPalette [blockData [index ]];
194+ section .blockPalette ().set (x , y , z , blockStateId );
195+
196+ // Vanilla block entities must be tracked in the chunk entries so they are sent to the client.
197+ var block = Block .fromStateId (blockStateId );
198+ if (chunkEntires != null && block .registry ().isBlockEntity ()) {
199+ int chunkY = sectionY * CHUNK_SECTION_SIZE + y ;
200+ chunkEntires .putIfAbsent (CoordConversion .chunkBlockIndex (x , chunkY , z ), block );
201+ }
192202 }
193203 }
194204 }
0 commit comments