3030import org .jetbrains .annotations .Nullable ;
3131
3232import java .lang .foreign .Arena ;
33+ import java .lang .foreign .MemoryLayout ;
3334import java .lang .foreign .MemorySegment ;
35+ import java .lang .foreign .SequenceLayout ;
3436import java .util .Comparator ;
3537import java .util .HashMap ;
3638import java .util .HashSet ;
@@ -252,6 +254,14 @@ private static int highlightTerrain(CustomClientCommandSource source, int chunkR
252254 int version = source .getVersion ();
253255
254256 ChunkPos center = new ChunkPos (BlockPos .containing (source .getPosition ()));
257+ int minChunkX = center .x - chunkRange ;
258+ int minChunkZ = center .z - chunkRange ;
259+ int chunkW = chunkRange * 2 + 1 ;
260+ int chunkH = chunkRange * 2 + 1 ;
261+ int blockW = chunkW << 4 ;
262+ int blockH = chunkH << 4 ;
263+ int minX = minChunkX << 4 ;
264+ int minZ = minChunkZ << 4 ;
255265
256266 try (Arena arena = Arena .ofConfined ()) {
257267 MemorySegment params = TerrainNoiseParameters .allocate (arena );
@@ -260,24 +270,23 @@ private static int highlightTerrain(CustomClientCommandSource source, int chunkR
260270 }
261271
262272 Set <BlockPos > blocks = new HashSet <>();
263- SpiralLoop . spiral ( center . x , center . z , chunkRange , ( chunkX , chunkZ ) -> {
264- final int minChunkX = chunkX << 4 ;
265- final int minChunkZ = chunkZ << 4 ;
266- for ( int x = minChunkX ; x < minChunkX + 16 ; x ++) {
267- for (int z = minChunkZ ; z < minChunkZ + 16 ; z ++) {
268- for ( int y = - 64 ; y < 320 ; y ++) {
269- double spaghettiRoughness = Cubiomes . sampleSpaghettiRoughness ( params , x , y , z );
270- double entrances = Cubiomes . sampleEntrances ( params , x , y , z , spaghettiRoughness ) ;
271- double slopedCheese = Cubiomes . sampleSlopedCheese ( params , x , y , z ) ;
272- double sample = Cubiomes . sampleFinalDensity ( params , x , y , z , spaghettiRoughness , entrances , slopedCheese );
273- if ( sample <= 0 ) {
274- blocks . add ( new BlockPos ( x , y , z ));
275- }
273+ SequenceLayout columnLayout = MemoryLayout . sequenceLayout ( 384 , Cubiomes . C_INT );
274+ MemorySegment blockStates = arena . allocate ( columnLayout , ( long ) blockW * blockH ) ;
275+ Cubiomes . generateRegion ( params , minChunkX , minChunkZ , chunkW , chunkH , blockStates , MemorySegment . NULL , 0 ) ;
276+
277+ for (int relX = 0 ; relX < blockW ; relX ++) {
278+ int x = minX + relX ;
279+ for ( int relZ = 0 ; relZ < blockH ; relZ ++) {
280+ int z = minZ + relZ ;
281+ int columnIdx = ( relX * blockH + relZ ) * 384 ;
282+ for ( int y = - 64 ; y < 320 ; y ++) {
283+ int block = blockStates . getAtIndex ( Cubiomes . C_INT , columnIdx + y + 64 );
284+ if ( block == 1 ) {
285+ blocks . add ( new BlockPos ( x , y , z ));
276286 }
277287 }
278288 }
279- return false ;
280- });
289+ }
281290 RenderManager .drawBoxes (blocks , 0xFF_FF0000 );
282291 return blocks .size ();
283292 }
0 commit comments