3232import org .jetbrains .annotations .Nullable ;
3333
3434import java .lang .foreign .Arena ;
35+ import java .lang .foreign .MemoryLayout ;
3536import java .lang .foreign .MemorySegment ;
37+ import java .lang .foreign .SequenceLayout ;
3638import java .util .Comparator ;
3739import java .util .HashMap ;
3840import java .util .HashSet ;
@@ -254,6 +256,14 @@ private static int highlightTerrain(CustomClientCommandSource source, int chunkR
254256 int version = source .getVersion ();
255257
256258 ChunkPos center = new ChunkPos (BlockPos .containing (source .getPosition ()));
259+ int minChunkX = center .x - chunkRange ;
260+ int minChunkZ = center .z - chunkRange ;
261+ int chunkW = chunkRange * 2 + 1 ;
262+ int chunkH = chunkRange * 2 + 1 ;
263+ int blockW = chunkW << 4 ;
264+ int blockH = chunkH << 4 ;
265+ int minX = minChunkX << 4 ;
266+ int minZ = minChunkZ << 4 ;
257267
258268 try (Arena arena = Arena .ofConfined ()) {
259269 MemorySegment params = TerrainNoiseParameters .allocate (arena );
@@ -262,24 +272,23 @@ private static int highlightTerrain(CustomClientCommandSource source, int chunkR
262272 }
263273
264274 Set <BlockPos > blocks = new HashSet <>();
265- SpiralLoop . spiral ( center . x , center . z , chunkRange , ( chunkX , chunkZ ) -> {
266- final int minChunkX = chunkX << 4 ;
267- final int minChunkZ = chunkZ << 4 ;
268- for ( int x = minChunkX ; x < minChunkX + 16 ; x ++) {
269- for (int z = minChunkZ ; z < minChunkZ + 16 ; z ++) {
270- for ( int y = - 64 ; y < 320 ; y ++) {
271- double spaghettiRoughness = Cubiomes . sampleSpaghettiRoughness ( params , x , y , z );
272- double entrances = Cubiomes . sampleEntrances ( params , x , y , z , spaghettiRoughness ) ;
273- double slopedCheese = Cubiomes . sampleSlopedCheese ( params , x , y , z ) ;
274- double sample = Cubiomes . sampleFinalDensity ( params , x , y , z , spaghettiRoughness , entrances , slopedCheese );
275- if ( sample <= 0 ) {
276- blocks . add ( new BlockPos ( x , y , z ));
277- }
275+ SequenceLayout columnLayout = MemoryLayout . sequenceLayout ( 384 , Cubiomes . C_INT );
276+ MemorySegment blockStates = arena . allocate ( columnLayout , ( long ) blockW * blockH ) ;
277+ Cubiomes . generateRegion ( params , minChunkX , minChunkZ , chunkW , chunkH , blockStates , MemorySegment . NULL , 0 ) ;
278+
279+ for (int relX = 0 ; relX < blockW ; relX ++) {
280+ int x = minX + relX ;
281+ for ( int relZ = 0 ; relZ < blockH ; relZ ++) {
282+ int z = minZ + relZ ;
283+ int columnIdx = ( relX * blockH + relZ ) * 384 ;
284+ for ( int y = - 64 ; y < 320 ; y ++) {
285+ int block = blockStates . getAtIndex ( Cubiomes . C_INT , columnIdx + y + 64 );
286+ if ( block == 1 ) {
287+ blocks . add ( new BlockPos ( x , y , z ));
278288 }
279289 }
280290 }
281- return false ;
282- });
291+ }
283292 RenderManager .drawBoxes (blocks , Configs .TerrainESP , 0xFF_FF0000 );
284293 return blocks .size ();
285294 }
0 commit comments