Aaron Suen 9879a23680 Mapgen determinism
This should cause maps that have the same
seeds to have much more similar results
than before, e.g. sponge deposits will be in
the same places determined by seed and not
random each regeneration of the map.

- Mapgen shared now provides an RNG which
  will be deterministic when feasible, for
  repeatable mapgen results.
- Make existing rng-using mapgen hooks use
  the new deterministic RNG.
- Mapgen shared hooks are also run in
  deterministic order too.
- Tidy up mapgen_shared API a little more.
2020-06-20 23:48:29 -04:00

64 lines
2.1 KiB
Lua

-- LUALOCALS < ---------------------------------------------------------
local math, minetest, nodecore, pairs
= math, minetest, nodecore, pairs
local math_floor
= math.floor
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
minetest.register_ore({
name = "gravel",
ore_type = "blob",
ore = modname .. ":gravel",
wherein = modname .. ":stone",
clust_size = 5,
clust_scarcity = 8 * 8 * 8,
random_factor = 0,
noise_params = {
offset = 0,
scale = 3,
spread = {x = 10, y = 25, z = 10},
seed = 34654,
octaves = 3,
persist = 0.5,
flags = "eased",
},
noise_threshold = 1.2
})
local c_air = minetest.get_content_id("air")
local c_stones = {}
for _, n in pairs(minetest.registered_nodes[modname .. ":stone"].strata) do
c_stones[minetest.get_content_id(n)] = true
end
local function regspring(label, node, rarity)
local c_node = minetest.get_content_id(node)
nodecore.register_mapgen_shared({
label = label,
func = function(minp, maxp, area, data, _, _, _, rng)
local rawqty = rng() * (maxp.x - minp.x + 1)
* (maxp.z - minp.z + 1) * (maxp.y - minp.y + 1) / rarity
local qty = math_floor(rawqty)
if rng() < (rawqty - qty) then qty = qty + 1 end
for _ = 1, qty do
local x = math_floor(rng() * (maxp.x - minp.x + 1)) + minp.x
local y = math_floor(rng() * (maxp.y - minp.y + 1)) + minp.y
local z = math_floor(rng() * (maxp.z - minp.z + 1)) + minp.z
if c_stones[data[area:index(x, y, z)]]
and (x < maxp.x and data[area:index(x + 1, y, z)] == c_air
or x > minp.x and data[area:index(x - 1, y, z)] == c_air
or y < maxp.y and data[area:index(x, y + 1, z)] == c_air
or y > minp.y and data[area:index(x, y - 1, z)] == c_air
or z < maxp.z and data[area:index(x, y, z + 1)] == c_air
or z > minp.z and data[area:index(x, y, z - 1)] == c_air)
then data[area:index(x, y, z)] = c_node end
end
end
})
end
local baserarity = 32 * 32 * 32
regspring("water spring", modname .. ":water_source", baserarity)
regspring("lava spring", modname .. ":lava_source", baserarity * 8)