Update & improve documentation
							parent
							
								
									f718768235
								
							
						
					
					
						commit
						25a72b62a4
					
				
							
								
								
									
										21
									
								
								API.md
								
								
								
								
							
							
						
						
									
										21
									
								
								API.md
								
								
								
								
							|  | @ -48,16 +48,6 @@ The shapes are defined as follows: | |||
|     --                       |                    |                   | | ||||
|     --            massive caves only       smaller caves         always cave | ||||
| 
 | ||||
|     func = function(pos, n) | ||||
|         return 2 * n | ||||
|     end, | ||||
|     -- Function to edit the NoiseParams based on some operation. | ||||
|     -- Keep in mind that this function will be run many, many times, so it is | ||||
|     -- best to keep this function as trivial as possible. | ||||
|     -- The function receives a node's position `pos` and the noise value `n`, | ||||
|     -- and it is expected to return an updated noise value. | ||||
|     -- If absent, the noise value is used as-is. | ||||
| 
 | ||||
|     y_min = -31000, | ||||
|     y_max = 31000, | ||||
|     -- Lower and upper limits for cave shapes. | ||||
|  | @ -250,7 +240,6 @@ The decorations are defined as follows: | |||
|     -- Rotation can be "0", "90", "180", "270", or "random" | ||||
| 
 | ||||
|     place_offset_y = 0, | ||||
|     -- If the flag 'place_center_y' is set this parameter is ignored. | ||||
|     -- Y offset of the schematic base node layer relative to the 'place_on' | ||||
|     -- node. | ||||
|     -- Can be positive or negative. Default is 0. | ||||
|  | @ -265,13 +254,3 @@ The decorations are defined as follows: | |||
| This mod does not support adding ores to the caves, as this is a feature that | ||||
| is already well-supported by the Minetest Lua API and doesn't need a mod like | ||||
| this. | ||||
| 
 | ||||
| ## Misc | ||||
| 
 | ||||
| In case you wish to do a few other operations, here's a few other functions | ||||
| that might be helpful to you: | ||||
| 
 | ||||
| - `ns_cavegen.set_world_depth(h)` Set the world's depth to a given number. | ||||
| 
 | ||||
| This feature is currently only supported in VoxeLibre. Contributions that help | ||||
| change the world depth in other games, are very welcome. | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ custom caves into the world and to lower the world depth. | |||
| 
 | ||||
| The mod has been tested on the following games: | ||||
| 
 | ||||
| - [x] MineClone2 | ||||
| - [x] VoxeLibre | ||||
| - [ ] Mineclonia | ||||
| - [ ] MTG | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										4
									
								
								mod.conf
								
								
								
								
							
							
						
						
									
										4
									
								
								mod.conf
								
								
								
								
							|  | @ -2,5 +2,5 @@ name=ns_cavegen | |||
| description=A custom cave generator engine | ||||
| author=Noordstar | ||||
| title=Cave Generator | ||||
| depends=dripstone,mcl_init | ||||
| optional_depends=mcl_init,mcl_worlds | ||||
| depends= | ||||
| optional_depends= | ||||
							
								
								
									
										82
									
								
								script.lua
								
								
								
								
							
							
						
						
									
										82
									
								
								script.lua
								
								
								
								
							|  | @ -8,21 +8,10 @@ local BIOME_SIZE = { x = 250, y = 250, z = 250 } | |||
| -- on a vertical scale, and barely on a horizontal scale. | ||||
| local CONNECTIVITY_BLOB = { x =  250, y =  100, z =  250 } | ||||
| 
 | ||||
| local ENUM_AIR = 1 | ||||
| local ENUM_CEILING = 2 | ||||
| local ENUM_CEILING_DECORATION = 3 | ||||
| local ENUM_FLOOR = 4 | ||||
| local ENUM_FLOOR_DECORATION = 5 | ||||
| local ENUM_STONE = 6 | ||||
| local ENUM_WALL = 7 | ||||
| 
 | ||||
| -- Point that is so out of the normal connectivity/verticality scope (0 - 100) | ||||
| -- that it is only selected when no other items are registered. | ||||
| local OUTLANDISH_POINT = -1e3 | ||||
| 
 | ||||
| -- Average size of each cave shape | ||||
| local SHAPE_SIZE = { x = 128, y = 128, z = 128 } | ||||
| 
 | ||||
