mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-17 08:31:08 +01:00
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:
parent
b42f883131
commit
f9a8033410
1 changed files with 10 additions and 9 deletions
|
@ -4,6 +4,8 @@ local registered_generators = {}
|
||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local modpath = minetest.get_modpath(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
|
-- Aliases for map generator outputs
|
||||||
--
|
--
|
||||||
|
@ -428,21 +430,20 @@ end
|
||||||
-- This should be moved to mcl_structures eventually if the dependencies can be sorted out.
|
-- 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 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
|
for _,struct in pairs(mcl_structures.registered_structures) do
|
||||||
local pr = PseudoRandom(blockseed + 42)
|
|
||||||
if struct.deco_id then
|
if struct.deco_id then
|
||||||
for _, pos in pairs(gennotify["decoration#"..struct.deco_id] or {}) do
|
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)
|
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
|
||||||
end
|
end
|
||||||
elseif struct.static_pos then
|
elseif struct.static_pos then
|
||||||
for _,p in pairs(struct.static_pos) do
|
local pr = PcgRandom(blockseed + RANDOM_SEED_OFFSET)
|
||||||
if vector.in_area(p,minp,maxp) then
|
for _, pos in pairs(struct.static_pos) do
|
||||||
mcl_structures.place_structure(p,struct,pr,blockseed)
|
if vector.in_area(pos, minp, maxp) then
|
||||||
|
mcl_structures.place_structure(pos, struct, pr, blockseed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue