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
|
-- 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_min = -31000,
|
||||||
y_max = 31000,
|
y_max = 31000,
|
||||||
-- Lower and upper limits for cave shapes.
|
-- 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"
|
-- Rotation can be "0", "90", "180", "270", or "random"
|
||||||
|
|
||||||
place_offset_y = 0,
|
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'
|
-- Y offset of the schematic base node layer relative to the 'place_on'
|
||||||
-- node.
|
-- node.
|
||||||
-- Can be positive or negative. Default is 0.
|
-- 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
|
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
|
is already well-supported by the Minetest Lua API and doesn't need a mod like
|
||||||
this.
|
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:
|
The mod has been tested on the following games:
|
||||||
|
|
||||||
- [x] MineClone2
|
- [x] VoxeLibre
|
||||||
- [ ] Mineclonia
|
- [ ] Mineclonia
|
||||||
- [ ] MTG
|
- [ ] MTG
|
||||||
|
|
||||||
|
|
4
mod.conf
4
mod.conf
|
@ -2,5 +2,5 @@ name=ns_cavegen
|
||||||
description=A custom cave generator engine
|
description=A custom cave generator engine
|
||||||
author=Noordstar
|
author=Noordstar
|
||||||
title=Cave Generator
|
title=Cave Generator
|
||||||
depends=dripstone,mcl_init
|
depends=
|
||||||
optional_depends=mcl_init,mcl_worlds
|
optional_depends=
|
90
script.lua
90
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.
|
-- on a vertical scale, and barely on a horizontal scale.
|
||||||
local CONNECTIVITY_BLOB = { x = 250, y = 100, z = 250 }
|
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)
|
-- Point that is so out of the normal connectivity/verticality scope (0 - 100)
|
||||||
-- that it is only selected when no other items are registered.
|
-- that it is only selected when no other items are registered.
|
||||||
local OUTLANDISH_POINT = -1e3
|
local OUTLANDISH_POINT = -1e3
|
||||||
|
|
||||||
-- Average size of each cave shape
|
|
||||||
local SHAPE_SIZE = { x = 128, y = 128, z = 128 }
|
|
||||||
|
|
||||||
-- Several seeds for mapgen
|
-- Several seeds for mapgen
|
||||||
local SEED_CONNECTIVITY = 297948
|
local SEED_CONNECTIVITY = 297948
|
||||||
local SEED_HEAT = 320523
|
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_min = def.y_min or WORLD_MINP.y
|
||||||
def.y_max = def.y_max or WORLD_MAXP.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_min) == "number")
|
||||||
assert(type(def.y_max) == "number")
|
assert(type(def.y_max) == "number")
|
||||||
assert(type(def.func) == "function")
|
|
||||||
assert(def.noise_params == nil or type(def.noise_params) == "table")
|
assert(def.noise_params == nil or type(def.noise_params) == "table")
|
||||||
|
|
||||||
return def
|
return def
|
||||||
end
|
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
|
-- Get connectivity noise params
|
||||||
function internal.connectivity_noise_params()
|
function internal.connectivity_noise_params()
|
||||||
local factor = math.max(1, math.abs(#ns_cavegen.registered_shapes) ^ 0.5)
|
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"
|
{ name = "ns_cavegen:none"
|
||||||
, connectivity_point = OUTLANDISH_POINT
|
, connectivity_point = OUTLANDISH_POINT
|
||||||
, verticality_point = OUTLANDISH_POINT
|
, verticality_point = OUTLANDISH_POINT
|
||||||
, func = function (pos, v) return 0 end
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -257,7 +255,7 @@ function internal.euclidian(x1, x2, y1, y2)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- For each node, determine which cave biome they're in.
|
-- 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)
|
assert(#heat == #humidity)
|
||||||
|
|
||||||
local allocs = {}
|
local allocs = {}
|
||||||
|
@ -278,8 +276,12 @@ function internal.find_biome_allocations(heat, humidity)
|
||||||
)
|
)
|
||||||
|
|
||||||
if def_d < d then
|
if def_d < d then
|
||||||
d = def_d
|
local pos = va:position(i)
|
||||||
biome_name = name
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -290,7 +292,7 @@ function internal.find_biome_allocations(heat, humidity)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- For each node, determine which cave shape they follow.
|
-- 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)
|
assert(#connectivity == #verticality)
|
||||||
|
|
||||||
local allocs = {}
|
local allocs = {}
|
||||||
|
@ -311,8 +313,12 @@ function internal.find_shape_allocations(connectivity, verticality)
|
||||||
)
|
)
|
||||||
|
|
||||||
if def_d < d then
|
if def_d < d then
|
||||||
d = def_d
|
local pos = va:position(i)
|
||||||
shape_name = name
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -450,8 +456,13 @@ function internal.mapgen(vm, minp, maxp, blockseed)
|
||||||
-- bordering nodes in different chunks.
|
-- bordering nodes in different chunks.
|
||||||
local bminp = vector.offset(minp, -1, -1, -1)
|
local bminp = vector.offset(minp, -1, -1, -1)
|
||||||
local bmaxp = vector.offset(maxp, 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 va = VoxelArea(vm:get_emerged_area())
|
||||||
|
local bva = VoxelArea(bminp, bmaxp)
|
||||||
|
local sva = VoxelArea(minp, maxp)
|
||||||
|
|
||||||
|
-- Set seed
|
||||||
math.randomseed(blockseed)
|
math.randomseed(blockseed)
|
||||||
|
|
||||||
-- Find cave shape params
|
-- Find cave shape params
|
||||||
|
@ -459,7 +470,7 @@ function internal.mapgen(vm, minp, maxp, blockseed)
|
||||||
local verticality = internal.generate_verticality_noise(bminp, bmaxp)
|
local verticality = internal.generate_verticality_noise(bminp, bmaxp)
|
||||||
|
|
||||||
-- Draw cave shapes
|
-- 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.find_shape_values(used_shapes, bminp, bmaxp, bva)
|
||||||
internal.shape_to_air(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 heat = internal.generate_heat_noise(minp, maxp)
|
||||||
local humidity = internal.generate_humidity_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
|
-- Classify various nodes as walls, floors, ceilings
|
||||||
local classified_nodes = internal.classify_nodes(used_shapes, bminp, bmaxp)
|
local classified_nodes = internal.classify_nodes(used_shapes, bminp, bmaxp)
|
||||||
|
|
||||||
-- Draw cave biomes
|
-- 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
|
-- Manipulate `data` table by adding classified nodes based on which biome
|
||||||
-- they're in.
|
-- they're in.
|
||||||
local sva = VoxelArea(minp, maxp)
|
|
||||||
local data = vm:get_data()
|
local data = vm:get_data()
|
||||||
local ground = { [ minetest.CONTENT_AIR ] = false }
|
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
|
return claimed_spots
|
||||||
end
|
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)
|
function internal.write_simple_floor_decorations(vm_data, va, used_biomes, classified_nodes, sva)
|
||||||
local claimed_spots = {}
|
local claimed_spots = {}
|
||||||
|
|
||||||
|
@ -870,6 +876,12 @@ ns_cavegen = {
|
||||||
return 1 - (math.abs(y - d) / d)
|
return 1 - (math.abs(y - d) / d)
|
||||||
end,
|
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_biome = internal.register_biome,
|
||||||
|
|
||||||
register_decoration = internal.register_decoration,
|
register_decoration = internal.register_decoration,
|
||||||
|
@ -881,6 +893,10 @@ ns_cavegen = {
|
||||||
registered_decorations = {},
|
registered_decorations = {},
|
||||||
|
|
||||||
registered_shapes = {},
|
registered_shapes = {},
|
||||||
|
|
||||||
|
unregister_biome = internal.unregister_biome,
|
||||||
|
|
||||||
|
unregister_shape = internal.unregister_shape,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/lua/register.lua")
|
-- dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/lua/register.lua")
|
Loading…
Reference in New Issue