Page 1 of 1

Patch to limit cave generation in mgv7

PostPosted: Sat Dec 17, 2016 06:05
by sorcerykid
I reworked the v7 cave generator for Minetest 0.4.13, including the addition of the following mapgen parameters:

  • mgv7_spflags = [nocaverns|caverns], [notunnels|tunnels]
    Flags specifying which v7 cave generator to use; requires that "caves" be enabled in mg_flags
  • caves_bedrock_level = [value]
    Integer specifying the lower boundary for generated tunnels (does not apply to caverns)
  • caves_surface_level = [value]
    Integer specifying the upper boundary for generated tunnels (does not apply to caverns)
I was able to cull quite a bit of redundant and extraneous code from from CaveV7::makeCave( ). I opted to limit the range based upon just the route area (ar), rather than the more obfuscated water_level calculations.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
   // Limit route along y-axis to height of area
   route_y_min = 0;
   route_y_max = ar.Y - 1;

   // Randomize starting position relative to area
   orp = v3f(
      (float)(ps->next() % ar.X) + 0.5,
      (float)(ps->range(route_y_min, route_y_max)) + 0.5,
      (float)(ps->next() % ar.Z) + 0.5
   );

I also fixed the start-point and end-point boundary checks in "CaveV7::makeTunnel( )". The radius (rs) was being added to the absolute position (p), even though the height-map comparison is only applicable along the Y-axis.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
   p = of + orpi + veci;
   if (p.Z >= node_min.Z && p.Z <= node_max.Z &&
         p.X >= node_min.X && p.X <= node_max.X) {
      u32 index = (p.Z - node_min.Z) * mg->ystride + (p.X - node_min.X);
      s16 h = mg->ridge_heightmap[index];
      if (p.Y + rs / 2 > h)
         return; // Ignore section not in our heightmap
   }
   if (p.Y + rs / 2 > surface_level || p.Y - rs / 2 < bedrock_level) {
      return; // Ignore section above surface level or below bedrock level
   }



I tested these changes extensively with a variety of mapgen parameters, and all works as expected. I was also careful to use an unassigned slot in mgv7_spflags, accounting for addition of "floatlands" in 0.4.14.

All of the patched files are in the attachment, with comments delineating the specific changes. I hope it is useful!

Re: Patch to limit cave generation in mgv7

PostPosted: Sat Dec 17, 2016 11:49
by ExeterDad
Nice!
I guess you won't be irked by that any more :P

Re: Patch to limit cave generation in mgv7

PostPosted: Wed Jan 04, 2017 17:59
by sorcerykid
My cavegen patch for Minetest 0.4.14 is now available. Bear in mind, I renamed the mapgen parameters for consistency with the official conventions (they are mgv7-specific) and to coincide with the addition of mgv7_cave_width:

  • mgv7_spflags = [nocaverns|caverns], [notunnels|tunnels]
    Flags specifying which v7 cave generator to use; requires that "caves" be enabled in mg_flags
  • mgv7_cave_depth_min = [value]
    Integer specifying the lower boundary for generated tunnels (formerly caves_bedrock_level)
  • mgv7_cave_depth_max = [value]
    Integer specifying the upper boundary for generated tunnels (formerly caves_surface_level)
Simply copy the files from the attached archive into your "minetest-0.4.14/src" directory. Then recompile for the changes to take effect. Enjoy your new customized caves!