subterrane/functions.lua

41 lines
1.5 KiB
Lua

--subterrane functions.lua
--FUNCTIONS--
function subterrane:vertically_consistent_random(vi, area)
local pos = area:position(vi)
local next_seed = math.random(1, 1000000000)
math.randomseed(pos.x + pos.z * 2 ^ 8)
local output = math.random()
math.randomseed(next_seed)
return output
end
-- Unfortunately there's no easy way to override a single biome, so do it by wiping everything and re-registering
-- Not only that, but the decorations also need to be wiped and re-registered - it appears they keep
-- track of the biome they belong to via an internal ID that gets changed when the biomes
-- are re-registered, resulting in them being left assigned to the wrong biomes.
function subterrane:override_biome(biome_def)
local registered_biomes_copy = {}
for old_biome_key, old_biome_def in pairs(minetest.registered_biomes) do
registered_biomes_copy[old_biome_key] = old_biome_def
end
local registered_decorations_copy = {}
for old_decoration_key, old_decoration_def in pairs(minetest.registered_decorations) do
registered_decorations_copy[old_decoration_key] = old_decoration_def
end
registered_biomes_copy[biome_def.name] = biome_def
minetest.clear_registered_decorations()
minetest.clear_registered_biomes()
for biome_key, new_biome_def in pairs(registered_biomes_copy) do
minetest.register_biome(new_biome_def)
end
for decoration_key, new_decoration_def in pairs(registered_decorations_copy) do
minetest.register_decoration(new_decoration_def)
end
end