1
1
package net .hollowcube .polar ;
2
2
3
3
import com .github .luben .zstd .Zstd ;
4
+ import it .unimi .dsi .fastutil .ints .Int2ObjectMap ;
4
5
import it .unimi .dsi .fastutil .objects .Object2IntMap ;
5
6
import it .unimi .dsi .fastutil .objects .Object2IntOpenHashMap ;
6
7
import net .minestom .server .MinecraftServer ;
9
10
import net .minestom .server .coordinate .CoordConversion ;
10
11
import net .minestom .server .instance .InstanceContainer ;
11
12
import net .minestom .server .instance .Section ;
13
+ import net .minestom .server .instance .block .Block ;
12
14
import net .minestom .server .network .NetworkBuffer ;
13
15
import net .minestom .server .utils .validate .Check ;
14
16
import net .minestom .server .world .biome .Biome ;
@@ -131,7 +133,7 @@ private void readChunk(@NotNull NetworkBuffer buffer, int minSection, int maxSec
131
133
// Load block data
132
134
synchronized (chunk ) {
133
135
for (int sectionY = minSection ; sectionY <= maxSection ; sectionY ++) {
134
- readSection (buffer , chunk .getSection (sectionY ));
136
+ readSection (buffer , chunk .getSection (sectionY ), sectionY , chunkEntries );
135
137
}
136
138
137
139
// Load block entities
@@ -168,7 +170,7 @@ private void readChunk(@NotNull NetworkBuffer buffer, int minSection, int maxSec
168
170
}
169
171
}
170
172
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 ) {
172
174
if (buffer .read (BOOLEAN )) return ; // Empty section
173
175
174
176
int [] blockPalette = readBlockPalette (buffer );
@@ -188,7 +190,15 @@ private void readSection(@NotNull NetworkBuffer buffer, @NotNull Section section
188
190
for (int z = 0 ; z < CHUNK_SECTION_SIZE ; z ++) {
189
191
for (int x = 0 ; x < CHUNK_SECTION_SIZE ; x ++) {
190
192
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
+ }
192
202
}
193
203
}
194
204
}
0 commit comments