Use local function, and change names to use underscores.
Also add biomegen.generate_all that does all the job in one function.master
parent
84a940f457
commit
0cfe913dcb
|
@ -5,7 +5,7 @@ local emptynodes = {
|
||||||
ignore = true,
|
ignore = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function generateDecoSimple(deco, vm, pr, p, ceiling)
|
local function generate_deco_simple(deco, vm, pr, p, ceiling)
|
||||||
local emin, emax = vm:get_emerged_area()
|
local emin, emax = vm:get_emerged_area()
|
||||||
|
|
||||||
local place_offset_y = deco.place_offset_y
|
local place_offset_y = deco.place_offset_y
|
||||||
|
@ -62,7 +62,7 @@ local function get_schematic_size(schem)
|
||||||
return {x=0, y=0, z=0}
|
return {x=0, y=0, z=0}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function generateDecoSchematic(deco, vm, pr, p, ceiling)
|
local function generate_deco_schematic(deco, vm, pr, p, ceiling)
|
||||||
local force_placement = deco.flags.force_placement == true
|
local force_placement = deco.flags.force_placement == true
|
||||||
local direction = ceiling and -1 or 1
|
local direction = ceiling and -1 or 1
|
||||||
if not deco.flags.place_center_y then
|
if not deco.flags.place_center_y then
|
||||||
|
@ -182,7 +182,7 @@ local function make_decolist()
|
||||||
b.param2_max = math.max(a.params2_max or b.param2, b.height)
|
b.param2_max = math.max(a.params2_max or b.param2, b.height)
|
||||||
b.vary_param2 = b.param2 < b.param2_max
|
b.vary_param2 = b.param2 < b.param2_max
|
||||||
b.place_offset_y = a.place_offset_y or 0
|
b.place_offset_y = a.place_offset_y or 0
|
||||||
b.generate = generateDecoSimple
|
b.generate = generate_deco_simple
|
||||||
elseif b.deco_type == "schematic" then
|
elseif b.deco_type == "schematic" then
|
||||||
b.schematic = a.schematic
|
b.schematic = a.schematic
|
||||||
b.replacements = a.replacements or {}
|
b.replacements = a.replacements or {}
|
||||||
|
@ -197,7 +197,7 @@ local function make_decolist()
|
||||||
end
|
end
|
||||||
b.schem_flags = table.concat(schem_flags, ',')
|
b.schem_flags = table.concat(schem_flags, ',')
|
||||||
|
|
||||||
b.generate = generateDecoSchematic
|
b.generate = generate_deco_schematic
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
65
init.lua
65
init.lua
|
@ -1,7 +1,5 @@
|
||||||
-- biomegen/init.lua
|
-- biomegen/init.lua
|
||||||
|
|
||||||
biomegen = {}
|
|
||||||
|
|
||||||
local make_biomelist = dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/biomelist.lua")
|
local make_biomelist = dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/biomelist.lua")
|
||||||
local make_decolist = dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/decorations.lua")
|
local make_decolist = dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/decorations.lua")
|
||||||
|
|
||||||
|
@ -24,7 +22,7 @@ local nvals_humid_blend = {}
|
||||||
|
|
||||||
local water_level = tonumber(minetest.get_mapgen_setting('water_level'))
|
local water_level = tonumber(minetest.get_mapgen_setting('water_level'))
|
||||||
local elevation_chill = 0
|
local elevation_chill = 0
|
||||||
function biomegen.set_elevation_chill(ec)
|
local function set_elevation_chill(ec)
|
||||||
elevation_chill = ec
|
elevation_chill = ec
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -68,7 +66,7 @@ local biomemap = {}
|
||||||
local heatmap = {}
|
local heatmap = {}
|
||||||
local humidmap = {}
|
local humidmap = {}
|
||||||
|
|
||||||
function biomegen.calculateNoises(minp)
|
local function calculate_noises(minp)
|
||||||
local minp2d = {x=minp.x, y=minp.z}
|
local minp2d = {x=minp.x, y=minp.z}
|
||||||
nobj_filler_depth:get_2d_map_flat(minp2d, nvals_filler_depth)
|
nobj_filler_depth:get_2d_map_flat(minp2d, nvals_filler_depth)
|
||||||
|
|
||||||
|
@ -84,13 +82,7 @@ function biomegen.calculateNoises(minp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function biomegen.getBiomeAtIndex(i, pos)
|
local function calc_biome_from_noise(heat, humid, pos)
|
||||||
local heat = heatmap[i] - math.max(pos.y, water_level)*elevation_chill
|
|
||||||
local humid = humidmap[i]
|
|
||||||
return biomegen.calcBiomeFromNoise(heat, humid, pos)
|
|
||||||
end
|
|
||||||
|
|
||||||
function biomegen.calcBiomeFromNoise(heat, humid, pos)
|
|
||||||
local biome_closest = nil
|
local biome_closest = nil
|
||||||
local biome_closest_blend = nil
|
local biome_closest_blend = nil
|
||||||
local dist_min = 31000
|
local dist_min = 31000
|
||||||
|
@ -131,7 +123,13 @@ function biomegen.calcBiomeFromNoise(heat, humid, pos)
|
||||||
return biome_closest
|
return biome_closest
|
||||||
end
|
end
|
||||||
|
|
||||||
function biomegen.generateBiomes(data, a, minp, maxp)
|
local function get_biome_at_index(i, pos)
|
||||||
|
local heat = heatmap[i] - math.max(pos.y, water_level)*elevation_chill
|
||||||
|
local humid = humidmap[i]
|
||||||
|
return calc_biome_from_noise(heat, humid, pos)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function generate_biomes(data, a, minp, maxp)
|
||||||
local chulens = {x=maxp.x-minp.x+1, y=maxp.y-minp.y+1, z=maxp.z-minp.z+1}
|
local chulens = {x=maxp.x-minp.x+1, y=maxp.y-minp.y+1, z=maxp.z-minp.z+1}
|
||||||
|
|
||||||
local index = 1
|
local index = 1
|
||||||
|
@ -140,7 +138,7 @@ function biomegen.generateBiomes(data, a, minp, maxp)
|
||||||
initialize(chulens)
|
initialize(chulens)
|
||||||
end
|
end
|
||||||
|
|
||||||
biomegen.calculateNoises(minp)
|
calculate_noises(minp)
|
||||||
|
|
||||||
for z=minp.z, maxp.z do
|
for z=minp.z, maxp.z do
|
||||||
for x=minp.x, maxp.x do
|
for x=minp.x, maxp.x do
|
||||||
|
@ -180,7 +178,7 @@ function biomegen.generateBiomes(data, a, minp, maxp)
|
||||||
(air_above or not biome or y < biome_y_min)
|
(air_above or not biome or y < biome_y_min)
|
||||||
|
|
||||||
if is_stone_surface or is_water_surface then
|
if is_stone_surface or is_water_surface then
|
||||||
biome = biomegen.getBiomeAtIndex(index, {x=x, y=y, z=z})
|
biome = get_biome_at_index(index, {x=x, y=y, z=z})
|
||||||
biome_stone = biome.node_stone
|
biome_stone = biome.node_stone
|
||||||
|
|
||||||
if not biomemap[index] and is_stone_surface then
|
if not biomemap[index] and is_stone_surface then
|
||||||
|
@ -288,7 +286,7 @@ local liquid = setmetatable({}, {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
local function canPlaceDeco(deco, data, vi, pattern)
|
local function can_place_deco(deco, data, vi, pattern)
|
||||||
if not deco.place_on[data[vi]] then
|
if not deco.place_on[data[vi]] then
|
||||||
return false
|
return false
|
||||||
elseif deco.num_spawn_by <= 0 then
|
elseif deco.num_spawn_by <= 0 then
|
||||||
|
@ -310,7 +308,7 @@ local function canPlaceDeco(deco, data, vi, pattern)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function placeDeco(deco, data, a, vm, minp, maxp, blockseed)
|
local function place_deco(deco, data, a, vm, minp, maxp, blockseed)
|
||||||
local ps = PcgRandom(blockseed + 53)
|
local ps = PcgRandom(blockseed + 53)
|
||||||
local carea_size = maxp.x - minp.x + 1
|
local carea_size = maxp.x - minp.x + 1
|
||||||
|
|
||||||
|
@ -394,7 +392,7 @@ local function placeDeco(deco, data, a, vm, minp, maxp, blockseed)
|
||||||
for _, y in ipairs(floors) do
|
for _, y in ipairs(floors) do
|
||||||
if y >= biome.y_min and y <= biome.y_max then
|
if y >= biome.y_min and y <= biome.y_max then
|
||||||
local pos = {x=x, y=y, z=z}
|
local pos = {x=x, y=y, z=z}
|
||||||
if canPlaceDeco(deco, data, vi, pattern) then
|
if can_place_deco(deco, data, vi, pattern) then
|
||||||
deco:generate(vm, ps, pos, false)
|
deco:generate(vm, ps, pos, false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -405,7 +403,7 @@ local function placeDeco(deco, data, a, vm, minp, maxp, blockseed)
|
||||||
for _, y in ipairs(ceilings) do
|
for _, y in ipairs(ceilings) do
|
||||||
if y >= biome.y_min and y <= biome.y_max then
|
if y >= biome.y_min and y <= biome.y_max then
|
||||||
local pos = {x=x, y=y, z=z}
|
local pos = {x=x, y=y, z=z}
|
||||||
if canPlaceDeco(deco, data, vi, pattern) then
|
if can_place_deco(deco, data, vi, pattern) then
|
||||||
deco:generate(vm, ps, pos, true)
|
deco:generate(vm, ps, pos, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -448,7 +446,7 @@ local function placeDeco(deco, data, a, vm, minp, maxp, blockseed)
|
||||||
|
|
||||||
if biome_ok then
|
if biome_ok then
|
||||||
local pos = {x=x, y=y, z=z}
|
local pos = {x=x, y=y, z=z}
|
||||||
if canPlaceDeco(deco, data, a:index(x,y,z), pattern) then
|
if can_place_deco(deco, data, a:index(x,y,z), pattern) then
|
||||||
deco:generate(vm, ps, pos, false)
|
deco:generate(vm, ps, pos, false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -461,18 +459,18 @@ local function placeDeco(deco, data, a, vm, minp, maxp, blockseed)
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getBlockseed(p, seed)
|
local function get_blockseed(p, seed)
|
||||||
return seed + p.z * 38134234 + p.y * 42123 + p.x * 23
|
return seed + p.z * 38134234 + p.y * 42123 + p.x * 23
|
||||||
end
|
end
|
||||||
|
|
||||||
function biomegen.placeAllDecos(data, a, vm, minp, maxp, seed)
|
local function place_all_decos(data, a, vm, minp, maxp, seed)
|
||||||
local emin = vm:get_emerged_area()
|
local emin = vm:get_emerged_area()
|
||||||
local blockseed = getBlockseed(emin, seed)
|
local blockseed = get_blockseed(emin, seed)
|
||||||
|
|
||||||
local nplaced = 0
|
local nplaced = 0
|
||||||
|
|
||||||
for i, deco in pairs(decos) do
|
for i, deco in pairs(decos) do
|
||||||
nplaced = nplaced + placeDeco(deco, data, a, vm, minp, maxp, blockseed)
|
nplaced = nplaced + place_deco(deco, data, a, vm, minp, maxp, blockseed)
|
||||||
end
|
end
|
||||||
|
|
||||||
return nplaced
|
return nplaced
|
||||||
|
@ -494,7 +492,7 @@ local dustable = setmetatable({}, {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
function biomegen.dustTopNodes(vm, data, a, minp, maxp)
|
local function dust_top_nodes(vm, data, a, minp, maxp)
|
||||||
if maxp.y < water_level then
|
if maxp.y < water_level then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -545,3 +543,22 @@ function biomegen.dustTopNodes(vm, data, a, minp, maxp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
biomegen = {
|
||||||
|
set_elevation_chill = set_elevation_chill,
|
||||||
|
calculate_noises = calculate_noises,
|
||||||
|
get_biome_at_index = get_biome_at_index,
|
||||||
|
calc_biome_from_noise = calc_biome_from_noise,
|
||||||
|
generate_biomes = generate_biomes,
|
||||||
|
place_all_decos = place_all_decos,
|
||||||
|
dust_top_nodes = dust_top_nodes,
|
||||||
|
}
|
||||||
|
|
||||||
|
function biomegen.generate_all(data, a, vm, minp, maxp, seed)
|
||||||
|
generate_biomes(data, a, minp, maxp)
|
||||||
|
vm:set_data(data)
|
||||||
|
place_all_decos(data, a, vm, minp, maxp, seed)
|
||||||
|
minetest.generate_ores(vm, minp, maxp)
|
||||||
|
vm:get_data(data)
|
||||||
|
dust_top_nodes(vm, data, a, minp, maxp)
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue