Use per-chunk probability and 1-octave Perlin noise to simplify spawning temples

This commit is contained in:
kay27 2022-01-17 20:43:30 +04:00
parent 30a0eb1d4a
commit 4e832ba323
5 changed files with 40 additions and 18 deletions

View File

@ -1,6 +1,9 @@
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
local per_chunk_probability = 11
local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level
local node_list = {"mcl_core:sand", "mcl_core:sandstone", "mcl_core:redsand", "mcl_colorblocks:hardened_clay_orange"}
local schematic_file = modpath .. "/schematics/mcl_structures_desert_temple.mts"
@ -144,12 +147,10 @@ mcl_structures.register_structure({
},
},
on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list)
local a = seed % 14
local b = (math.floor(seed / 39) + 4) % 12
if a ~= b then return end
mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100)
local current_noise_level = mcl_structures.perlin_noise:get_3d(minp)
if current_noise_level > -0.3 then return end
local pr = PseudoRandom(seed + 999)
local random_number = pr:next(1, per_chunk_probability)
local noise = mcl_structures_get_perlin_noise_level(minp)
if (random_number + noise) < (per_chunk_probability - 1) then return end
local pos = pos_list[1]
if #pos_list > 1 then
local count = get_place_rank(pos)

View File

@ -17,7 +17,25 @@ local use_process_mapgen_chunk = false
local on_finished_block_callbacks = {}
local on_finished_chunk_callbacks = {}
mcl_structures.perlin_noise = minetest.get_perlin(329, 3, 0.6, 100)
local noise_params = {
offset = 0,
scale = 1,
spread = {
x = mcl_mapgen.CS_NODES,
y = mcl_mapgen.CS_NODES,
z = mcl_mapgen.CS_NODES,
},
seed = 329,
octaves = 1,
persistence = 0.6,
}
local perlin_noise
local get_perlin_noise_level = function(minp)
perlin_noise = perlin_noise or minetest.get_perlin(noise_params)
return perlin_noise:get_3d(minp)
end
mcl_structures.get_perlin_noise_level = get_perlin_noise_level
local spawnstruct_hint = S("Use /help spawnstruct to see a list of avaiable types.")

View File

@ -1,6 +1,9 @@
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
local per_chunk_probability = 8
local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level
local node_list = {"mcl_core:dirt_with_grass", "mcl_core:dirt", "mcl_core:stone", "mcl_core:granite", "mcl_core:gravel", "mcl_core:diorite"}
local schematic_file = modpath .. "/schematics/mcl_structures_jungle_temple.mts"
@ -161,12 +164,10 @@ mcl_structures.register_structure({
},
},
on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list)
local a = seed % 17
local b = (math.ceil(seed / 123) - 4) % 17
if a ~= b then return end
mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100)
local current_noise_level = mcl_structures.perlin_noise:get_3d(maxp)
if current_noise_level < 0.8 then return end
local pr = PseudoRandom(seed + 132)
local random_number = pr:next(1, per_chunk_probability)
local noise = mcl_structures_get_perlin_noise_level(minp)
if (random_number + noise) < (per_chunk_probability - 1) then return end
local pos
local count = -1
for i = 1, #pos_list do

View File

@ -1,5 +1,5 @@
local step = 1
local chunk_borders = true
local chunk_borders = false
local levels = {
[-9] = "black",
@ -26,13 +26,15 @@ local levels = {
local math_min, math_max = math.min, math.max
local math_floor, math_ceil = math.floor, math.ceil
local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level
local noise_offset_x_and_z = math_floor(mcl_mapgen.CS_NODES/2)
mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context)
mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100)
local perlin_noise = mcl_structures.perlin_noise
local y0 = minp.y
for x0 = minp.x, maxp.x, step do
for z0 = minp.z, maxp.z, step do
local current_noise_level = perlin_noise:get_3d({x=x0, y=y0, z=z0})
local current_noise_level = mcl_structures_get_perlin_noise_level({x = x0 - noise_offset_x_and_z, y = y0, z = z0 - noise_offset_x_and_z})
local amount
if current_noise_level < 0 then
amount = math_max(math_ceil(current_noise_level * 9), -9)

View File

@ -6,5 +6,5 @@ if not mcl_mapgen.singlenode then
dofile(modpath .. "/jungle_temple.lua")
dofile(modpath .. "/stronghold.lua")
-- dofile(modpath .. "/noise_indicator.lua")
dofile(modpath .. "/noise_indicator.lua")
end