| -- Several seeds for mapgen | ||||
| local SEED_CONNECTIVITY   =  297948 | ||||
| local SEED_HEAT           =  320523 | ||||
|  | @ -198,16 +187,26 @@ function internal.clean_shape_def(def) | |||
| 
 | ||||
|     def.y_min = def.y_min or WORLD_MINP.y | ||||
|     def.y_max = def.y_max or WORLD_MAXP.y | ||||
|     def.func = def.func or function(_, n) return n end | ||||
| 
 | ||||
|     assert(type(def.y_min) == "number") | ||||
|     assert(type(def.y_max) == "number") | ||||
|     assert(type(def.func) == "function") | ||||
|     assert(def.noise_params == nil or type(def.noise_params) == "table") | ||||
| 
 | ||||
|     return def | ||||
| end | ||||
| 
 | ||||
| function internal.clear_registered_biomes() | ||||
|     ns_cavegen.registered_biomes = {} | ||||
| end | ||||
| 
 | ||||
| function internal.clear_registered_decorations() | ||||
|     ns_cavegen.registered_decorations = {} | ||||
| end | ||||
| 
 | ||||
| function internal.clear_registered_shapes() | ||||
|     ns_cavegen.registered_shapes = {} | ||||
| end | ||||
| 
 | ||||
