@@ -41,8 +41,10 @@ final class StreamingPolarLoader {
4141 private final Object2IntMap <String > biomeToIdCache = new Object2IntOpenHashMap <>();
4242 private final int plainsBiomeId ;
4343
44- StreamingPolarLoader (@ NotNull InstanceContainer instance , @ NotNull PolarDataConverter dataConverter ,
45- @ Nullable PolarWorldAccess worldAccess , boolean loadLighting ) {
44+ StreamingPolarLoader (
45+ @ NotNull InstanceContainer instance , @ NotNull PolarDataConverter dataConverter ,
46+ @ Nullable PolarWorldAccess worldAccess , boolean loadLighting
47+ ) {
4648 this .instance = instance ;
4749 this .dataConverter = dataConverter ;
4850 this .worldAccess = worldAccess ;
@@ -111,7 +113,8 @@ private NetworkBuffer readHeader(@NotNull ReadableByteChannel channel, long file
111113 final var dst = NetworkBuffer .staticBuffer (compressedDataLength , MinecraftServer .process ());
112114 final var srcAddress = networkBufferAddress (buffer ) + buffer .readIndex ();
113115 final var dstAddress = networkBufferAddress (dst );
114- long count = Zstd .decompressUnsafe (dstAddress , compressedDataLength , srcAddress , buffer .readableBytes ());
116+ long count = Zstd .decompressUnsafe (dstAddress , compressedDataLength , srcAddress ,
117+ buffer .readableBytes ());
115118 if (Zstd .isError (count )) {
116119 throw new RuntimeException ("decompression failed: " + Zstd .getErrorName (count ));
117120 }
@@ -142,7 +145,8 @@ private void readChunk(@NotNull NetworkBuffer buffer, int minSection, int maxSec
142145 final var blockEntity = readBlockEntity (dataConverter , version , dataVersion , buffer );
143146 if (chunkEntries != null && chunkTickables != null ) {
144147 final var block = createBlockEntity (chunk , blockEntity );
145- final int index = CoordConversion .chunkBlockIndex (blockEntity .x (), blockEntity .y (), blockEntity .z ());
148+ final int index = CoordConversion .chunkBlockIndex (
149+ blockEntity .x (), blockEntity .y (), blockEntity .z ());
146150 chunkEntries .put (index , block );
147151 if (block .handler () != null && block .handler ().isTickable ())
148152 chunkTickables .put (index , block );
@@ -157,6 +161,7 @@ private void readChunk(@NotNull NetworkBuffer buffer, int minSection, int maxSec
157161 else unsafeSetNeedsCompleteHeightmapRefresh (chunk , true );
158162 }
159163
164+ unsafeChunkOnLoad (chunk );
160165 unsafeCacheChunk (instance , chunk );
161166
162167 // Load user data
@@ -170,7 +175,10 @@ private void readChunk(@NotNull NetworkBuffer buffer, int minSection, int maxSec
170175 }
171176 }
172177
173- private void readSection (@ NotNull NetworkBuffer buffer , @ NotNull Section section , int sectionY , @ Nullable Int2ObjectMap <Block > chunkEntires ) {
178+ private void readSection (
179+ @ NotNull NetworkBuffer buffer , @ NotNull Section section , int sectionY ,
180+ @ Nullable Int2ObjectMap <Block > chunkEntires
181+ ) {
174182 if (buffer .read (BOOLEAN )) return ; // Empty section
175183
176184 int [] blockPalette = readBlockPalette (buffer );
@@ -202,20 +210,20 @@ private void readSection(@NotNull NetworkBuffer buffer, @NotNull Section section
202210 }
203211 }
204212 }
205- // section.blockPalette().setAll((x, y, z) -> {
206- // int index = y * CHUNK_SECTION_SIZE * CHUNK_SECTION_SIZE + z * CHUNK_SECTION_SIZE + x;
207- // return blockPalette[blockData[index]];
208- // });
213+ // section.blockPalette().setAll((x, y, z) -> {
214+ // int index = y * CHUNK_SECTION_SIZE * CHUNK_SECTION_SIZE + z * CHUNK_SECTION_SIZE + x;
215+ // return blockPalette[blockData[index]];
216+ // });
209217
210218 // Below was some previous logic, leaving it around for now I would like to fix it up.
211- // System.out.println(Arrays.toString(blockPalette));
212- // var rawBlockData = buffer.read(LONG_ARRAY);
213- // var bitsPerEntry = (int) Math.ceil(Math.log(blockPalette.length) / Math.log(2));
214- //
215- //// int count = computeCount(blockPalette, rawBlockData, bitsPerEntry);
216- // int count = 16 * 16 * 16;
217- // directReplaceInnerPaletteBlock(section.blockPalette(), (byte) bitsPerEntry, count,
218- // blockPalette, rawBlockData);
219+ // System.out.println(Arrays.toString(blockPalette));
220+ // var rawBlockData = buffer.read(LONG_ARRAY);
221+ // var bitsPerEntry = (int) Math.ceil(Math.log(blockPalette.length) / Math.log(2));
222+ //
223+ //// int count = computeCount(blockPalette, rawBlockData, bitsPerEntry);
224+ // int count = 16 * 16 * 16;
225+ // directReplaceInnerPaletteBlock(section.blockPalette(), (byte) bitsPerEntry, count,
226+ // blockPalette, rawBlockData);
219227 }
220228
221229 int [] biomePalette = readBiomePalette (buffer );
@@ -236,17 +244,17 @@ private void readSection(@NotNull NetworkBuffer buffer, @NotNull Section section
236244 }
237245 }
238246 }
239- // section.biomePalette().setAll((x, y, z) -> {
240- // int index = x / 4 + (z / 4) * 4 + (y / 4) * 16;
241- // return biomePalette[biomeData[index]];
242- // });
243-
244- // var rawBiomeData = buffer.read(LONG_ARRAY);
245- // var bitsPerEntry = (int) Math.ceil(Math.log(biomePalette.length) / Math.log(2));
246- // // Biome count is irrelevant to the client. Though it might be worth computing it anyway here
247- // // in case a server implementation uses it for anything.
248- // directReplaceInnerPaletteBiome(section.biomePalette(), (byte) bitsPerEntry, 4 * 4 * 4,
249- // biomePalette, rawBiomeData);
247+ // section.biomePalette().setAll((x, y, z) -> {
248+ // int index = x / 4 + (z / 4) * 4 + (y / 4) * 16;
249+ // return biomePalette[biomeData[index]];
250+ // });
251+
252+ // var rawBiomeData = buffer.read(LONG_ARRAY);
253+ // var bitsPerEntry = (int) Math.ceil(Math.log(biomePalette.length) / Math.log(2));
254+ // // Biome count is irrelevant to the client. Though it might be worth computing it anyway here
255+ // // in case a server implementation uses it for anything.
256+ // directReplaceInnerPaletteBiome(section.biomePalette(), (byte) bitsPerEntry, 4 * 4 * 4,
257+ // biomePalette, rawBiomeData);
250258 }
251259
252260 if (version > PolarWorld .VERSION_UNIFIED_LIGHT ) {
@@ -298,7 +306,8 @@ private int[] readBiomePalette(@NotNull NetworkBuffer buffer) {
298306 int [] biomePalette = new int [rawBiomePalette .length ];
299307 for (int i = 0 ; i < rawBiomePalette .length ; i ++) {
300308 biomePalette [i ] = biomeToIdCache .computeIfAbsent (rawBiomePalette [i ], (String name ) -> {
301- PolarWorldAccess searchWorldAccess = Objects .requireNonNullElse (this .worldAccess , PolarWorldAccess .DEFAULT );
309+ PolarWorldAccess searchWorldAccess = Objects .requireNonNullElse (this .worldAccess ,
310+ PolarWorldAccess .DEFAULT );
302311 var biomeId = searchWorldAccess .getBiomeId (name );
303312 if (biomeId == -1 ) {
304313 logger .error ("Failed to find biome: {}" , name );
0 commit comments