88import com .github .cubiomes .OreVeinParameters ;
99import com .github .cubiomes .Pos3 ;
1010import com .github .cubiomes .Pos3List ;
11+ import com .github .cubiomes .Range ;
1112import com .github .cubiomes .SurfaceNoise ;
1213import com .github .cubiomes .TerrainNoise ;
1314import com .mojang .brigadier .CommandDispatcher ;
4647import java .util .Map ;
4748import java .util .Objects ;
4849import java .util .Set ;
49- import java .util .function .BiFunction ;
5050import java .util .stream .Collectors ;
5151import java .util .stream .IntStream ;
5252
@@ -86,7 +86,7 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
8686 .requires (_ -> Configs .DevMode )
8787 .then (argument ("cave" , caveCarver ())
8888 .executes (ctx -> highlightCave (CustomClientCommandSource .of (ctx .getSource ()), getCaveCarver (ctx , "cave" )))
89- .then (argument ("chunks" , integer (0 , 20 ))
89+ .then (argument ("chunks" , integer (0 , 10 ))
9090 .executes (ctx -> submit (() -> highlightCave (CustomClientCommandSource .of (ctx .getSource ()), getCaveCarver (ctx , "cave" ), getInteger (ctx , "chunks" ))))))));
9191 }
9292
@@ -330,13 +330,8 @@ private static int highlightCanyon(CustomClientCommandSource source, int canyonC
330330 if (CanyonCarverConfig .dim (ccc ) != dimension ) {
331331 throw CommandExceptions .INVALID_DIMENSION_EXCEPTION .create ();
332332 }
333- var biomeFunction = LocateCommand .getCarverBiomeFunction (arena , seed .seed (), dimension , version , source .getGeneratorFlags ());
334- return highlightCarver (source , chunkRange , Configs .CanyonESP , (chunkX , chunkZ ) -> {
335- int biome = biomeFunction .applyAsInt (chunkX , chunkZ );
336- if (Cubiomes .isViableCanyonBiome (canyonCarver , biome ) == 0 ) {
337- return null ;
338- }
339- return Cubiomes .carveCanyon (arena , seed .seed (), chunkX , chunkZ , ccc );
333+ return highlightCarver (source , chunkRange , Configs .CanyonESP , arena , (chunkX , chunkZ , biomes , poses ) -> {
334+ Cubiomes .carveCanyon (seed .seed (), version , chunkX , chunkZ , ccc , canyonCarver , biomes , poses );
340335 });
341336 }
342337 }
@@ -359,34 +354,63 @@ private static int highlightCave(CustomClientCommandSource source, int caveCarve
359354 if (CaveCarverConfig .dim (ccc ) != dimension ) {
360355 throw CommandExceptions .INVALID_DIMENSION_EXCEPTION .create ();
361356 }
362- var biomeFunction = LocateCommand .getCarverBiomeFunction (arena , seed .seed (), dimension , version , source .getGeneratorFlags ());
363- return highlightCarver (source , chunkRange , Configs .CaveESP , (chunkX , chunkZ ) -> {
364- int biome = biomeFunction .applyAsInt (chunkX , chunkZ );
365- if (Cubiomes .isViableCaveBiome (caveCarver , biome ) == 0 ) {
366- return null ;
367- }
368- return Cubiomes .carveCave (arena , seed .seed (), chunkX , chunkZ , ccc );
357+ return highlightCarver (source , chunkRange , Configs .CaveESP , arena , (chunkX , chunkZ , biomes , poses ) -> {
358+ Cubiomes .carveCave (seed .seed (), version , chunkX , chunkZ , ccc , caveCarver , biomes , poses );
369359 });
370360 }
371361 }
372362
373- private static int highlightCarver (CustomClientCommandSource source , int chunkRange , EspStyle style , BiFunction <Integer , Integer , @ Nullable MemorySegment > carverFunction ) {
363+ private static int highlightCarver (CustomClientCommandSource source , int chunkRange , EspStyle style , Arena arena , CarverFunction carverFunction ) throws CommandSyntaxException {
364+ SeedIdentifier seed = source .getSeed ().getSecond ();
365+ int dimension = source .getDimension ();
366+ int version = source .getVersion ();
367+ int generatorFlags = source .getGeneratorFlags ();
368+
369+ @ Nullable MemorySegment generator , range ;
370+ MemorySegment biomes ;
371+ if (version <= Cubiomes .MC_1_17_1 ()) {
372+ generator = Generator .allocate (arena );
373+ Cubiomes .setupGenerator (generator , version , generatorFlags );
374+ Cubiomes .applySeed (generator , dimension , seed .seed ());
375+
376+ range = Range .allocate (arena );
377+ Range .scale (range , 16 );
378+ Range .sx (range , 17 );
379+ Range .sz (range , 17 );
380+ Range .y (range , 0 );
381+ Range .sy (range , 0 );
382+
383+ long cacheSize = Cubiomes .getMinCacheSize (generator , Range .scale (range ), Range .sx (range ), Range .sy (range ), Range .sz (range ));
384+ biomes = arena .allocate (Cubiomes .C_INT , cacheSize );
385+ } else {
386+ generator = null ;
387+ range = null ;
388+ biomes = arena .allocate (MemoryLayout .sequenceLayout (17 , MemoryLayout .sequenceLayout (17 , Cubiomes .C_INT )));
389+ }
390+
391+ MemorySegment pos3List = Pos3List .allocate (arena );
392+ Cubiomes .createPos3List (pos3List , 1024 );
393+
374394 ChunkPos center = ChunkPos .containing (BlockPos .containing (source .getPosition ()));
375- Set <BlockPos > blocks = new HashSet <>();
376395 SpiralLoop .spiral (center .x (), center .z (), chunkRange , (chunkX , chunkZ ) -> {
377- MemorySegment pos3List = carverFunction .apply (chunkX , chunkZ );
378- if (pos3List == null ) {
379- return false ;
380- }
381- int size = Pos3List .size (pos3List );
382- MemorySegment pos3s = Pos3List .pos3s (pos3List );
383- for (int i = 0 ; i < size ; i ++) {
384- MemorySegment pos3 = Pos3 .asSlice (pos3s , i );
385- blocks .add (new BlockPos (Pos3 .x (pos3 ), Pos3 .y (pos3 ), Pos3 .z (pos3 )));
396+ if (version <= Cubiomes .MC_1_17_1 ()) {
397+ assert range != null ;
398+ Range .x (range , chunkX - 8 );
399+ Range .z (range , chunkZ - 8 );
400+ Cubiomes .genBiomes (generator , biomes , range );
386401 }
387-
402+ carverFunction . carve ( chunkX , chunkZ , biomes , pos3List );
388403 return false ;
389404 });
405+
406+ Set <BlockPos > blocks = new HashSet <>();
407+ int size = Pos3List .size (pos3List );
408+ MemorySegment pos3s = Pos3List .pos3s (pos3List );
409+ for (int i = 0 ; i < size ; i ++) {
410+ MemorySegment pos3 = Pos3 .asSlice (pos3s , i );
411+ blocks .add (new BlockPos (Pos3 .x (pos3 ), Pos3 .y (pos3 ), Pos3 .z (pos3 )));
412+ }
413+ Cubiomes .freePos3List (pos3List );
390414 RenderManager .drawBoxes (blocks , style , 0xFF_FF0000 );
391415 source .getClient ().schedule (() -> source .sendFeedback (Component .translatable ("command.highlight.carver.success" , accent (String .valueOf (blocks .size ())))));
392416 return blocks .size ();
@@ -396,4 +420,9 @@ private static boolean isAirOrLava(LevelChunk chunk, BlockPos pos) {
396420 var state = chunk .getBlockState (pos );
397421 return state .isAir () || state .is (Blocks .LAVA ) || state .getFluidState ().is (Fluids .LAVA );
398422 }
423+
424+ @ FunctionalInterface
425+ private interface CarverFunction {
426+ void carve (int chunkX , int chunkZ , MemorySegment biomes , MemorySegment poses );
427+ }
399428}
0 commit comments