| -- Get connectivity noise params | ||||
| function internal.connectivity_noise_params() | ||||
|     local factor = math.max(1, math.abs(#ns_cavegen.registered_shapes) ^ 0.5) | ||||
|  | @ -244,7 +243,6 @@ function internal.default_shape() | |||
|         { name = "ns_cavegen:none" | ||||
|         , connectivity_point = OUTLANDISH_POINT | ||||
|         , verticality_point = OUTLANDISH_POINT | ||||
|         , func = function (pos, v) return 0 end | ||||
|         } | ||||
|     ) | ||||
| end | ||||
|  | @ -257,7 +255,7 @@ function internal.euclidian(x1, x2, y1, y2) | |||
| end | ||||
| 
 | ||||
| -- For each node, determine which cave biome they're in. | ||||
| function internal.find_biome_allocations(heat, humidity) | ||||
| function internal.find_biome_allocations(heat, humidity, va) | ||||
|     assert(#heat == #humidity) | ||||
| 
 | ||||
|     local allocs = {} | ||||
|  | @ -278,10 +276,14 @@ function internal.find_biome_allocations(heat, humidity) | |||
|             ) | ||||
| 
 | ||||
|             if def_d < d then | ||||
|                 local pos = va:position(i) | ||||
| 
 | ||||
|                 if VoxelArea:new(def.min_pos, def.max_pos):contains(pos.x, pos.y, pos.z) then | ||||
|                     d = def_d | ||||
|                     biome_name = name | ||||
|                 end | ||||
|             end | ||||
|         end | ||||
| 
 | ||||
|         allocs[i] = biome_name | ||||
|     end | ||||
|  | @ -290,7 +292,7 @@ function internal.find_biome_allocations(heat, humidity) | |||
| end | ||||
| 
 | ||||
| -- For each node, determine which cave shape they follow. | ||||
| function internal.find_shape_allocations(connectivity, verticality) | ||||
| function internal.find_shape_allocations(connectivity, verticality, va) | ||||
|     assert(#connectivity == #verticality) | ||||
| 
 | ||||
|     local allocs = {} | ||||
|  | @ -311,10 +313,14 @@ function internal.find_shape_allocations(connectivity, verticality) | |||
|             ) | ||||
| 
 | ||||
|             if def_d < d then | ||||
|                 local pos = va:position(i) | ||||
| 
 | ||||
|                 if VoxelArea:new(def.min_pos, def.max_pos):contains(pos.x, pos.y, pos.z) then | ||||
|                     d = def_d | ||||
|                     shape_name = name | ||||
|                 end | ||||
|             end | ||||
|         end | ||||
| 
 | ||||
|         -- Assign the chosen name | ||||
|         allocs[i] = shape_name | ||||
|  | @ -450,8 +456,13 @@ function internal.mapgen(vm, minp, maxp, blockseed) | |||
|     -- bordering nodes in different chunks. | ||||
|     local bminp = vector.offset(minp, -1, -1, -1) | ||||
|     local bmaxp = vector.offset(maxp,  1,  1,  1) | ||||
|     local bva = VoxelArea(bminp, bmaxp) | ||||
| 
 | ||||
|     -- Initiate VoxelArea objects | ||||
|     local va = VoxelArea(vm:get_emerged_area()) | ||||
|     local bva = VoxelArea(bminp, bmaxp) | ||||
|     local sva = VoxelArea(minp, maxp) | ||||
| 
 | ||||
|     -- Set seed | ||||
|     math.randomseed(blockseed) | ||||
| 
 | ||||
|     -- Find cave shape params | ||||
|  | @ -459,7 +470,7 @@ function internal.mapgen(vm, minp, maxp, blockseed) | |||
|     local verticality = internal.generate_verticality_noise(bminp, bmaxp) | ||||
| 
 | ||||
|     -- Draw cave shapes | ||||
|     local used_shapes = internal.find_shape_allocations(connectivity, verticality) | ||||
|     local used_shapes = internal.find_shape_allocations(connectivity, verticality, bva) | ||||
|     internal.find_shape_values(used_shapes, bminp, bmaxp, bva) | ||||
|     internal.shape_to_air(used_shapes, bminp, bmaxp, bva) | ||||
| 
 | ||||
|  | @ -467,28 +478,14 @@ function internal.mapgen(vm, minp, maxp, blockseed) | |||
|     local heat = internal.generate_heat_noise(minp, maxp) | ||||
|     local humidity = internal.generate_humidity_noise(minp, maxp) | ||||
| 
 | ||||
|     -- -- DEBUG: Write to air (or not) | ||||
|     -- local air = 0 | ||||
| 
 | ||||
|     -- for i in small_va:iterp(minp, maxp) do | ||||
|     --     if used_shapes[i] == true then | ||||
|     --         local pos = small_va:position(i) | ||||
|     --         local vmi = va:index(pos.x, pos.y, pos.z) | ||||
|     --         data[vmi] = minetest.CONTENT_AIR | ||||
| 
 | ||||
|     --         air = air + 1 | ||||
|     --     end | ||||
|     -- end | ||||
| 
 | ||||
|     -- Classify various nodes as walls, floors, ceilings | ||||
|     local classified_nodes = internal.classify_nodes(used_shapes, bminp, bmaxp) | ||||
| 
 | ||||
|     -- Draw cave biomes | ||||
|     local used_biomes = internal.find_biome_allocations(heat, humidity) | ||||
|     local used_biomes = internal.find_biome_allocations(heat, humidity, sva) | ||||
| 
 | ||||
|     -- Manipulate `data` table by adding classified nodes based on which biome | ||||
|     -- they're in. | ||||
|     local sva = VoxelArea(minp, maxp) | ||||
|     local data = vm:get_data() | ||||
|     local ground = { [ minetest.CONTENT_AIR ] = false } | ||||
| 
 | ||||
|  | @ -796,6 +793,15 @@ function internal.write_simple_ceiling_decorations(vm_data, va, used_biomes, cla | |||
| 
 | ||||
|     return claimed_spots | ||||
| end | ||||
| 
 | ||||
| function internal.unregister_biome(name) | ||||
|     ns_cavegen.registered_biomes[name] = nil | ||||
| end | ||||
| 
 | ||||
| function internal.unregister_shape(name) | ||||
|     ns_cavegen.registerd_shapes[name] = nil | ||||
| end | ||||
| 
 | ||||
| function internal.write_simple_floor_decorations(vm_data, va, used_biomes, classified_nodes, sva) | ||||
|     local claimed_spots = {} | ||||
| 
 | ||||
|  | @ -870,6 +876,12 @@ ns_cavegen = { | |||
|         return 1 - (math.abs(y - d) / d) | ||||
|     end, | ||||
| 
 | ||||
|     clear_registered_biomes = internal.clear_registered_biomes, | ||||
| 
 | ||||
|     clear_registered_decorations = internal.clear_registered_decorations, | ||||
| 
 | ||||
|     clear_registered_shapes = internal.clear_registered_shapes, | ||||
| 
 | ||||
|     register_biome = internal.register_biome, | ||||
| 
 | ||||
|     register_decoration = internal.register_decoration, | ||||
|  | @ -881,6 +893,10 @@ ns_cavegen = { | |||
|     registered_decorations = {}, | ||||
| 
 | ||||
|     registered_shapes = {}, | ||||
| 
 | ||||
|     unregister_biome = internal.unregister_biome, | ||||
| 
 | ||||
|     unregister_shape = internal.unregister_shape, | ||||
| } | ||||
| 
 | ||||
| -- dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/lua/register.lua") | ||||
		Loading…
	
		Reference in New Issue