2019-02-23 22:48:39 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2020-06-28 21:06:00 -04:00
|
|
|
local VoxelArea, ipairs, math, minetest, nodecore, table
|
|
|
|
= VoxelArea, ipairs, math, minetest, nodecore, table
|
|
|
|
local math_floor, table_insert
|
|
|
|
= math.floor, table.insert
|
2019-02-23 22:48:39 -05:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
2019-02-24 10:19:22 -05:00
|
|
|
local mapgens = {}
|
|
|
|
nodecore.registered_mapgen_shared = mapgens
|
|
|
|
|
2020-06-20 23:48:29 -04:00
|
|
|
local singlenode = minetest.get_mapgen_setting("mg_name") == "singlenode"
|
|
|
|
|
|
|
|
local counters = {}
|
2020-01-12 10:30:02 -05:00
|
|
|
function nodecore.register_mapgen_shared(def)
|
2020-06-20 23:48:29 -04:00
|
|
|
local label = def.label
|
|
|
|
if not label then
|
|
|
|
label = minetest.get_current_modname()
|
|
|
|
local i = (counters[label] or 0) + 1
|
|
|
|
counters[label] = i
|
|
|
|
label = label .. ":" .. i
|
2020-01-12 11:01:30 -05:00
|
|
|
end
|
2019-02-24 10:19:22 -05:00
|
|
|
|
2020-01-12 10:30:02 -05:00
|
|
|
local prio = def.priority or 0
|
|
|
|
def.priority = prio
|
2019-02-24 10:19:22 -05:00
|
|
|
local min = 1
|
|
|
|
local max = #mapgens + 1
|
|
|
|
while max > min do
|
|
|
|
local try = math_floor((min + max) / 2)
|
2020-01-12 10:30:02 -05:00
|
|
|
local oldp = mapgens[try].priority
|
2020-06-20 23:48:29 -04:00
|
|
|
if (prio < oldp) or (prio == oldp and label > mapgens[try].label) then
|
2019-02-24 10:19:22 -05:00
|
|
|
min = try + 1
|
|
|
|
else
|
|
|
|
max = try
|
|
|
|
end
|
|
|
|
end
|
2020-01-12 10:30:02 -05:00
|
|
|
table_insert(mapgens, min, def)
|
2019-02-24 10:19:22 -05:00
|
|
|
end
|
2019-02-23 22:48:39 -05:00
|
|
|
|
2020-06-20 23:48:29 -04:00
|
|
|
local mapperlin
|
|
|
|
minetest.after(0, function() mapperlin = minetest.get_perlin(0, 1, 0, 1) end)
|
2020-01-12 11:01:30 -05:00
|
|
|
|
2020-06-15 07:21:39 -04:00
|
|
|
nodecore.register_on_generated("mapgen shared", function(minp, maxp)
|
2019-02-23 22:48:39 -05:00
|
|
|
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
|
|
|
local data = vm:get_data()
|
2019-08-27 19:14:51 -04:00
|
|
|
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
2019-02-23 22:48:39 -05:00
|
|
|
|
2020-06-28 21:06:00 -04:00
|
|
|
local rng = nodecore.seeded_rng(mapperlin:get_3d(minp))
|
2020-06-20 23:48:29 -04:00
|
|
|
|
2020-01-12 11:01:30 -05:00
|
|
|
for _, def in ipairs(mapgens) do
|
|
|
|
local en = def.enabled
|
|
|
|
if en == nil then en = not singlenode end
|
|
|
|
if en then
|
2020-06-20 23:48:29 -04:00
|
|
|
def.func(minp, maxp, area, data, vm, emin, emax, rng)
|
2020-01-12 11:01:30 -05:00
|
|
|
end
|
2019-02-23 22:48:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
vm:set_data(data)
|
|
|
|
vm:write_to_map()
|
|
|
|
end)
|