Generate random Mese strata based on world seed

This commit is contained in:
Wuzzy 2017-09-13 22:50:21 +02:00
parent 66e1abf1dc
commit 15892c6604

@ -1299,7 +1299,6 @@ local function register_biomelike_ores()
-- Mesa strata (registered as sheet ores) -- Mesa strata (registered as sheet ores)
-- Helper function to create strata. -- Helper function to create strata.
-- Available Mesa colors: silver (light grey), brown, orange, red, yellow, white
local stratum = function(y_min, height, color, seed) local stratum = function(y_min, height, color, seed)
if not height then if not height then
height = 1 height = 1
@ -1322,39 +1321,75 @@ local function register_biomelike_ores()
}) })
end end
-- First stratum near the sand level. Always orange.
stratum(11, 3, "orange") stratum(11, 3, "orange")
-- Create strata for up to Y = 256 -- Create random strata for up to Y = 256.
-- This is semi-random based on the mapseed. -- These strata are calculated based on the world seed and are global.
local seed = minetest.get_mapgen_setting("seed") -- They are thus unique per-world.
local i = 0 local mesapr = PcgRandom(minetest.get_mapgen_setting("seed"))
--[[
------ DANGER ZONE! ------
The following code is sensitive to changes; changing any number may break
mapgen consistency when the mapgen generates new mapchunks in existing
worlds because the random generator will yield different results and the strata
suddenly don't match up anymore. ]]
-- Available Mesa colors:
local mesa_stratum_colors = { "silver", "brown", "orange", "red", "yellow", "white" }
-- Start level
local y = 17
-- Generate stratas
repeat repeat
seed = seed + i -- Each stratum has a color (duh!)
local colorid = mesapr:next(1, #mesa_stratum_colors)
stratum(17+i, 1, "orange", seed) -- … and a random thickness
stratum(19+i, 1, "silver", seed) local heightrandom = mesapr:next(1, 12)
stratum(21+i, 1, "brown", seed) local h
stratum(22+i, 1, "red", seed) if heightrandom == 12 then
stratum(24+i, 1, "silver", seed) h = 4
stratum(26+i, 1, "brown", seed) elseif heightrandom >= 10 then
stratum(27+i, 1, "white", seed) h = 3
stratum(29+i, 1, "orange", seed) elseif heightrandom >= 8 then
stratum(34+i, 1, "red", seed) h = 2
stratum(42+i, 1, "orange", seed) else
stratum(44+i, 1, "yellow", seed) h = 1
stratum(46+i, 1, "brown", seed) end
stratum(48+i, 1, "silver", seed) -- Small built-in bias: Only thin strata up to this Y level
stratum(51+i, 1, "white", seed) if y < 45 then
stratum(55+i, 2, "yellow", seed) h = math.min(h, 2)
stratum(58+i, 2, "orange", seed) end
stratum(62+i, 1, "brown", seed)
stratum(68+i, 3, "orange", seed)
stratum(73+i, 2, "brown", seed)
stratum(76+i, 1, "white", seed)
-- Repeat strata above Y=76
i = i + 66 -- Register stratum
until i > 256 stratum(y, h, mesa_stratum_colors[colorid])
-- Skip a random amount of layers (which won't get painted)
local skiprandom = mesapr:next(1, 12)
local skip
if skiprandom == 12 then
skip = 4
elseif skiprandom >= 10 then
skip = 3
elseif skiprandom >= 5 then
skip = 2
elseif skiprandom >= 2 then
skip = 1
else
-- If this happens, the next stratum will touch the previous one without gap
skip = 0
end
-- Get height of next stratum or finish
y = y + h + skip
until y > 256
--[[ END OF DANGER ZONE ]]
end end
-- Non-Overworld ores -- Non-Overworld ores