diff --git a/mods/MAPGEN/mcl_biomes/init.lua b/mods/MAPGEN/mcl_biomes/init.lua index 33111f951..da18c755d 100644 --- a/mods/MAPGEN/mcl_biomes/init.lua +++ b/mods/MAPGEN/mcl_biomes/init.lua @@ -26,11 +26,6 @@ local mod_mcl_crimson = minetest.get_modpath("mcl_crimson") local mod_mcl_blackstone = minetest.get_modpath("mcl_blackstone") local mod_mcl_mangrove = minetest.get_modpath("mcl_mangrove") --- these are registered asynchronously -local deco_ids_fungus = {} -local deco_ids_trees = {} -local deco_id_chorus_plant - -- -- Register biomes -- @@ -3528,6 +3523,36 @@ local function register_coral_decos(ck) }) end +--- Fix light for mushroom lights after generation +local function fix_light_8_gennotify(t, minp, maxp, blockseed) + for _, pos in ipairs(t) do + minetest.fix_light(vector.offset(pos, -8, -8, -8), vector.offset(pos, 8, 8, 8)) + end +end +--- Grow mangrove roots after generation +local swamp_biome_id, swamp_shore_id +local function mangrove_root_gennotify(t, minp, maxp, blockseed) + for _, pos in ipairs(t) do + local nn = minetest.find_nodes_in_area(vector.offset(pos, -8, -1, -8), vector.offset(pos, 8, 0, 8), {"mcl_mangrove:mangrove_roots"}) + if nn and #nn > 0 then + local pr = PcgRandom(blockseed + mg_seed + 38327) + 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(v, 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(v, 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(v, vector.offset(v, 0, -l, 0), {"air"}), {name = "mcl_mangrove:mangrove_roots"}) + end + end + end + end +end + local function register_decorations() -- Coral Reefs for k, _ in pairs(corals) do @@ -3991,11 +4016,8 @@ local function register_decorations() schematic = mod_mcl_mangrove .. "/schematics/mcl_mangrove_tree_1.mts", flags = "place_center_x, place_center_z, force_placement", rotation = "random", - }, function() - local f = minetest.get_decoration_id("mcl_biomes:mangrove_tree_1") - table.insert(deco_ids_trees, f) - minetest.set_gen_notify({decoration = true}, {f}) - end) + gen_callback = mangrove_root_gennotify, + }) mcl_mapgen_core.register_decoration({ name = "mcl_biomes:mangrove_tree_2", deco_type = "schematic", @@ -4008,11 +4030,8 @@ local function register_decorations() schematic = mod_mcl_mangrove .. "/schematics/mcl_mangrove_tree_2.mts", flags = "place_center_x, place_center_z, force_placement", rotation = "random", - }, function() - local f = minetest.get_decoration_id("mcl_biomes:mangrove_tree_2") - table.insert(deco_ids_trees, f) - minetest.set_gen_notify({decoration = true}, {f}) - end) + gen_callback = mangrove_root_gennotify, + }) mcl_mapgen_core.register_decoration({ name = "mcl_biomes:mangrove_tree_3", deco_type = "schematic", @@ -4025,11 +4044,8 @@ local function register_decorations() schematic = mod_mcl_mangrove .. "/schematics/mcl_mangrove_tree_3.mts", flags = "place_center_x, place_center_z, force_placement", rotation = "random", - }, function() - local f = minetest.get_decoration_id("mcl_biomes:mangrove_tree_3") - table.insert(deco_ids_trees, f) - minetest.set_gen_notify({decoration = true}, {f}) - end) + gen_callback = mangrove_root_gennotify, + }) mcl_mapgen_core.register_decoration({ name = "mcl_biomes:mangrove_tree_4", deco_type = "schematic", @@ -4042,11 +4058,8 @@ local function register_decorations() schematic = mod_mcl_mangrove .. "/schematics/mcl_mangrove_tree_4.mts", flags = "place_center_x, place_center_z, force_placement", rotation = "random", - }, function() - local f = minetest.get_decoration_id("mcl_biomes:mangrove_tree_4") - table.insert(deco_ids_trees, f) - minetest.set_gen_notify({decoration = true}, {f}) - end) + gen_callback = mangrove_root_gennotify, + }) mcl_mapgen_core.register_decoration({ name = "mcl_biomes:mangrove_tree_5", deco_type = "schematic", @@ -4059,11 +4072,8 @@ local function register_decorations() schematic = mod_mcl_mangrove .. "/schematics/mcl_mangrove_tree_5.mts", flags = "place_center_x, place_center_z, force_placement", rotation = "random", - }, function() - local f = minetest.get_decoration_id("mcl_biomes:mangrove_tree_5") - table.insert(deco_ids_trees, f) - minetest.set_gen_notify({decoration = true}, {f}) - end) + gen_callback = mangrove_root_gennotify, + }) mcl_mapgen_core.register_decoration({ name = "mcl_biomes:mangrove_bee_nest", deco_type = "schematic", @@ -4086,11 +4096,8 @@ local function register_decorations() rotation = "random", spawn_by = "group:flower", priority = 1550, - }, function() - local f = minetest.get_decoration_id("mcl_biomes:mangrove_bee_nest") - table.insert(deco_ids_trees, f) - minetest.set_gen_notify({decoration = true}, {f}) - end) + gen_callback = mangrove_root_gennotify, + }) mcl_mapgen_core.register_decoration({ deco_type = "simple", place_on = {"mcl_mud:mud"}, @@ -4698,9 +4705,9 @@ local function register_decorations() y_max = mcl_vars.mg_overworld_max, decoration = "mcl_core:cactus", biomes = {"Desert", - "Mesa", "Mesa_sandlevel", - "MesaPlateauF", "MesaPlateauF_sandlevel", - "MesaPlateauFM", "MesaPlateauFM_sandlevel"}, + "Mesa", "Mesa_sandlevel", + "MesaPlateauF", "MesaPlateauF_sandlevel", + "MesaPlateauFM", "MesaPlateauFM_sandlevel"}, height = 1, height_max = 3, spawn_by = "air", @@ -4907,7 +4914,7 @@ local function register_decorations() octaves = 4, persist = 0.6, }, - biomes = {"Jungle", }, + biomes = {"Jungle" }, y_min = 3, y_max = mcl_vars.mg_overworld_max, schematic = mod_mcl_core .. "/schematics/mcl_core_jungle_bush_oak_leaves_2.mts", @@ -5190,30 +5197,6 @@ local function register_decorations() register_seagrass_decoration("seagrass", 0, 0.5, b_seagrass) register_seagrass_decoration("kelp", -0.5, 1, b_kelp) - local b_sponge = {"Plains_deep_ocean", "SunflowerPlains_deep_ocean", "Forest_deep_ocean", "FlowerForest_deep_ocean", "BirchForest_deep_ocean", "BirchForestM_deep_ocean", "RoofedForest_deep_ocean", "Jungle_deep_ocean", "JungleM_deep_ocean", "JungleEdge_deep_ocean", "JungleEdgeM_deep_ocean", "MushroomIsland_deep_ocean", "Desert_deep_ocean", "Savanna_deep_ocean", "SavannaM_deep_ocean", "Mesa_deep_ocean", "MesaBryce_deep_ocean", "MesaPlateauF_deep_ocean", "MesaPlateauFM_deep_ocean"} - -- Wet Sponge - -- TODO: Remove this when we got ocean monuments - mcl_mapgen_core.register_decoration({ - deco_type = "simple", - decoration = "mcl_sponges:sponge_wet", - biomes = b_sponge, - spawn_by = {"group:water"}, - num_spawn_by = 1, - place_on = {"mcl_core:dirt", "mcl_core:sand", "mcl_core:gravel"}, - sidelen = 16, - noise_params = { - offset = 0.00495, - scale = 0.006, - spread = vector.new(250, 250, 250), - seed = 999, - octaves = 3, - persist = 0.666 - }, - flags = "force_placement", - y_min = mcl_vars.mg_lava_overworld_max + 5, - y_max = -20, - }) - -- Place tall grass on snow in Ice Plains and Extreme Hills+ mcl_mapgen_core.register_decoration({ deco_type = "schematic", @@ -5604,11 +5587,8 @@ local function register_dimension_decorations() schematic = mod_mcl_crimson .. "/schematics/warped_fungus_1.mts", size = vector.new(5, 11, 5), rotation = "random", - }, function() - local f = minetest.get_decoration_id("mcl_biomes:warped_tree1") - table.insert(deco_ids_fungus, f) - minetest.set_gen_notify({decoration = true}, {f}) - end) + gen_callback = fix_light_8_gennotify, + }) mcl_mapgen_core.register_decoration({ deco_type = "schematic", name = "mcl_biomes:warped_tree2", @@ -5622,11 +5602,8 @@ local function register_dimension_decorations() schematic = mod_mcl_crimson .. "/schematics/warped_fungus_2.mts", size = vector.new(5, 6, 5), rotation = "random", - }, function() - local f = minetest.get_decoration_id("mcl_biomes:warped_tree2") - table.insert(deco_ids_fungus, f) - minetest.set_gen_notify({decoration = true}, {f}) - end) + gen_callback = fix_light_8_gennotify, + }) mcl_mapgen_core.register_decoration({ deco_type = "schematic", name = "mcl_biomes:warped_tree3", @@ -5640,11 +5617,8 @@ local function register_dimension_decorations() schematic = mod_mcl_crimson .. "/schematics/warped_fungus_3.mts", size = vector.new(5, 12, 5), rotation = "random", - }, function() - local f = minetest.get_decoration_id("mcl_biomes:warped_tree3") - table.insert(deco_ids_fungus, f) - minetest.set_gen_notify({decoration = true}, {f}) - end) + gen_callback = fix_light_8_gennotify, + }) mcl_mapgen_core.register_decoration({ deco_type = "simple", place_on = {"mcl_crimson:warped_nylium", "mcl_crimson:twisting_vines"}, @@ -5703,11 +5677,8 @@ local function register_dimension_decorations() schematic = mod_mcl_crimson .. "/schematics/crimson_fungus_1.mts", size = vector.new(5, 8, 5), rotation = "random", - }, function() - local f = minetest.get_decoration_id("mcl_biomes:crimson_tree1") - table.insert(deco_ids_fungus, f) - minetest.set_gen_notify({decoration = true}, {f}) - end) + gen_callback = fix_light_8_gennotify, + }) minetest.register_alias("mcl_biomes:crimson_tree", "mcl_biomes:crimson_tree1") -- legacy inconsistency, fixed 08/2024 mcl_mapgen_core.register_decoration({ deco_type = "schematic", @@ -5722,11 +5693,8 @@ local function register_dimension_decorations() schematic = mod_mcl_crimson .. "/schematics/crimson_fungus_2.mts", size = vector.new(5, 12, 5), rotation = "random", - }, function() - local f = minetest.get_decoration_id("mcl_biomes:crimson_tree2") - table.insert(deco_ids_fungus, f) - minetest.set_gen_notify({decoration = true}, {f}) - end) + gen_callback = fix_light_8_gennotify, + }) mcl_mapgen_core.register_decoration({ deco_type = "schematic", name = "mcl_biomes:crimson_tree3", @@ -5740,11 +5708,8 @@ local function register_dimension_decorations() schematic = mod_mcl_crimson .. "/schematics/crimson_fungus_3.mts", size = vector.new(7, 13, 7), rotation = "random", - }, function() - local f = minetest.get_decoration_id("mcl_biomes:crimson_tree3") - table.insert(deco_ids_fungus, f) - minetest.set_gen_notify({decoration = true}, {f}) - end) + gen_callback = fix_light_8_gennotify, + }) mcl_mapgen_core.register_decoration({ deco_type = "simple", place_on = {"mcl_crimson:warped_nylium", "mcl_crimson:weeping_vines", "mcl_nether:netherrack"}, @@ -5955,15 +5920,24 @@ local function register_dimension_decorations() decoration = "mcl_end:chorus_flower", height = 1, biomes = {"End", "EndMidlands", "EndHighlands", "EndBarrens", "EndSmallIslands"}, - },function() - deco_id_chorus_plant = minetest.get_decoration_id("mcl_biomes:chorus_plant") - minetest.set_gen_notify({decoration = true}, {deco_id_chorus_plant}) - end) + gen_callback = function(t, minp, maxp, blockseed) + local pr = PcgRandom(blockseed + mg_seed + 99682) + for _, pos in ipairs(t) 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 = vector.new(x, y + 1, 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, + }) -- TODO: End cities end - -- -- Detect mapgen to select functions -- @@ -5991,74 +5965,4 @@ if mg_name ~= "singlenode" then register_dimension_biomes() register_dimension_ores() register_dimension_decorations() - - -- Overworld decorations for v6 are handled in mcl_mapgen_core - 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 = vector.new(x, y + 1, 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 - mcl_mapgen_core.register_generator("chorus_grow", nil, function(minp, maxp, blockseed) - local gennotify = minetest.get_mapgen_object("gennotify") - local pr = PseudoRandom(blockseed + 14) - - if not (maxp.y < mcl_vars.mg_overworld_min or minp.y > mcl_vars.mg_overworld_max) then - local biomemap = minetest.get_mapgen_object("biomemap") - local swamp_biome_id = minetest.get_biome_id("MangroveSwamp") - local swamp_shore_id = minetest.get_biome_id("MangroveSwamp_shore") - if biomemap and (table.indexof(biomemap, swamp_biome_id) ~= -1 or table.indexof(biomemap, swamp_shore_id) ~= -1) then - mangrove_roots_gen(gennotify, pr) - end - end - - if not (maxp.y < mcl_vars.mg_end_min or minp.y > mcl_vars.mg_end_max) then - chorus_gen(gennotify, pr) - end - - if not (maxp.y < mcl_vars.mg_nether_min or minp.y > mcl_vars.mg_nether_max) then - crimson_warped_gen(gennotify) - end - end) - end - end diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index c329c1d3a..55648007b 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -256,7 +256,7 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) -- If it failed again, tough luck! We stick with only 1 chest spawned. local lastRandom local secondChance = true -- second chance is still available - for i=1, totalChests do + for _ = 1, totalChests do local r = pr:next(1, totalChestSlots) if r == lastRandom and secondChance then -- Oops! Same slot selected. Try again. diff --git a/mods/MAPGEN/mcl_mapgen_core/api.lua b/mods/MAPGEN/mcl_mapgen_core/api.lua index 63f5edb8f..cfbf8fa11 100644 --- a/mods/MAPGEN/mcl_mapgen_core/api.lua +++ b/mods/MAPGEN/mcl_mapgen_core/api.lua @@ -4,19 +4,7 @@ local log_timing = minetest.settings:get_bool("mcl_logging_mapgen_timing", false local registered_generators = {} local lvm, nodes, param2 = 0, 0, 0 -local function run_generators(minp, maxp, blockseed) - if nodes == 0 then return end - for _, rec in ipairs(registered_generators) do - if rec.nf then - local gt1 = os.clock() - local p1, p2 = vector.copy(minp), vector.copy(maxp) -- defensive copies - rec.nf(p1, p2, blockseed) - if log_timing then - minetest.log("action", string.format("[mcl_mapgen_core] %-20s %s ... %s %8.2fms", rec.id, minetest.pos_to_string(minp), minetest.pos_to_string(maxp), (os.clock() - gt1)*1000)) - end - end - end -end +local seed = minetest.get_mapgen_setting("seed") minetest.register_on_generated(function(minp, maxp, blockseed) local t1 = os.clock() @@ -62,7 +50,7 @@ minetest.register_on_generated(function(minp, maxp, blockseed) minetest.log("action", string.format("[mcl_mapgen_core] %-20s %s ... %s %8.2fms", "set_data", minetest.pos_to_string(minp), minetest.pos_to_string(maxp), (os.clock() - gt1)*1000)) end local gt1 = os.clock() - if deco_table then + if deco_table and #deco_table > 0 then minetest.generate_decorations(vm,vector.new(minp.x,deco_table.min,minp.z),vector.new(maxp.x,deco_table.max,maxp.z)) elseif deco_used then minetest.generate_decorations(vm) @@ -71,7 +59,7 @@ minetest.register_on_generated(function(minp, maxp, blockseed) minetest.log("action", string.format("[mcl_mapgen_core] %-20s %s ... %s %8.2fms", "decorations", minetest.pos_to_string(minp), minetest.pos_to_string(maxp), (os.clock() - gt1)*1000)) end local gt1 = os.clock() - if ore_table then + if ore_table and #ore_table > 0 then minetest.generate_ores(vm,vector.new(minp.x,ore_table.min,minp.z),vector.new(maxp.x,ore_table.max,maxp.z)) elseif ore_used then minetest.generate_ores(vm) @@ -89,7 +77,18 @@ minetest.register_on_generated(function(minp, maxp, blockseed) end end - run_generators(minp, maxp, blockseed) + if nodes > 0 then + for _, rec in ipairs(registered_generators) do + if rec.nf then + local gt1 = os.clock() + local p1, p2 = vector.copy(minp), vector.copy(maxp) -- defensive copies + rec.nf(p1, p2, blockseed) + if log_timing then + minetest.log("action", string.format("[mcl_mapgen_core] %-20s %s ... %s %8.2fms", rec.id, minetest.pos_to_string(minp), minetest.pos_to_string(maxp), (os.clock() - gt1)*1000)) + end + end + end + end mcl_vars.add_chunk(minp) if logging then @@ -147,15 +146,25 @@ end -- later, because currently decoration blockseeds are incremented sequentially -- c.f., https://github.com/minetest/minetest/issues/14919 local pending_decorations = {} +local gennotify_map = {} function mcl_mapgen_core.register_decoration(def, callback) + def = table.copy(def) -- defensive deep copy, needed for water lily + if def.gen_callback and not def.name then error("gen_callback requires a named decoration.") end + if callback then error("Callbacks have been redesigned.") end if pending_decorations == nil then - minetest.log("warning", "Decoration registered after mapgen: "..tostring(def.name)) + minetest.log("warning", "Decoration registered after mapgen core initialization: "..tostring(def.name)) minetest.register_decoration(def) - if callback ~= nil then callback() end + if def.gen_callback then + def.deco_id = minetest.get_decoration_id(def.name) + if not def.deco_id then + error("Failed to get the decoration id for "..tostring(key)) + else + minetest.set_gen_notify({decoration = true}, {def.deco_id}) + gennotify_map["decoration#" .. def.deco_id] = def + end + end return end - def = table.copy(def) -- defensive deep copy, needed for water lily - def.callback = callback table.insert(pending_decorations, def) end local function sort_decorations() @@ -183,9 +192,38 @@ local function sort_decorations() end table.sort(keys) for _, key in ipairs(keys) do - minetest.register_decoration(map[key]) - if map[key].callback then map[key].callback() end + local def = map[key] + local deco_id = minetest.register_decoration(def) + if not deco_id then + error("Failed to register decoration"..tostring(key)) + end + if def.gen_callback then + deco_id = minetest.get_decoration_id(def.name) + if not deco_id then + error("Failed to get the decoration id for "..tostring(key)) + else + minetest.set_gen_notify({decoration = true}, {deco_id}) + gennotify_map["decoration#" .. deco_id] = def + end + end end pending_decorations = nil -- as we will not run again end + +mcl_mapgen_core.register_generator("Gennotify callbacks", nil, function(minp, maxp, blockseed) + local pr = PcgRandom(blockseed + seed + 48214) -- constant seed offset + local gennotify = minetest.get_mapgen_object("gennotify") + for key, def in pairs(gennotify_map) do + local t = gennotify[key] + if t and #t > 0 then + -- Fisher-Yates shuffle, using pr + for i = 1, #t-1 do + local r = pr:next(i,#t) + t[i], t[r] = t[r], t[i] + end + def.gen_callback(t, minp, maxp, blockseed) + end + end +end) + minetest.register_on_mods_loaded(sort_decorations) diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index b11fc94e3..0f223ad21 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1,6 +1,4 @@ mcl_mapgen_core = {} -local registered_generators = {} - local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) @@ -118,8 +116,6 @@ elseif mg_name == "fractal" then mg_flags.caverns = true end - - local mg_flags_str = "" for k,v in pairs(mg_flags) do if v == false then @@ -211,12 +207,12 @@ end local function set_layers(data, area, content_id, check, min, max, minp, maxp, pr) if maxp.y < min or minp.y > max then return false end local lvm_used = false - if check == nil then + if not check then for p_pos in area:iter(minp.x, math.max(min, minp.y), minp.z, maxp.x, math.min(max, maxp.y), maxp.z) do data[p_pos] = content_id lvm_used = true end - elseif check and type(check) == "function" then + elseif type(check) == "function" then -- slow path, needs vector coordinates (bedrock uses y only) for p_pos in area:iter(minp.x, math.max(min, minp.y), minp.z, maxp.x, math.min(max, maxp.y), maxp.z) do if check(area:position(p_pos), data[p_pos], pr) then @@ -408,6 +404,7 @@ local function end_basic(vm, data, data2, emin, emax, area, minp, maxp, blocksee end end end + lvm_used = true -- light is broken otherwise return lvm_used, false end @@ -416,7 +413,7 @@ mcl_mapgen_core.register_generator("end_fixes", end_basic, nil, 9999, true) if mg_name ~= "v6" and mg_name ~= "singlenode" then mcl_mapgen_core.register_generator("block_fixes_grass", block_fixes_grass, nil, 9999, true) - --mcl_mapgen_core.register_generator("block_fixes_foliage", block_fixes_foliage, nil, 9999, true) + mcl_mapgen_core.register_generator("block_fixes_foliage", block_fixes_foliage, nil, 9999, true) mcl_mapgen_core.register_generator("block_fixes_water", block_fixes_water, nil, 9999, true) mcl_mapgen_core.register_generator("block_fixes_seagrass", block_fixes_seagrass, nil, 9999, true) end @@ -425,6 +422,7 @@ if mg_name == "v6" then dofile(modpath.."/v6.lua") end +--[[ minetest.register_lbm({ label = "Fix grass palette indexes", -- This LBM fixes any incorrect grass palette indexes. name = "mcl_mapgen_core:fix_grass_palette_indexes", @@ -493,7 +491,6 @@ minetest.register_lbm({ end }) ---[[ -- We go outside x and y for where trees are placed next to a biome that has already been generated. -- We go above maxp.y because trees can often get placed close to the top of a generated area and folliage may not -- be coloured correctly. diff --git a/mods/MAPGEN/mcl_mapgen_core/ores.lua b/mods/MAPGEN/mcl_mapgen_core/ores.lua index 3eeaefef8..b5b4e6a05 100644 --- a/mods/MAPGEN/mcl_mapgen_core/ores.lua +++ b/mods/MAPGEN/mcl_mapgen_core/ores.lua @@ -136,7 +136,7 @@ minetest.register_ore({ clust_num_ores = 58, clust_size = 7, y_min = deepslate_min, - y_max = deepslate_max, + y_max = deepslate_max, noise_params = { offset = 0, scale = 1, @@ -450,14 +450,15 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then ore_type = "scatter", ore = "mcl_nether:ancient_debris", wherein = ancient_debris_wherein, - clust_scarcity = 25000, -- 0.004% chance + clust_scarcity = 15000, + -- in MC it's 0.004% chance (~= scarcity 25000) but reports and experiments show that ancient debris is unreasonably hard to find in survival with that value clust_num_ores = 3, clust_size = 3, y_min = mcl_vars.mg_nether_min + 8, y_max = mcl_vars.mg_nether_min + 22, }) - -- Rare spawn (below) + -- Rare spawn (below) minetest.register_ore({ ore_type = "scatter", ore = "mcl_nether:ancient_debris", diff --git a/mods/MAPGEN/mcl_nether_fortresses/init.lua b/mods/MAPGEN/mcl_nether_fortresses/init.lua index c8c3087b7..248d651f0 100644 --- a/mods/MAPGEN/mcl_nether_fortresses/init.lua +++ b/mods/MAPGEN/mcl_nether_fortresses/init.lua @@ -1,7 +1,5 @@ local modname = minetest.get_current_modname() -local S = minetest.get_translator(modname) local modpath = minetest.get_modpath(modname) -local peaceful = minetest.settings:get_bool("only_peaceful_mobs", false) local BLAZE_SPAWNER_MAX_LIGHT = 11 diff --git a/mods/MAPGEN/mcl_strongholds/init.lua b/mods/MAPGEN/mcl_strongholds/init.lua index 028b680b0..2072af476 100644 --- a/mods/MAPGEN/mcl_strongholds/init.lua +++ b/mods/MAPGEN/mcl_strongholds/init.lua @@ -96,9 +96,7 @@ vl_structures.register_structure("end_shrine",{ filenames = { minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_end_portal_room_simple.mts" }, - after_place = function(pos,def,pr,p1,p2,size,rotation) - local p1 = vector.subtract(pos,size) - local p2 = vector.add(pos,size) + after_place = function(pos, def, pr, p1, p2, size, rotation) local spawners = minetest.find_nodes_in_area(p1, p2, "mcl_mobspawners:spawner") for s=1, #spawners do --local meta = minetest.get_meta(spawners[s]) diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua index f00939259..aa38df4fb 100644 --- a/mods/MAPGEN/mcl_structures/desert_temple.lua +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -1,5 +1,4 @@ local modname = minetest.get_current_modname() -local S = minetest.get_translator(modname) local modpath = minetest.get_modpath(modname) local function temple_placement_callback(pos,def,pr,p1,p2) @@ -34,7 +33,7 @@ vl_structures.register_structure("desert_temple",{ flags = "place_center_x, place_center_z", y_offset = -12, prepare = { padding = 3, corners = 3, foundation = true, clear = false }, - chunk_probability = 8, + chunk_probability = 18, y_max = mcl_vars.mg_overworld_max, y_min = 1, biomes = { "Desert" }, diff --git a/mods/MAPGEN/mcl_structures/desert_well.lua b/mods/MAPGEN/mcl_structures/desert_well.lua index 964c891b9..f4d9f65be 100644 --- a/mods/MAPGEN/mcl_structures/desert_well.lua +++ b/mods/MAPGEN/mcl_structures/desert_well.lua @@ -1,5 +1,4 @@ local modname = minetest.get_current_modname() ---local S = minetest.get_translator(modname) local modpath = minetest.get_modpath(modname) vl_structures.register_structure("desert_well",{ diff --git a/mods/MAPGEN/mcl_structures/end_city.lua b/mods/MAPGEN/mcl_structures/end_city.lua index deb805ae8..526f3d478 100644 --- a/mods/MAPGEN/mcl_structures/end_city.lua +++ b/mods/MAPGEN/mcl_structures/end_city.lua @@ -1,5 +1,4 @@ local modname = minetest.get_current_modname() -local S = minetest.get_translator(modname) local modpath = minetest.get_modpath(modname) local spawnon = {"mcl_end:purpur_block"} @@ -8,7 +7,7 @@ local function spawn_shulkers(pos,def,pr,p1,p2) vl_structures.spawn_mobs("mobs_mc:shulker",spawnon,p1,p2,pr,1) local guard = minetest.find_nodes_in_area(p1,p2,{"mcl_itemframes:item_frame"}) if #guard > 0 then - minetest.add_entity(vector.offset(guard[1],0,-1.5,0),"mobs_mc:shulker") + minetest.add_entity(vector.offset(guard[1],0,-1.5,0),"mobs_mc:shulker") -- fixme: MCLA uses -0.5? end end diff --git a/mods/MAPGEN/mcl_structures/end_spawn.lua b/mods/MAPGEN/mcl_structures/end_spawn.lua index 2e4bf34aa..c19b6eba8 100644 --- a/mods/MAPGEN/mcl_structures/end_spawn.lua +++ b/mods/MAPGEN/mcl_structures/end_spawn.lua @@ -1,10 +1,9 @@ local modname = minetest.get_current_modname() -local S = minetest.get_translator(modname) local modpath = minetest.get_modpath(modname) vl_structures.register_structure("end_spawn_obsidian_platform",{ static_pos ={mcl_vars.mg_end_platform_pos}, - place_func = function(pos,def,pr) + place_func = function(pos, _, _) local obby = minetest.find_nodes_in_area(vector.offset(pos,-2,0,-2),vector.offset(pos,2,0,2),{"air","mcl_end:end_stone"}) local air = minetest.find_nodes_in_area(vector.offset(pos,-2,1,-2),vector.offset(pos,2,3,2),{"air","mcl_end:end_stone"}) minetest.bulk_set_node(obby,{name="mcl_core:obsidian"}) @@ -41,7 +40,7 @@ vl_structures.register_structure("end_exit_portal_open",{ filenames = { modpath.."/schematics/mcl_structures_end_exit_portal.mts" }, - after_place = function(pos,def,pr,p1,p2) + after_place = function(pos,def,pr,p1,p2) minetest.fix_light(p1,p2) end }) @@ -101,7 +100,7 @@ vl_structures.register_structure("end_spike",{ local h = d * pr:next(4,6) local p1 = vector.offset(pos, -d / 2, 0, -d / 2) local p2 = vector.offset(pos, d / 2, h + d, d / 2) - minetest.emerge_area(p1, p2, function(blockpos, action, calls_remaining, param) + minetest.emerge_area(p1, p2, function(_, _, calls_remaining) if calls_remaining ~= 0 then return end local s = make_endspike(pos,d,h) minetest.set_node(vector.offset(s,0,1,0),{name="mcl_core:bedrock"}) diff --git a/mods/MAPGEN/mcl_structures/fossil.lua b/mods/MAPGEN/mcl_structures/fossil.lua index 6468a5538..78bc03e1d 100644 --- a/mods/MAPGEN/mcl_structures/fossil.lua +++ b/mods/MAPGEN/mcl_structures/fossil.lua @@ -1,13 +1,12 @@ local modname = minetest.get_current_modname() ---local S = minetest.get_translator(modname) local modpath = minetest.get_modpath(modname) vl_structures.register_structure("fossil",{ place_on = {"group:material_stone","group:sand"}, flags = "place_center_x, place_center_z", prepare = { }, - chunk_probability = 15, -- was 25 - y_offset = function(pr) return pr:next(-16,-32) end, + chunk_probability = 15, -- was 25, FIXME: needs rebalancing + y_offset = function(pr) return pr:next(-32,-16) end, y_max = 15, y_min = mcl_vars.mg_overworld_min + 35, biomes = { "Desert" }, diff --git a/mods/MAPGEN/mcl_structures/geode.lua b/mods/MAPGEN/mcl_structures/geode.lua index 2a162c597..65790099a 100644 --- a/mods/MAPGEN/mcl_structures/geode.lua +++ b/mods/MAPGEN/mcl_structures/geode.lua @@ -14,11 +14,11 @@ local function set_node_no_bedrock(pos, node) return minetest.set_node(pos,node) end -local function makegeode(pos,def,pr) +local function makegeode(pos, _, pr) local size = pr:next(5,7) local p1 = vector.offset(pos,-size,-size,-size) local p2 = vector.offset(pos,size,size,size) - minetest.emerge_area(p1, p2, function(blockpos, action, calls_remaining, param) + minetest.emerge_area(p1, p2, function(_, _, calls_remaining) if calls_remaining ~= 0 then return end local calcite = {} local nn = minetest.find_nodes_in_area(p1,p2,{"group:material_stone","group:dirt","mcl_core:gravel"}) @@ -37,9 +37,9 @@ local function makegeode(pos,def,pr) set_node_no_bedrock(nn[i],{name="mcl_amethyst:amethyst_block"}) end - for k,v in pairs(minetest.find_nodes_in_area(p1,p2,{"mcl_amethyst:amethyst_block"})) do + for _, v in pairs(minetest.find_nodes_in_area(p1,p2,{"mcl_amethyst:amethyst_block"})) do local all_amethyst = true - for kk,vv in pairs(adjacents) do + for _, vv in pairs(adjacents) do local pp = vector.add(v,vv) local an = minetest.get_node(pp) if an.name ~= "mcl_amethyst:amethyst_block" then @@ -58,13 +58,13 @@ local function makegeode(pos,def,pr) if all_amethyst then set_node_no_bedrock(v,{name="air"}) end end - for _,v in pairs(calcite) do - for _,vv in pairs(minetest.find_nodes_in_area(vector.offset(v,-1,-1,-1),vector.offset(v,1,1,1),{"group:material_stone"})) do + for _, v in pairs(calcite) do + for _, vv in pairs(minetest.find_nodes_in_area(vector.offset(v,-1,-1,-1),vector.offset(v,1,1,1),{"group:material_stone"})) do set_node_no_bedrock(vv,{name="mcl_blackstone:basalt_smooth"}) end end - for k,v in pairs(minetest.find_nodes_in_area_under_air(p1,p2,{"mcl_amethyst:amethyst_block","mcl_amethyst:budding_amethyst_block"})) do + for _, v in pairs(minetest.find_nodes_in_area_under_air(p1,p2,{"mcl_amethyst:amethyst_block","mcl_amethyst:budding_amethyst_block"})) do local r = pr:next(1,50) if r < 10 then set_node_no_bedrock(vector.offset(v,0,1,0),{name="mcl_amethyst:amethyst_cluster",param2=1}) diff --git a/mods/MAPGEN/mcl_structures/igloo.lua b/mods/MAPGEN/mcl_structures/igloo.lua index 2ca3e0434..5317f8d83 100644 --- a/mods/MAPGEN/mcl_structures/igloo.lua +++ b/mods/MAPGEN/mcl_structures/igloo.lua @@ -13,9 +13,11 @@ local function spawn_mobs(p1,p2,vi,zv) elseif zv and vi then return end - vi = minetest.add_entity(vector.offset(mc[1],0,1,0),"mobs_mc:villager") - zv = minetest.add_entity(vector.offset(mc[2],0,1,0),"mobs_mc:villager_zombie") - minetest.after(1,spawn_mobs,p1,p2,vi,zv) + vi = minetest.add_entity(vector.offset(vp,0,1,0),"mobs_mc:villager") + zv = minetest.add_entity(vector.offset(zp,0,1,0),"mobs_mc:villager_zombie") + if vi and vi:get_pos() and zv and zv:get_pos() then + minetest.after(1,spawn_mobs,p1,p2,vi,zv) + end end end @@ -78,7 +80,7 @@ local function igloo_callback(cpos,def,pr,p1,p2,size,rotation) vl_structures.place_schematic(bpos, -1, path, rotation, { force_place = true, prepare = { tolerance = -1, foundation = false, clear = false }, - after_place = function(p1, p2) + after_place = function(_, _, pr, p1, p2) -- Generate ladder to basement local ladder = {name="mcl_core:ladder", param2=minetest.dir_to_wallmounted(tdir)} -- TODO: use voxelmanip? diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua index c80d9401c..47f3a12be 100644 --- a/mods/MAPGEN/mcl_structures/jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -22,7 +22,7 @@ vl_structures.register_structure("jungle_temple",{ { itemstring = "mcl_mobitems:bone", weight = 20, amount_min = 4, amount_max=6 }, { itemstring = "mcl_mobitems:rotten_flesh", weight = 16, amount_min = 3, amount_max=7 }, { itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 }, - --{ itemstring = "mcl_bamboo:bamboo", weight = 15, amount_min = 1, amount_max=3 }, --FIXME BAMBOO + { itemstring = "mcl_bamboo:bamboo", weight = 15, amount_min = 1, amount_max=3 }, { itemstring = "mcl_core:iron_ingot", weight = 15, amount_min = 1, amount_max = 5 }, { itemstring = "mcl_core:diamond", weight = 3, amount_min = 1, amount_max = 3 }, { itemstring = "mcl_mobitems:saddle", weight = 3, }, diff --git a/mods/MAPGEN/mcl_structures/ocean_ruins.lua b/mods/MAPGEN/mcl_structures/ocean_ruins.lua index cd22803df..86986c5d6 100644 --- a/mods/MAPGEN/mcl_structures/ocean_ruins.lua +++ b/mods/MAPGEN/mcl_structures/ocean_ruins.lua @@ -1,5 +1,4 @@ local modname = minetest.get_current_modname() -local S = minetest.get_translator(modname) local modpath = minetest.get_modpath(modname) local cold_oceans = { diff --git a/mods/MAPGEN/mcl_structures/ocean_temple.lua b/mods/MAPGEN/mcl_structures/ocean_temple.lua index 85ed872b8..33ec4c56e 100644 --- a/mods/MAPGEN/mcl_structures/ocean_temple.lua +++ b/mods/MAPGEN/mcl_structures/ocean_temple.lua @@ -1,6 +1,5 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) ---local S = minetest.get_translator(modname) local water_level = minetest.get_mapgen_setting("water_level") local spawnon = { "mcl_stairs:slab_prismarine_dark" } @@ -81,7 +80,9 @@ vl_structures.register_structure("ocean_temple",{ persist = 0.001, flags = "absvalue", }, + flags = "force_placement", force_place = true, + prepare = { tolerance = -1, clear = false, foundation = false }, biomes = ocean_biomes, y_max = water_level-4, y_min = mcl_vars.mg_overworld_min, @@ -89,9 +90,8 @@ vl_structures.register_structure("ocean_temple",{ modpath .. "/schematics/mcl_structures_ocean_temple.mts", modpath .. "/schematics/mcl_structures_ocean_temple_2.mts", }, - prepare = { tolerance = -1, clear = false, foundation = false }, y_offset = function(pr) return pr:next(-2,0) end, - after_place = function(p,def,pr,p1,p2) + after_place = function(p, _, pr, p1, p2) vl_structures.spawn_mobs("mobs_mc:guardian",spawnon,p1,p2,pr,5,true) vl_structures.spawn_mobs("mobs_mc:guardian_elder",spawnon,p1,p2,pr,1,true) vl_structures.construct_nodes(p1,p2,{"group:wall"}) diff --git a/mods/MAPGEN/mcl_structures/pillager_outpost.lua b/mods/MAPGEN/mcl_structures/pillager_outpost.lua index 90df3a7f1..732b80d80 100644 --- a/mods/MAPGEN/mcl_structures/pillager_outpost.lua +++ b/mods/MAPGEN/mcl_structures/pillager_outpost.lua @@ -57,7 +57,7 @@ vl_structures.register_structure("pillager_outpost",{ } }} }, - after_place = function(p,def,pr) + after_place = function(p,_,pr) -- fixme: use p1, p2 from the callback? local p1, p2 = vector.offset(p,-9,0,-9), vector.offset(p,9,32,9) vl_structures.spawn_mobs("mobs_mc:pillager",spawnon,p1,p2,pr,5) vl_structures.spawn_mobs("mobs_mc:parrot",{"mesecons_pressureplates:pressure_plate_stone_off"},p1,p2,pr,3) diff --git a/mods/MAPGEN/mcl_structures/ruined_portal.lua b/mods/MAPGEN/mcl_structures/ruined_portal.lua index ce60f1516..697946431 100644 --- a/mods/MAPGEN/mcl_structures/ruined_portal.lua +++ b/mods/MAPGEN/mcl_structures/ruined_portal.lua @@ -4,7 +4,7 @@ local modpath = minetest.get_modpath(modname) local function get_replacements(b,c,pr) local r = {} if not b then return r end - for k,v in pairs(b) do + for _, v in pairs(b) do if pr:next(1,100) < c then table.insert(r,v) end end return r diff --git a/mods/MAPGEN/mcl_structures/shipwrecks.lua b/mods/MAPGEN/mcl_structures/shipwrecks.lua index ea88c99c5..fe6755893 100644 --- a/mods/MAPGEN/mcl_structures/shipwrecks.lua +++ b/mods/MAPGEN/mcl_structures/shipwrecks.lua @@ -1,6 +1,5 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) ---local S = minetest.get_translator(modname) local water_level = minetest.get_mapgen_setting("water_level") --schematics by chmodsayshello @@ -91,6 +90,8 @@ local beach_biomes = { "Jungle_shore" } +-- FIXME: integrate treasure maps from MCLA + vl_structures.register_structure("shipwreck",{ place_on = {"group:sand","mcl_core:gravel"}, spawn_by = {"group:water"}, @@ -127,13 +128,13 @@ vl_structures.register_structure("shipwreck",{ { itemstring = "mcl_core:coal_lump", weight = 6, amount_min = 2, amount_max = 8 }, { itemstring = "mcl_mobitems:rotten_flesh", weight = 5, amount_min = 5, amount_max = 24 }, { itemstring = "mcl_farming:potato_item", weight = 3, amount_min = 1, amount_max = 5 }, - { itemstring = "mcl_armor:helmet_leather_enchanted", weight = 3, func = function(stack, pr) + { itemstring = "mcl_armor:helmet_leather_enchanted", weight = 3, func = function(stack, _) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}) end }, - { itemstring = "mcl_armor:chestplate_leather_enchanted", weight = 3, func = function(stack, pr) + { itemstring = "mcl_armor:chestplate_leather_enchanted", weight = 3, func = function(stack, _) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}) end }, - { itemstring = "mcl_armor:leggings_leather_enchanted", weight = 3, func = function(stack, pr) + { itemstring = "mcl_armor:leggings_leather_enchanted", weight = 3, func = function(stack, _) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}) end }, - { itemstring = "mcl_armor:boots_leather_enchanted", weight = 3, func = function(stack, pr) + { itemstring = "mcl_armor:boots_leather_enchanted", weight = 3, func = function(stack, _) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}) end }, { itemstring = "mcl_bamboo:bamboo", weight = 2, amount_min = 1, amount_max = 3 }, { itemstring = "mcl_farming:pumpkin", weight = 2, amount_min = 1, amount_max = 3 }, diff --git a/mods/MAPGEN/mcl_structures/witch_hut.lua b/mods/MAPGEN/mcl_structures/witch_hut.lua index d81c2edaf..c21401fd9 100644 --- a/mods/MAPGEN/mcl_structures/witch_hut.lua +++ b/mods/MAPGEN/mcl_structures/witch_hut.lua @@ -14,11 +14,14 @@ local function spawn_witch(p1,p2) witch._home = c witch.can_despawn = false end - local cat = minetest.add_entity(vector.offset(nn[math.random(#nn)],0,1,0),"mobs_mc:cat"):get_luaentity() - cat.object:set_properties({textures = {"mobs_mc_cat_black.png"}}) - cat.owner = "!witch!" --so it's not claimable by player - cat._home = c - cat.can_despawn = false + local catobject = minetest.add_entity(vector.offset(nn[math.random(#nn)],0,1,0),"mobs_mc:cat") + if catobject and catobject:get_pos() then + local cat=catobject:get_luaentity() + cat.object:set_properties({textures = {"mobs_mc_cat_black.png"}}) + cat.owner = "!witch!" --so it's not claimable by player + cat._home = c + cat.can_despawn = false + end return end end diff --git a/mods/MAPGEN/mcl_structures/woodland_mansion.lua b/mods/MAPGEN/mcl_structures/woodland_mansion.lua index f68a399e5..3d735eae2 100644 --- a/mods/MAPGEN/mcl_structures/woodland_mansion.lua +++ b/mods/MAPGEN/mcl_structures/woodland_mansion.lua @@ -1,7 +1,5 @@ local modname = minetest.get_current_modname() -local S = minetest.get_translator(modname) local modpath = minetest.get_modpath(modname) -local peaceful = minetest.settings:get_bool("only_peaceful_mobs", false) local spawnon = {"mcl_deepslate:deepslate","mcl_core:birchwood","mcl_wool:red_carpet","mcl_wool:brown_carpet"} diff --git a/mods/MAPGEN/mcl_terrain_features/init.lua b/mods/MAPGEN/mcl_terrain_features/init.lua index 112bbd974..45e38c47f 100644 --- a/mods/MAPGEN/mcl_terrain_features/init.lua +++ b/mods/MAPGEN/mcl_terrain_features/init.lua @@ -10,19 +10,6 @@ local adjacents = { vector.new(0,-1,0) } -local plane_adjacents = { - vector.new(1,0,0), - vector.new(-1,0,0), - vector.new(0,0,1), - vector.new(0,0,-1), -} - -local function set_node_no_bedrock(pos,node) - local n = minetest.get_node(pos) - if n.name == "mcl_core:bedrock" then return end - return minetest.set_node(pos,node) -end - local function airtower(pos,tbl,h) for i=1,h do table.insert(tbl,vector.offset(pos,0,i,0)) @@ -32,7 +19,7 @@ end local function makelake(pos,size,liquid,placein,border,pr,noair) local p1, p2 = vector.offset(pos,-size,-1,-size), vector.offset(pos,size,-1,size) local e1, e2 = vector.offset(pos,-size,-2,-size), vector.offset(pos,size,15,size) - minetest.emerge_area(e1, e2, function(blockpos, action, calls_remaining, param) + minetest.emerge_area(e1, e2, function(_, _, calls_remaining) if calls_remaining ~= 0 then return end local nn = minetest.find_nodes_in_area(p1,p2,placein) if not nn[1] then return end @@ -165,7 +152,6 @@ vl_structures.register_structure("fallen_tree",{ persist = 0.66 }, flags = "place_center_x, place_center_z", - sidelen = 10, solid_ground = true, y_max = mcl_vars.mg_overworld_max, y_min = minetest.get_mapgen_setting("water_level"), @@ -207,7 +193,7 @@ vl_structures.register_structure("water_lake",{ flags = "place_center_x, place_center_z, all_floors", y_max = mcl_vars.mg_overworld_max, y_min = minetest.get_mapgen_setting("water_level"), - place_func = function(pos,def,pr) + place_func = function(pos,_,pr) return makelake(pos,5,"mcl_core:water_source",{"group:material_stone", "group:sand", "group:dirt","group:grass_block"},"mcl_core:dirt_with_grass",pr) end }) @@ -228,7 +214,7 @@ vl_structures.register_structure("water_lake_mangrove_swamp",{ flags = "place_center_x, place_center_z, all_floors", y_max = mcl_vars.mg_overworld_max, y_min = minetest.get_mapgen_setting("water_level"), - place_func = function(pos,def,pr) + place_func = function(pos, _, pr) return makelake(pos,3,"mcl_core:water_source",{"group:material_stone", "group:sand", "group:dirt","group:grass_block","mcl_mud:mud"},"mcl_mud:mud",pr,true) end }) @@ -251,7 +237,7 @@ vl_structures.register_structure("basalt_column",{ y_max = mcl_vars.mg_nether_max - 20, y_min = mcl_vars.mg_lava_nether_max + 1, biomes = { "BasaltDelta" }, - place_func = function(pos,def,pr) + place_func = function(pos, _, pr) local nn = minetest.find_nodes_in_area(vector.offset(pos,-5,-1,-5),vector.offset(pos,5,-1,5),{"air","mcl_blackstone:basalt","mcl_blackstone:blackstone"}) table.sort(nn,function(a, b) return vector.distance(vector.new(pos.x,0,pos.z), a) < vector.distance(vector.new(pos.x,0,pos.z), b) @@ -293,7 +279,7 @@ vl_structures.register_structure("basalt_pillar",{ y_max = mcl_vars.mg_nether_max-40, y_min = mcl_vars.mg_lava_nether_max + 1, biomes = { "BasaltDelta" }, - place_func = function(pos,def,pr) + place_func = function(pos, _, pr) local nn = minetest.find_nodes_in_area(vector.offset(pos,-2,-1,-2),vector.offset(pos,2,-1,2),{"air","mcl_blackstone:basalt","mcl_blackstone:blackstone"}) table.sort(nn,function(a, b) return vector.distance(vector.new(pos.x,0,pos.z), a) < vector.distance(vector.new(pos.x,0,pos.z), b) @@ -337,7 +323,7 @@ vl_structures.register_structure("lavadelta",{ y_max = mcl_vars.mg_nether_max, y_min = mcl_vars.mg_lava_nether_max + 1, biomes = { "BasaltDelta" }, - place_func = function(pos,def,pr) + place_func = function(pos, _, pr) local nn = minetest.find_nodes_in_area_under_air(vector.offset(pos,-10,-1,-10),vector.offset(pos,10,-2,10),{"mcl_blackstone:basalt","mcl_blackstone:blackstone","mcl_nether:netherrack"}) table.sort(nn,function(a, b) return vector.distance(vector.new(pos.x,0,pos.z), a) < vector.distance(vector.new(pos.x,0,pos.z), b) diff --git a/mods/MAPGEN/mcl_villages/buildings.lua b/mods/MAPGEN/mcl_villages/buildings.lua index 5b0d7ef05..08acd7c79 100644 --- a/mods/MAPGEN/mcl_villages/buildings.lua +++ b/mods/MAPGEN/mcl_villages/buildings.lua @@ -241,7 +241,7 @@ function mcl_villages.place_schematics(vm, settlement, blockseed, pr) minp, schematic, rotation, - nil, + { ["mcl_core:dirt_with_grass"]=schematic.surface_mat or "mcl_core:dirt" }, true, { place_center_x = false, place_center_y = false, place_center_z = false } ) @@ -279,6 +279,10 @@ function mcl_villages.place_schematics(vm, settlement, blockseed, pr) local biome_name = minetest.get_biome_name(biome_data.biome) mcl_villages.paths(blockseed, biome_name) + for i, building in ipairs(settlement) do + init_nodes(building.minp, building.maxp, pr) + end + -- this will run delayed actions, such as spawning mobs minetest.set_node(bell_center_pos, { name = "mcl_villages:village_block" }) local meta = minetest.get_meta(bell_center_pos) @@ -287,13 +291,9 @@ function mcl_villages.place_schematics(vm, settlement, blockseed, pr) meta:set_string("infotext", S("The timer for this @1 has not run yet!", bell_center_node_type)) minetest.get_node_timer(bell_center_pos):start(1.0) - for i, building in ipairs(settlement) do - init_nodes(vector.offset(building.minp,-2,-2,-2), vector.offset(building.maxp,2,2,2), pr) - end - - -- read back any changes - local emin, emax = vm:get_emerged_area() - vm:read_from_map(emin, emax) + -- read back any changes (fixme: would be better if we would not need this often. + --local emin, emax = vm:get_emerged_area() + --vm:read_from_map(emin, emax) end function mcl_villages.post_process_village(blockseed) diff --git a/mods/MAPGEN/mcl_villages/init.lua b/mods/MAPGEN/mcl_villages/init.lua index d3a8e0bd5..3e940a290 100644 --- a/mods/MAPGEN/mcl_villages/init.lua +++ b/mods/MAPGEN/mcl_villages/init.lua @@ -22,12 +22,12 @@ minetest.register_node("mcl_villages:structblock", {drawtype="airlike",groups = local function build_a_settlement(minp, maxp, blockseed) if mcl_villages.village_exists(blockseed) then return end local pr = PcgRandom(blockseed) - local lvm = VoxelManip(minp, maxp) - local settlement = mcl_villages.create_site_plan(lvm, minp, maxp, pr) + local vm = VoxelManip(minp, maxp) + local settlement = mcl_villages.create_site_plan(vm, minp, maxp, pr) if not settlement then return false, false end -- all foundations first, then all buildings, to avoid damaging very close buildings - mcl_villages.terraform(lvm, settlement, pr) - mcl_villages.place_schematics(lvm, settlement, blockseed, pr) + mcl_villages.terraform(vm, settlement, pr) + mcl_villages.place_schematics(vm, settlement, blockseed, pr) mcl_villages.add_village(blockseed, settlement) --lvm:write_to_map(true) -- destory paths as of now --mcl_villages.paths(blockseed) -- TODO: biome @@ -110,7 +110,7 @@ minetest.register_node("mcl_villages:village_block", { -- Somethings don't work reliably when done in the map building -- so we use a timer to run them later when they work more reliably -- e.g. spawning mobs, running minetest.find_path - on_timer = function(pos, elapsed) + on_timer = function(pos, _) local meta = minetest.get_meta(pos) local blockseed = meta:get_string("blockseed") local node_type = meta:get_string("node_type") @@ -283,14 +283,26 @@ mcl_villages.register_building({ }) mcl_villages.register_building({ - name = "fletcher", + name = "fletcher_tiny", + group = "g:fletcher", mts = schem_path .. "bogner.mts", num_others = 8, + max_jobs = 6, yadjust = 0, }) +mcl_villages.register_building({ + name = "fletcher", + group = "g:fletcher", + mts = schem_path .. "new_villages/fletcher.mts", + num_others = 8, + min_jobs = 7, + yadjust = 1, +}) + mcl_villages.register_building({ name = "library", + group = "g:library", mts = schem_path .. "new_villages/library.mts", min_jobs = 12, max_jobs = 99, @@ -300,6 +312,7 @@ mcl_villages.register_building({ mcl_villages.register_building({ name = "librarian", + group = "g:library", mts = schem_path .. "schreiber.mts", min_jobs = 1, max_jobs = 11, @@ -350,6 +363,7 @@ mcl_villages.register_building({ mcl_villages.register_building({ name = "chapel", + group = "g:church", mts = schem_path .. "new_villages/chapel.mts", num_others = 8, min_jobs = 1, @@ -358,14 +372,25 @@ mcl_villages.register_building({ }) mcl_villages.register_building({ - name = "church", + name = "church_european", + group = "g:church", mts = schem_path .. "kirche.mts", num_others = 20, - min_jobs = 10, + min_jobs = 8, max_jobs = 99, yadjust = 0, }) +mcl_villages.register_building({ + name = "church", + group = "g:church", + mts = schem_path .. "new_villages/church.mts", + num_others = 20, + min_jobs = 8, + max_jobs = 99, + yadjust = 1, +}) + mcl_villages.register_building({ name = "farm_small", mts = schem_path .. "new_villages/farm_small_1.mts", diff --git a/mods/MAPGEN/vl_structures/api.lua b/mods/MAPGEN/vl_structures/api.lua index 919c2250e..c3e04c64b 100644 --- a/mods/MAPGEN/vl_structures/api.lua +++ b/mods/MAPGEN/vl_structures/api.lua @@ -128,8 +128,8 @@ function vl_structures.place_structure(pos, def, pr, blockseed, rot) end end -local EMPTY_SCHEMATIC = { size = {x = 1, y = 1, z = 1}, data = { { name = "ignore" } } } --- local EMPTY_SCHEMATIC = { size = {x = 0, y = 0, z = 0}, data = { } } +-- local EMPTY_SCHEMATIC = { size = {x = 1, y = 1, z = 1}, data = { { name = "ignore" } } } +local EMPTY_SCHEMATIC = { size = {x = 0, y = 0, z = 0}, data = { } } --- Register a structure -- @param name string: Structure name @@ -142,6 +142,7 @@ function vl_structures.register_structure(name,def) if not def.noise_params and def.chunk_probability and not def.fill_ratio then def.fill_ratio = 1.1/80/80 -- 1 per chunk, controlled by chunk probability only end + def.flags = def.flags or vl_structures.DEFAULT_FLAGS if def.filenames then for _, filename in ipairs(def.filenames) do if not mcl_util.file_exists(filename) then @@ -153,7 +154,7 @@ function vl_structures.register_structure(name,def) if def.place_on then minetest.register_on_mods_loaded(function() def.deco = mcl_mapgen_core.register_decoration({ - name = "vl_structures:deco_"..name, + name = "vl_structures:"..name, priority = def.priority or (def.terrain_feature and 900) or 100, -- run before regular decorations deco_type = "schematic", schematic = EMPTY_SCHEMATIC, -- use gennotify only @@ -166,29 +167,26 @@ function vl_structures.register_structure(name,def) flags = def.flags, biomes = def.biomes, y_max = def.y_max, - y_min = def.y_min - }, function() -- callback when mcl_mapgen_core has reordered the decoration calls - def.deco_id = minetest.get_decoration_id("vl_structures:deco_"..name) - minetest.set_gen_notify({decoration=true}, { def.deco_id }) - end) + y_min = def.y_min, + gen_callback = function(t,minp,maxp,blockseed) + for _, pos in ipairs(t) do + local pr = PcgRandom(minetest.hash_node_position(pos) + worldseed + RANDOM_SEED_OFFSET) + if def.chunk_probability == nil or pr:next(0, 1e9) * 1e-9 * def.chunk_probability <= structure_boost then + vl_structures.place_structure(vector_offset(pos, 0, 1, 0), def, pr, blockseed) + if def.chunk_probability ~= nil then break end -- allow only one per gennotify, e.g., on multiple surfaces + end + end + end + }) end) end end -- To avoid a cyclic dependency, run this when modules have finished loading minetest.register_on_mods_loaded(function() -mcl_mapgen_core.register_generator("structures", nil, function(minp, maxp, blockseed) - local gennotify = minetest.get_mapgen_object("gennotify") +mcl_mapgen_core.register_generator("static structures", nil, function(minp, maxp, blockseed) for _,struct in pairs(vl_structures.registered_structures) do - if struct.deco_id then - for _, pos in pairs(gennotify["decoration#"..struct.deco_id] or {}) do - local pr = PcgRandom(minetest.hash_node_position(pos) + worldseed + RANDOM_SEED_OFFSET) - if struct.chunk_probability == nil or pr:next(0, 1e9) * 1e-9 * struct.chunk_probability <= structure_boost then - vl_structures.place_structure(vector_offset(pos, 0, 1, 0), struct, pr, blockseed) - if struct.chunk_probability ~= nil then break end -- allow only one per gennotify, e.g., on multiple surfaces - end - end - elseif struct.static_pos then + if struct.static_pos then local pr -- initialize only when needed below for _, pos in pairs(struct.static_pos) do if vector.in_area(pos, minp, maxp) then diff --git a/mods/MAPGEN/vl_structures/commands.lua b/mods/MAPGEN/vl_structures/commands.lua index f83529c06..ffae8db4a 100644 --- a/mods/MAPGEN/vl_structures/commands.lua +++ b/mods/MAPGEN/vl_structures/commands.lua @@ -4,7 +4,7 @@ local modpath = minetest.get_modpath(modname) --- /spawnstruct chat command minetest.register_chatcommand("spawnstruct", { - params = mcl_dungeons and "dungeon" or "", + params = "", description = S("Generate a pre-defined structure near your position."), privs = {debug = true}, func = function(name, param) @@ -35,7 +35,7 @@ minetest.register_chatcommand("spawnstruct", { end }) minetest.register_on_mods_loaded(function() - local p = minetest.registered_chatcommands["spawnstruct"].params + local p = _G["mcl_dungeons"] and "dungeon" or "" for n,_ in pairs(vl_structures.registered_structures) do p = (p ~= "" and (p.." | ") or "")..n end