1
0
Fork 0

Mapgen optimisations

This commit is contained in:
ancientmarinerdev 2023-03-30 01:46:29 +01:00 committed by Gitea
parent 4205915a0b
commit 0abc0ffc48
2 changed files with 84 additions and 45 deletions

View File

@ -6066,50 +6066,82 @@ if mg_name ~= "singlenode" then
for _, f in pairs(deco_ids_trees) do for _, f in pairs(deco_ids_trees) do
minetest.set_gen_notify({decoration = true}, {f}) minetest.set_gen_notify({decoration = true}, {f})
end end
local function mangrove_roots_gen(gennotify, pr)
for _, f in pairs(deco_ids_trees) do
for _, pos in ipairs(gennotify["decoration#" .. f] or {}) do
local nn = minetest.find_nodes_in_area(vector.offset(pos, -8, -1, -8), vector.offset(pos, 8, 0, 8), {"mcl_mangrove:mangrove_roots"})
for _, v in pairs(nn) do
local l = pr:next(2, 16)
local n = minetest.get_node(vector.offset(v, 0, -1, 0)).name
if minetest.get_item_group(n, "water") > 0 then
local wl = "mcl_mangrove:water_logged_roots"
if n:find("river") then
wl = "mcl_mangrove:river_water_logged_roots"
end
minetest.bulk_set_node(minetest.find_nodes_in_area(vector.offset(v, 0, 0, 0), vector.offset(v, 0, -l, 0), {"group:water"}), {name = wl})
elseif n == "mcl_mud:mud" then
minetest.bulk_set_node(minetest.find_nodes_in_area(vector.offset(v, 0, 0, 0), vector.offset(v, 0, -l, 0), {"mcl_mud:mud"}), {name = "mcl_mangrove:mangrove_mud_roots"})
elseif n == "air" then
minetest.bulk_set_node(minetest.find_nodes_in_area(vector.offset(v, 0, 0, 0), vector.offset(v, 0, -l, 0), {"air"}), {name = "mcl_mangrove:mangrove_roots"})
end
end
end
end
end
local function chorus_gen (gennotify, pr)
for _, pos in ipairs(gennotify["decoration#" .. deco_id_chorus_plant] or {}) do
local x, y, z = pos.x, pos.y, pos.z
if x < -10 or x > 10 or z < -10 or z > 10 then
local realpos = {x = x, y = y + 1, z = z}
local node = minetest.get_node(realpos)
if node and node.name == "mcl_end:chorus_flower" then
mcl_end.grow_chorus_plant(realpos, node, pr)
end
end
end
end
local function crimson_warped_gen(gennotify)
for _, f in pairs(deco_ids_fungus) do
for _, pos in ipairs(gennotify["decoration#" .. f] or {}) do
minetest.fix_light(vector.offset(pos, -8, -8, -8), vector.offset(pos, 8, 8, 8))
end
end
end
if deco_id_chorus_plant or deco_ids_fungus or deco_ids_trees then if deco_id_chorus_plant or deco_ids_fungus or deco_ids_trees then
mcl_mapgen_core.register_generator("chorus_grow", nil, function(minp, maxp, blockseed) mcl_mapgen_core.register_generator("chorus_grow", nil, function(minp, maxp, blockseed)
local gennotify = minetest.get_mapgen_object("gennotify") local gennotify = minetest.get_mapgen_object("gennotify")
local pr = PseudoRandom(blockseed + 14) local pr = PseudoRandom(blockseed + 14)
for _, f in pairs(deco_ids_trees) do
for _, pos in ipairs(gennotify["decoration#" .. f] or {}) do if not (maxp.y < mcl_vars.mg_overworld_min or minp.y > mcl_vars.mg_overworld_max) then
local nn = minetest.find_nodes_in_area(vector.offset(pos, -8, -1, -8), vector.offset(pos, 8, 0, 8), {"mcl_mangrove:mangrove_roots"}) local biomemap = minetest.get_mapgen_object("biomemap")
for _, v in pairs(nn) do --minetest.log("mangrove stuff: " .. dump(biomemap))
local l = pr:next(2, 16) local swamp_biome_id = minetest.get_biome_id("MangroveSwamp")
local n = minetest.get_node(vector.offset(v, 0, -1, 0)).name local swamp_shore_id = minetest.get_biome_id("MangroveSwamp_shore")
if minetest.get_item_group(n, "water") > 0 then local is_swamp = table.indexof(biomemap, swamp_biome_id) ~= -1
local wl = "mcl_mangrove:water_logged_roots" local is_swamp_shore = table.indexof(biomemap, swamp_shore_id) ~= -1
if n:find("river") then
wl = "mcl_mangrove:river_water_logged_roots" if is_swamp or is_swamp_shore then
end --minetest.log("Mangrove swamp biomes...")
minetest.bulk_set_node(minetest.find_nodes_in_area(vector.offset(v, 0, 0, 0), vector.offset(v, 0, -l, 0), {"group:water"}), {name = wl}) --minetest.log("is_swamp: " .. dump(is_swamp))
elseif n == "mcl_mud:mud" then --minetest.log("is_swamp_shore: " .. dump(is_swamp_shore))
minetest.bulk_set_node(minetest.find_nodes_in_area(vector.offset(v, 0, 0, 0), vector.offset(v, 0, -l, 0), {"mcl_mud:mud"}), {name = "mcl_mangrove:mangrove_mud_roots"}) mangrove_roots_gen(gennotify, pr)
elseif n == "air" then else
minetest.bulk_set_node(minetest.find_nodes_in_area(vector.offset(v, 0, 0, 0), vector.offset(v, 0, -l, 0), {"air"}), {name = "mcl_mangrove:mangrove_roots"}) --minetest.log("is not mangrove swamp biomes...")
end
end
end end
end end
if minp.y > -26900 then
return if not (maxp.y < mcl_vars.mg_end_min or minp.y > mcl_vars.mg_end_max) then
--minetest.log("chorus stuff")
chorus_gen(gennotify, pr)
end end
for _, pos in ipairs(gennotify["decoration#" .. deco_id_chorus_plant] or {}) do
local x, y, z = pos.x, pos.y, pos.z if not (maxp.y < mcl_vars.mg_nether_min or minp.y > mcl_vars.mg_nether_max) then
if x < -10 or x > 10 or z < -10 or z > 10 then --minetest.log("nether stuff")
local realpos = {x = x, y = y + 1, z = z} crimson_warped_gen(gennotify)
local node = minetest.get_node(realpos)
if node and node.name == "mcl_end:chorus_flower" then
mcl_end.grow_chorus_plant(realpos, node, pr)
end
end
end
if minp.y > mcl_vars.mg_nether_max then
return
end
for _, f in pairs(deco_ids_fungus) do
for _, pos in ipairs(gennotify["decoration#" .. f] or {}) do
minetest.fix_light(vector.offset(pos, -8, -8, -8), vector.offset(pos, 8, 8, 8))
end
end end
end) end)
end end

View File

@ -346,14 +346,21 @@ local function world_structure(vm, data, data2, emin, emax, area, minp, maxp, bl
end end
local function block_fixes_grass(vm, data, data2, emin, emax, area, minp, maxp, blockseed) local function block_fixes_grass(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
local biomemap = minetest.get_mapgen_object("biomemap") if maxp.y < mcl_vars.mg_overworld_min then
local lvm_used = false --minetest.log("Exit grass fix")
local pr = PseudoRandom(blockseed) return
if minp.y <= mcl_vars.mg_overworld_max and maxp.y >= mcl_vars.mg_overworld_min then else
-- Set param2 (=color) of nodes which use the grass colour palette. --minetest.log("Grass fixes")
lvm_used = set_grass_palette(minp,maxp,data2,area,biomemap,{"group:grass_palette"}) end
end
return lvm_used local biomemap = minetest.get_mapgen_object("biomemap")
local lvm_used = false
if minp.y <= mcl_vars.mg_overworld_max and maxp.y >= mcl_vars.mg_overworld_min then
-- Set param2 (=color) of nodes which use the grass colour palette.
lvm_used = set_grass_palette(minp,maxp,data2,area,biomemap,{"group:grass_palette"})
end
return lvm_used
end end