7
7
import net .minestom .server .command .builder .arguments .minecraft .ArgumentBlockState ;
8
8
import net .minestom .server .command .builder .exception .ArgumentSyntaxException ;
9
9
import net .minestom .server .coordinate .CoordConversion ;
10
- import net .minestom .server .instance .Chunk ;
11
10
import net .minestom .server .instance .InstanceContainer ;
12
11
import net .minestom .server .instance .Section ;
13
12
import net .minestom .server .network .NetworkBuffer ;
22
21
import static net .hollowcube .polar .PolarLoader .*;
23
22
import static net .hollowcube .polar .PolarReader .*;
24
23
import static net .hollowcube .polar .UnsafeOps .*;
25
- import static net .minestom .server .instance .palette .PolarPaletteAccessWidener .directReplaceInnerPaletteBiome ;
26
- import static net .minestom .server .instance .palette .PolarPaletteAccessWidener .directReplaceInnerPaletteBlock ;
24
+ import static net .minestom .server .instance .Chunk .CHUNK_SECTION_SIZE ;
27
25
import static net .minestom .server .network .NetworkBuffer .*;
28
26
import static net .minestom .server .network .PolarBufferAccessWidener .networkBufferAddress ;
29
27
import static net .minestom .server .network .PolarBufferAccessWidener .networkBufferView ;
@@ -66,7 +64,7 @@ public void loadAllSequential(@NotNull ReadableByteChannel channel, long fileSiz
66
64
// Chunk data
67
65
int chunkCount = buffer .read (VAR_INT );
68
66
for (int i = 0 ; i < chunkCount ; i ++) {
69
- unsafeCacheChunk ( instance , readChunk (buffer , minSection , maxSection ) );
67
+ readChunk (buffer , minSection , maxSection );
70
68
}
71
69
72
70
Check .stateCondition (buffer .readableBytes () > 0 , "Unexpected extra data at end of buffer" );
@@ -114,7 +112,7 @@ private NetworkBuffer readHeader(@NotNull ReadableByteChannel channel, long file
114
112
};
115
113
}
116
114
117
- private @ NotNull Chunk readChunk (@ NotNull NetworkBuffer buffer , int minSection , int maxSection ) {
115
+ private void readChunk (@ NotNull NetworkBuffer buffer , int minSection , int maxSection ) {
118
116
final var chunkX = buffer .read (VAR_INT );
119
117
final var chunkZ = buffer .read (VAR_INT );
120
118
final var chunk = instance .getChunkSupplier ().createChunk (instance , chunkX , chunkZ );
@@ -147,19 +145,19 @@ private NetworkBuffer readHeader(@NotNull ReadableByteChannel channel, long file
147
145
int [][] heightmaps = readHeightmapData (buffer , worldAccess == null );
148
146
if (worldAccess != null ) worldAccess .loadHeightmaps (chunk , heightmaps );
149
147
else unsafeSetNeedsCompleteHeightmapRefresh (chunk , true );
148
+ }
150
149
151
- // Load user data
152
- if ( version > PolarWorld . VERSION_USERDATA_OPT_BLOCK_ENT_NBT ) {
153
- int userDataLength = buffer . read ( VAR_INT );
154
- if (worldAccess != null ) {
155
- var chunkDataView = networkBufferView ( buffer , buffer . readIndex (), userDataLength );
156
- worldAccess . loadChunkData ( chunk , chunkDataView );
157
- }
158
- buffer . advanceRead ( userDataLength );
150
+ unsafeCacheChunk ( instance , chunk );
151
+
152
+ // Load user data
153
+ if (version > PolarWorld . VERSION_USERDATA_OPT_BLOCK_ENT_NBT ) {
154
+ int userDataLength = buffer . read ( VAR_INT );
155
+ if ( worldAccess != null ) {
156
+ var chunkDataView = networkBufferView ( buffer , buffer . readIndex (), userDataLength );
157
+ worldAccess . loadChunkData ( chunk , chunkDataView );
159
158
}
159
+ buffer .advanceRead (userDataLength );
160
160
}
161
-
162
- return chunk ;
163
161
}
164
162
165
163
private void readSection (@ NotNull NetworkBuffer buffer , @ NotNull Section section ) {
@@ -172,24 +170,49 @@ private void readSection(@NotNull NetworkBuffer buffer, @NotNull Section section
172
170
section .blockPalette ().fill (blockPalette [0 ]);
173
171
}
174
172
} else {
173
+ var blockData = new int [PolarSection .BLOCK_PALETTE_SIZE ];
174
+
175
175
var rawBlockData = buffer .read (LONG_ARRAY );
176
176
var bitsPerEntry = (int ) Math .ceil (Math .log (blockPalette .length ) / Math .log (2 ));
177
+ PaletteUtil .unpack (blockData , rawBlockData , bitsPerEntry );
178
+
179
+ section .blockPalette ().setAll ((x , y , z ) -> {
180
+ int index = y * CHUNK_SECTION_SIZE * CHUNK_SECTION_SIZE + z * CHUNK_SECTION_SIZE + x ;
181
+ return blockPalette [blockData [index ]];
182
+ });
177
183
178
- int count = computeCount (blockPalette , rawBlockData , bitsPerEntry );
179
- directReplaceInnerPaletteBlock (section .blockPalette (), (byte ) bitsPerEntry , count ,
180
- blockPalette , rawBlockData );
184
+ // Below was some previous logic, leaving it around for now I would like to fix it up.
185
+ // System.out.println(Arrays.toString(blockPalette));
186
+ // var rawBlockData = buffer.read(LONG_ARRAY);
187
+ // var bitsPerEntry = (int) Math.ceil(Math.log(blockPalette.length) / Math.log(2));
188
+ //
189
+ //// int count = computeCount(blockPalette, rawBlockData, bitsPerEntry);
190
+ // int count = 16 * 16 * 16;
191
+ // directReplaceInnerPaletteBlock(section.blockPalette(), (byte) bitsPerEntry, count,
192
+ // blockPalette, rawBlockData);
181
193
}
182
194
183
195
int [] biomePalette = readBiomePalette (buffer );
184
196
if (biomePalette .length == 1 ) {
185
197
section .biomePalette ().fill (biomePalette [0 ]);
186
198
} else {
199
+ var biomeData = new int [PolarSection .BIOME_PALETTE_SIZE ];
200
+
187
201
var rawBiomeData = buffer .read (LONG_ARRAY );
188
202
var bitsPerEntry = (int ) Math .ceil (Math .log (biomePalette .length ) / Math .log (2 ));
189
- // Biome count is irrelevant to the client. Though it might be worth computing it anyway here
190
- // in case a server implementation uses it for anything.
191
- directReplaceInnerPaletteBiome (section .biomePalette (), (byte ) bitsPerEntry , 4 * 4 * 4 ,
192
- biomePalette , rawBiomeData );
203
+ PaletteUtil .unpack (biomeData , rawBiomeData , bitsPerEntry );
204
+
205
+ section .biomePalette ().setAll ((x , y , z ) -> {
206
+ int index = x / 4 + (z / 4 ) * 4 + (y / 4 ) * 16 ;
207
+ return biomePalette [biomeData [index ]];
208
+ });
209
+
210
+ // var rawBiomeData = buffer.read(LONG_ARRAY);
211
+ // var bitsPerEntry = (int) Math.ceil(Math.log(biomePalette.length) / Math.log(2));
212
+ // // Biome count is irrelevant to the client. Though it might be worth computing it anyway here
213
+ // // in case a server implementation uses it for anything.
214
+ // directReplaceInnerPaletteBiome(section.biomePalette(), (byte) bitsPerEntry, 4 * 4 * 4,
215
+ // biomePalette, rawBiomeData);
193
216
}
194
217
195
218
if (version > PolarWorld .VERSION_UNIFIED_LIGHT ) {
0 commit comments