Make structure generation more deterministic

Pseudorandom now depends on position hash, not on blockseed + structure table order.
This should make structure generation more deterministic.
This commit is contained in:
kno10 2024-08-01 00:27:16 +02:00 committed by kno10
parent b42f883131
commit f9a8033410
1 changed files with 10 additions and 9 deletions

View File

@ -4,6 +4,8 @@ local registered_generators = {}
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
local RANDOM_SEED_OFFSET = 959 -- random constant that should be unique across each library
--
-- Aliases for map generator outputs
--
@ -426,23 +428,22 @@ if mg_name == "v6" then
end
-- This should be moved to mcl_structures eventually if the dependencies can be sorted out.
mcl_mapgen_core.register_generator("structures",nil, function(minp, maxp, blockseed)
mcl_mapgen_core.register_generator("structures", nil, function(minp, maxp, blockseed)
local gennotify = minetest.get_mapgen_object("gennotify")
local has = false
local poshash = minetest.hash_node_position(minp)
for _,struct in pairs(mcl_structures.registered_structures) do
local pr = PseudoRandom(blockseed + 42)
if struct.deco_id then
for _, pos in pairs(gennotify["decoration#"..struct.deco_id] or {}) do
if struct.chunk_probability == nil or (not has and pr:next(1,struct.chunk_probability) == 1 ) then
local pr = PcgRandom(minetest.hash_node_position(pos) + blockseed + RANDOM_SEED_OFFSET)
if struct.chunk_probability == nil or pr:next(1, struct.chunk_probability) == 1 then
mcl_structures.place_structure(vector.offset(pos,0,1,0),struct,pr,blockseed)
has=true
if struct.chunk_probability then break end -- one (attempt) per chunk only
end
end
elseif struct.static_pos then
for _,p in pairs(struct.static_pos) do
if vector.in_area(p,minp,maxp) then
mcl_structures.place_structure(p,struct,pr,blockseed)
local pr = PcgRandom(blockseed + RANDOM_SEED_OFFSET)
for _, pos in pairs(struct.static_pos) do
if vector.in_area(pos, minp, maxp) then
mcl_structures.place_structure(pos, struct, pr, blockseed)
end
end
end