From 899c8499968f6df518311387ca2d677c249d7942 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 6 Jun 2022 01:46:32 +0200 Subject: [PATCH 01/12] old registered_structures -> structure_data --- mods/ITEMS/mcl_end/eye_of_ender.lua | 2 +- mods/MAPGEN/mcl_strongholds/init.lua | 2 +- mods/MAPGEN/mcl_structures/init.lua | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mods/ITEMS/mcl_end/eye_of_ender.lua b/mods/ITEMS/mcl_end/eye_of_ender.lua index ea3d70aba2..bc697e3598 100644 --- a/mods/ITEMS/mcl_end/eye_of_ender.lua +++ b/mods/ITEMS/mcl_end/eye_of_ender.lua @@ -87,7 +87,7 @@ minetest.register_craftitem("mcl_end:ender_eye", { end local origin = user:get_pos() origin.y = origin.y + 1.5 - local strongholds = mcl_structures.get_registered_structures("stronghold") + local strongholds = mcl_structures.get_structure_data("stronghold") local dim = mcl_worlds.pos_to_dimension(origin) local is_creative = minetest.is_creative_enabled(user:get_player_name()) diff --git a/mods/MAPGEN/mcl_strongholds/init.lua b/mods/MAPGEN/mcl_strongholds/init.lua index 083172a3cb..2a362cc404 100644 --- a/mods/MAPGEN/mcl_strongholds/init.lua +++ b/mods/MAPGEN/mcl_strongholds/init.lua @@ -61,7 +61,7 @@ local function init_strongholds() end end - mcl_structures.register_structures("stronghold", table.copy(strongholds)) + mcl_structures.register_structure_data("stronghold", table.copy(strongholds)) strongholds_inited = true end diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 5d3ecac6c2..e330e2c013 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -530,7 +530,7 @@ function mcl_structures.generate_desert_temple(pos, rotation, pr) mcl_structures.place_schematic(newpos, path, rotation or "random", nil, true, nil, temple_placement_callback, pr) end -local registered_structures = {} +local structure_data = {} --[[ Returns a table of structure of the specified type. Currently the only valid parameter is "stronghold". @@ -543,18 +543,18 @@ Format of return value: TODO: Implement this function for all other structure types as well. ]] -function mcl_structures.get_registered_structures(structure_type) - if registered_structures[structure_type] then - return table.copy(registered_structures[structure_type]) +function mcl_structures.get_structure_data(structure_type) + if structure_data[structure_type] then + return table.copy(structure_data[structure_type]) else return {} end end -- Register a structures table for the given type. The table format is the same as for --- mcl_structures.get_registered_structures. -function mcl_structures.register_structures(structure_type, structures) - registered_structures[structure_type] = structures +-- mcl_structures.get_structure_data. +function mcl_structures.register_structure_data(structure_type, structures) + structure_data[structure_type] = structures end local function dir_to_rotation(dir) From 6406a147382c66e1c46bd1a374fa26e45d3c0fc0 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 6 Jun 2022 03:34:31 +0200 Subject: [PATCH 02/12] Add Structure placement api --- mods/MAPGEN/mcl_shipwrecks/init.lua | 146 +++++++++++++++++----------- mods/MAPGEN/mcl_structures/api.lua | 69 +++++++++++++ mods/MAPGEN/mcl_structures/init.lua | 2 + 3 files changed, 162 insertions(+), 55 deletions(-) create mode 100644 mods/MAPGEN/mcl_structures/api.lua diff --git a/mods/MAPGEN/mcl_shipwrecks/init.lua b/mods/MAPGEN/mcl_shipwrecks/init.lua index c9bf2c9426..b2c0c3306b 100644 --- a/mods/MAPGEN/mcl_shipwrecks/init.lua +++ b/mods/MAPGEN/mcl_shipwrecks/init.lua @@ -8,11 +8,11 @@ local pr = PseudoRandom(seed) --schematics by chmodsayshello local schems = { - "shipwreck_full_damaged", - "shipwreck_full_normal", - "shipwreck_full_back_damaged", - "shipwreck_half_front", - "shipwreck_half_back", + modpath.."/schematics/".."shipwreck_full_damaged"..".mts", + modpath.."/schematics/".."shipwreck_full_normal"..".mts", + modpath.."/schematics/".."shipwreck_full_back_damaged"..".mts", + modpath.."/schematics/".."shipwreck_half_front"..".mts", + modpath.."/schematics/".."shipwreck_half_back"..".mts", } local function get_supply_loot() @@ -41,7 +41,7 @@ local function get_supply_loot() --{ itemstring = "TODO:bamboo", weight = 2, amount_min = 1, amount_max = 3 }, { itemstring = "mcl_farming:pumpkin", weight = 2, amount_min = 1, amount_max = 3 }, { itemstring = "mcl_tnt:tnt", weight = 1, amount_min = 1, amount_max = 2 }, - + } } end @@ -75,61 +75,97 @@ local function fill_chests(p1,p2) end end -local function get_ocean_biomes() - local r = {} - for k,_ in pairs(minetest.registered_biomes) do - if k:find("_ocean") then table.insert(r,k) end - end - return r -end -local function get_beach_biomes() - local r = {} - for k,_ in pairs(minetest.registered_biomes) do - if k:find("_beach") or k:find("_shore") then table.insert(r,k) end - end - return r -end +local ocean_biomes = { + "RoofedForest_ocean", + "JungleEdgeM_ocean", + "BirchForestM_ocean", + "BirchForest_ocean", + "IcePlains_deep_ocean", + "Jungle_deep_ocean", + "Savanna_ocean", + "MesaPlateauF_ocean", + "ExtremeHillsM_deep_ocean", + "Savanna_deep_ocean", + "SunflowerPlains_ocean", + "Swampland_deep_ocean", + "Swampland_ocean", + "MegaSpruceTaiga_deep_ocean", + "ExtremeHillsM_ocean", + "JungleEdgeM_deep_ocean", + "SunflowerPlains_deep_ocean", + "BirchForest_deep_ocean", + "IcePlainsSpikes_ocean", + "Mesa_ocean", + "StoneBeach_ocean", + "Plains_deep_ocean", + "JungleEdge_deep_ocean", + "SavannaM_deep_ocean", + "Desert_deep_ocean", + "Mesa_deep_ocean", + "ColdTaiga_deep_ocean", + "Plains_ocean", + "MesaPlateauFM_ocean", + "Forest_deep_ocean", + "JungleM_deep_ocean", + "FlowerForest_deep_ocean", + "MushroomIsland_ocean", + "MegaTaiga_ocean", + "StoneBeach_deep_ocean", + "IcePlainsSpikes_deep_ocean", + "ColdTaiga_ocean", + "SavannaM_ocean", + "MesaPlateauF_deep_ocean", + "MesaBryce_deep_ocean", + "ExtremeHills+_deep_ocean", + "ExtremeHills_ocean", + "MushroomIsland_deep_ocean", + "Forest_ocean", + "MegaTaiga_deep_ocean", + "JungleEdge_ocean", + "MesaBryce_ocean", + "MegaSpruceTaiga_ocean", + "ExtremeHills+_ocean", + "Jungle_ocean", + "RoofedForest_deep_ocean", + "IcePlains_ocean", + "FlowerForest_ocean", + "ExtremeHills_deep_ocean", + "MesaPlateauFM_deep_ocean", + "Desert_ocean", + "Taiga_ocean", + "BirchForestM_deep_ocean", + "Taiga_deep_ocean", + "JungleM_ocean" +} -minetest.register_node("mcl_shipwrecks:structblock", {drawtype="airlike", walkable = false, pointable = false,groups = {structblock=1,not_in_creative_inventory=1}}) +local beach_biomes = { + "FlowerForest_beach", + "Forest_beach", + "StoneBeach", + "ColdTaiga_beach_water", + "Taiga_beach", + "Savanna_beach", + "Plains_beach", + "ExtremeHills_beach", + "ColdTaiga_beach", + "Swampland_shore", + "MushroomIslandShore", + "JungleM_shore", + "Jungle_shore" +} -minetest.register_decoration({ - decoration = "mcl_shipwrecks:structblock", - deco_type = "simple", +mcl_structures.register_structure("shipwreck",{ place_on = {"group:sand","mcl_core:gravel"}, spawn_by = {"group:water"}, num_spawn_by = 4, - sidelen = 80, fill_ratio = 0.00002, flags = "place_center_x, place_center_z, force_placement", - biomes = get_ocean_biomes(), - y_max=water_level-4, -}) - ---rare beached variant -minetest.register_decoration({ - decoration = "mcl_shipwrecks:structblock", - deco_type = "simple", - place_on = {"group:sand","mcl_core:gravel","group:dirt"}, - spawn_by = {"group:water","air"}, - num_spawn_by = 4, - sidelen = 80, - fill_ratio=0.000001, - flags = "place_center_x, place_center_z, force_placement", - biomes = get_beach_biomes(), - y_max = water_level + 4, - y_min = water_level - 1, -}) - -minetest.register_lbm({ - name = "mcl_shipwrecks:struct_lbm", - run_at_every_load = true, - nodenames = {"mcl_shipwrecks:structblock"}, - action = function(pos, node) - minetest.set_node(pos,{name="air"}) - local file = modpath.."/schematics/"..schems[pr:next(1,#schems)]..".mts" - local pp = vector.offset(pos,0,pr:next(-4,-2),0) - mcl_structures.place_schematic(pp, file, "random", nil, true, "place_center_x,place_center_z", function() - fill_chests(vector.offset(pos,-20,-5,-20),vector.offset(pos,20,15,20)) - end,pr) + biomes = ocean_biomes, + y_max = water_level-4, + y_min = mcl_vars.mg_overworld_min, + filenames = schems, + y_offset = function(pr) return pr:next(-4,-2) end, + after_place = function(pos) + fill_chests(vector.offset(pos,-20,-5,-20),vector.offset(pos,20,15,20)) end }) diff --git a/mods/MAPGEN/mcl_structures/api.lua b/mods/MAPGEN/mcl_structures/api.lua new file mode 100644 index 0000000000..201e2e83fd --- /dev/null +++ b/mods/MAPGEN/mcl_structures/api.lua @@ -0,0 +1,69 @@ +local registered_structures = {} + +--[[] structure def: +{ + fill_ratio= OR noise = {} + biomes = + y_min = + y_max = + place_on = + spawn_by = + num_spawn_by = + flags = (default: "place_center_x, place_center_z, force_placement") + (same as decoration def) + y_offset = + filenames = {} OR place_func = function(pos,filename) + after_place = function(pos) +} +]]-- + +function mcl_structures.register_structure(name,def,nospawn) --nospawn means it will be placed by another (non-nospawn) structure that contains it's structblock i.e. it will not be placed by mapgen directly + local structblock = "mcl_structures:structblock_"..name + minetest.register_node(":"..structblock, {drawtype="airlike", walkable = false, pointable = false,groups = {structblock=1,not_in_creative_inventory=1}}) + local flags = "place_center_x, place_center_z, force_placement" + local y_offset = 0 + if def.flags then flags = def.flags end + def.name = name + if nospawn == nil then + def.deco = minetest.register_decoration({ + decoration = structblock, + deco_type = "simple", + place_on = def.place_on, + spawn_by = def.spawn_by, + num_spawn_by = def.num_spawn_by, + sidelen = 80, + fill_ratio = def.fill_ratio, + noise = def.noise, + flags = flags, + biomes = def.biomes, + y_max = def.y_max, + y_min = def.y_min + }) + end + registered_structures[name] = def +end + +minetest.register_lbm({ + name = "mcl_structures:struct_lbm", + run_at_every_load = true, + nodenames = {"group:structblock"}, + action = function(pos, node) + local name = node.name:gsub("mcl_structures:structblock_","") + local pr = PseudoRandom(pos.x+pos.y+pos.z) + local def = registered_structures[name] + local y_offset = 0 + minetest.set_node(pos,{name="air"}) + if type(def.y_offset) == "function" then + y_offset = def.y_offset(pr) + elseif def.y_offset then + y_offset = def.y_offset + end + if def.filenames then + local file = def.filenames[pr:next(1,#def.filenames)] + local pp = vector.offset(pos,0,y_offset,0) + mcl_structures.place_schematic(pp, file, "random", nil, true, "place_center_x,place_center_z",def.after_place,pr,{pos,def}) + elseif def.place_func and def.place_func(pos,def) then + def.after_place(pos,def) + end + end +}) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index e330e2c013..388d78190a 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -571,6 +571,8 @@ local function dir_to_rotation(dir) return "0" end +dofile(modpath.."/api.lua") + -- Debug command minetest.register_chatcommand("spawnstruct", { params = "desert_temple | desert_well | igloo | witch_hut | boulder | ice_spike_small | ice_spike_large | fossil | end_exit_portal | end_exit_portal_open | end_gateway_portal | end_portal_shrine | nether_portal | dungeon", From 1eaac3c40604ffe62ecdc8416fbaec17d3c7e2b5 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 10 Jun 2022 01:06:24 +0200 Subject: [PATCH 03/12] use gennotify instead of lbm for placement keep the lbm for secondary structures --- mods/MAPGEN/mcl_structures/api.lua | 57 ++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/mods/MAPGEN/mcl_structures/api.lua b/mods/MAPGEN/mcl_structures/api.lua index 201e2e83fd..e9dc8b5bf4 100644 --- a/mods/MAPGEN/mcl_structures/api.lua +++ b/mods/MAPGEN/mcl_structures/api.lua @@ -17,15 +17,35 @@ local registered_structures = {} } ]]-- +local function place_schem(pos, def, pr) + if not def then return end + if type(def.y_offset) == "function" then + y_offset = def.y_offset(pr) + elseif def.y_offset then + y_offset = def.y_offset + end + if def.filenames then + local file = def.filenames[pr:next(1,#def.filenames)] + local pp = vector.offset(pos,0,y_offset,0) + mcl_structures.place_schematic(pp, file, "random", nil, true, "place_center_x,place_center_z",def.after_place,pr,{pos,def}) + elseif def.place_func and def.place_func(pos,def) then + def.after_place(pos,def) + end +end + function mcl_structures.register_structure(name,def,nospawn) --nospawn means it will be placed by another (non-nospawn) structure that contains it's structblock i.e. it will not be placed by mapgen directly local structblock = "mcl_structures:structblock_"..name - minetest.register_node(":"..structblock, {drawtype="airlike", walkable = false, pointable = false,groups = {structblock=1,not_in_creative_inventory=1}}) local flags = "place_center_x, place_center_z, force_placement" local y_offset = 0 + local sbgroups = { structblock = 1, not_in_creative_inventory=1 } if def.flags then flags = def.flags end def.name = name - if nospawn == nil then + if nospawn then + sbgroups.structblock = nil + sbgroups.structblock_lbm = 1 + else def.deco = minetest.register_decoration({ + name = "mcl_structures:deco_"..name, decoration = structblock, deco_type = "simple", place_on = def.place_on, @@ -39,31 +59,32 @@ function mcl_structures.register_structure(name,def,nospawn) --nospawn means it y_max = def.y_max, y_min = def.y_min }) + local deco_id = minetest.get_decoration_id("mcl_structures:deco_"..name) + minetest.set_gen_notify({decoration=true}, { deco_id }) + minetest.register_on_generated(function(minp, maxp, blockseed) + local gennotify = minetest.get_mapgen_object("gennotify") + local pr = PseudoRandom(blockseed + 42) + for _, pos in pairs(gennotify["decoration#"..deco_id] or {}) do + local realpos = vector.offset(pos,0,-1,0) + minetest.remove_node(realpos) + place_schem(realpos,def,pr) + end + end) end + minetest.register_node(":"..structblock, {drawtype="airlike", walkable = false, pointable = false,groups = sbgroups}) registered_structures[name] = def end +--lbm for secondary structures (structblock included in base structure) minetest.register_lbm({ name = "mcl_structures:struct_lbm", run_at_every_load = true, - nodenames = {"group:structblock"}, + nodenames = {"group:structblock_lbm"}, action = function(pos, node) local name = node.name:gsub("mcl_structures:structblock_","") - local pr = PseudoRandom(pos.x+pos.y+pos.z) local def = registered_structures[name] - local y_offset = 0 - minetest.set_node(pos,{name="air"}) - if type(def.y_offset) == "function" then - y_offset = def.y_offset(pr) - elseif def.y_offset then - y_offset = def.y_offset - end - if def.filenames then - local file = def.filenames[pr:next(1,#def.filenames)] - local pp = vector.offset(pos,0,y_offset,0) - mcl_structures.place_schematic(pp, file, "random", nil, true, "place_center_x,place_center_z",def.after_place,pr,{pos,def}) - elseif def.place_func and def.place_func(pos,def) then - def.after_place(pos,def) - end + if not def then return end + minetest.remove_node(pos) + place_schem(pos) end }) From 8fa67e6b4fe4b0bfc95f79aff3c9ced420a22ce3 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 10 Jun 2022 01:49:33 +0200 Subject: [PATCH 04/12] Geodes as test for place by function --- mods/MAPGEN/mcl_geodes/init.lua | 75 ++++++++++++++++++++++++++++++ mods/MAPGEN/mcl_geodes/mod.conf | 3 ++ mods/MAPGEN/mcl_structures/api.lua | 6 +-- 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 mods/MAPGEN/mcl_geodes/init.lua create mode 100644 mods/MAPGEN/mcl_geodes/mod.conf diff --git a/mods/MAPGEN/mcl_geodes/init.lua b/mods/MAPGEN/mcl_geodes/init.lua new file mode 100644 index 0000000000..cf0ec3050e --- /dev/null +++ b/mods/MAPGEN/mcl_geodes/init.lua @@ -0,0 +1,75 @@ +local adjacents = { + vector.new(1,0,0), + vector.new(-1,0,0), + vector.new(0,0,1), + vector.new(0,0,-1), + vector.new(0,1,0), + vector.new(0,-1,0) +} + +local function makegeode(pos,pr) + local size = pr:next(3,18) + local p1 = vector.offset(pos,-size,-size,-size) + local p2 = vector.offset(pos,size,size,size) + local nn = minetest.find_nodes_in_area(p1,p2,{"group:material_stone"}) + table.sort(nn,function(a, b) + return vector.distance(pos, a) < vector.distance(pos, b) + end) + if not nn[1] then return end + for i=1,math.random(#nn) do + minetest.set_node(nn[i],{name="mcl_amethyst:amethyst_block"}) + end + local nnn = minetest.find_nodes_in_area(p1,p2,{"mcl_amethyst:amethyst_block"}) + for k,v in pairs(nnn) do + local all_amethyst = true + for kk,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 + if minetest.get_item_group(an.name,"material_stone") > 0 then + minetest.set_node(pp,{name="mcl_amethyst:calcite"}) + if pr:next(1,5) == 1 then + minetest.set_node(v,{name="mcl_amethyst:budding_amethyst_block"}) + end + all_amethyst = false + elseif an.name ~= "mcl_amethyst:amethyst_block" and an.name ~= "air" then + all_amethyst = false + end + end + end + if all_amethyst then minetest.set_node(v,{name="air"}) end + end + + local nnnn = minetest.find_nodes_in_area_under_air(p1,p2,{"mcl_amethyst:amethyst_block"}) + for k,v in pairs(nnnn) do + local r = pr:next(1,50) + if r < 10 then + minetest.set_node(vector.offset(v,0,1,0),{name="mcl_amethyst:amethyst_cluster",param2=1}) + end + end +end + +mcl_structures.register_structure("geodes",{ + place_on = {"mcl_core:stone"}, + spawn_by = {"air"}, + num_spawn_by = 2, + fill_ratio = 0.002, + flags = "place_center_x, place_center_z, force_placement", + biomes = ocean_biomes, + y_max = mcl_vars.mg_overworld_max, + y_min = mcl_vars.mg_overworld_min, + filenames = schems, + y_offset = function(pr) return pr:next(-4,-2) end, + place_func = function(pos,def,pr) + local p = vector.new(pos.x + pr:next(-30,30),pos.y,pos.z + pr:next(-30,30)) + makegeode(pos,pr) + end, +}) + +minetest.register_chatcommand("makegeode",{ + privs = { debug = true }, + func=function(n,p) + local pos = pl:get_pos() + makegeode(pos,PseudoRandom(minetest.get_mapgen_setting("seed"))) + end +}) diff --git a/mods/MAPGEN/mcl_geodes/mod.conf b/mods/MAPGEN/mcl_geodes/mod.conf new file mode 100644 index 0000000000..cccb57108b --- /dev/null +++ b/mods/MAPGEN/mcl_geodes/mod.conf @@ -0,0 +1,3 @@ +name = mcl_geodes +author = cora +depends = mcl_init, mcl_structures diff --git a/mods/MAPGEN/mcl_structures/api.lua b/mods/MAPGEN/mcl_structures/api.lua index e9dc8b5bf4..71ca75ff50 100644 --- a/mods/MAPGEN/mcl_structures/api.lua +++ b/mods/MAPGEN/mcl_structures/api.lua @@ -2,7 +2,7 @@ local registered_structures = {} --[[] structure def: { - fill_ratio= OR noise = {} + fill_ratio = OR noise = {} biomes = y_min = y_max = @@ -28,8 +28,8 @@ local function place_schem(pos, def, pr) local file = def.filenames[pr:next(1,#def.filenames)] local pp = vector.offset(pos,0,y_offset,0) mcl_structures.place_schematic(pp, file, "random", nil, true, "place_center_x,place_center_z",def.after_place,pr,{pos,def}) - elseif def.place_func and def.place_func(pos,def) then - def.after_place(pos,def) + elseif def.place_func and def.place_func(pos,def,pr) then + def.after_place(pos,def,pr) end end From b0b8638a4c6d4858cff349c70ffb8dec18ccde34 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 10 Jun 2022 02:40:33 +0200 Subject: [PATCH 05/12] Add /spawnstruct support --- mods/MAPGEN/mcl_geodes/init.lua | 12 +-- mods/MAPGEN/mcl_structures/api.lua | 12 +-- mods/MAPGEN/mcl_structures/init.lua | 127 ++++++++++++++++------------ 3 files changed, 79 insertions(+), 72 deletions(-) diff --git a/mods/MAPGEN/mcl_geodes/init.lua b/mods/MAPGEN/mcl_geodes/init.lua index cf0ec3050e..413a8fbba4 100644 --- a/mods/MAPGEN/mcl_geodes/init.lua +++ b/mods/MAPGEN/mcl_geodes/init.lua @@ -8,7 +8,7 @@ local adjacents = { } local function makegeode(pos,pr) - local size = pr:next(3,18) + local size = pr:next(4,12) local p1 = vector.offset(pos,-size,-size,-size) local p2 = vector.offset(pos,size,size,size) local nn = minetest.find_nodes_in_area(p1,p2,{"group:material_stone"}) @@ -49,7 +49,7 @@ local function makegeode(pos,pr) end end -mcl_structures.register_structure("geodes",{ +mcl_structures.register_structure("geode",{ place_on = {"mcl_core:stone"}, spawn_by = {"air"}, num_spawn_by = 2, @@ -65,11 +65,3 @@ mcl_structures.register_structure("geodes",{ makegeode(pos,pr) end, }) - -minetest.register_chatcommand("makegeode",{ - privs = { debug = true }, - func=function(n,p) - local pos = pl:get_pos() - makegeode(pos,PseudoRandom(minetest.get_mapgen_setting("seed"))) - end -}) diff --git a/mods/MAPGEN/mcl_structures/api.lua b/mods/MAPGEN/mcl_structures/api.lua index 71ca75ff50..5e0858fb1c 100644 --- a/mods/MAPGEN/mcl_structures/api.lua +++ b/mods/MAPGEN/mcl_structures/api.lua @@ -1,4 +1,4 @@ -local registered_structures = {} +mcl_structures.registered_structures = {} --[[] structure def: { @@ -17,7 +17,7 @@ local registered_structures = {} } ]]-- -local function place_schem(pos, def, pr) +function mcl_structures.place_structure(pos, def, pr) if not def then return end if type(def.y_offset) == "function" then y_offset = def.y_offset(pr) @@ -67,12 +67,12 @@ function mcl_structures.register_structure(name,def,nospawn) --nospawn means it for _, pos in pairs(gennotify["decoration#"..deco_id] or {}) do local realpos = vector.offset(pos,0,-1,0) minetest.remove_node(realpos) - place_schem(realpos,def,pr) + mcl_structures.place_structure(realpos,def,pr) end end) end minetest.register_node(":"..structblock, {drawtype="airlike", walkable = false, pointable = false,groups = sbgroups}) - registered_structures[name] = def + mcl_structures.registered_structures[name] = def end --lbm for secondary structures (structblock included in base structure) @@ -82,9 +82,9 @@ minetest.register_lbm({ nodenames = {"group:structblock_lbm"}, action = function(pos, node) local name = node.name:gsub("mcl_structures:structblock_","") - local def = registered_structures[name] + local def = mcl_structures.registered_structures[name] if not def then return end minetest.remove_node(pos) - place_schem(pos) + mcl_structures.place_structure(pos) end }) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 388d78190a..665fbf4c06 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -573,60 +573,75 @@ end dofile(modpath.."/api.lua") --- Debug command -minetest.register_chatcommand("spawnstruct", { - params = "desert_temple | desert_well | igloo | witch_hut | boulder | ice_spike_small | ice_spike_large | fossil | end_exit_portal | end_exit_portal_open | end_gateway_portal | end_portal_shrine | nether_portal | dungeon", - description = S("Generate a pre-defined structure near your position."), - privs = {debug = true}, - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player then return end - local pos = player:get_pos() - if not pos then return end - pos = vector.round(pos) - local dir = minetest.yaw_to_dir(player:get_look_horizontal()) - local rot = dir_to_rotation(dir) - local pr = PseudoRandom(pos.x+pos.y+pos.z) - local errord = false - local message = S("Structure placed.") - if param == "desert_temple" then - mcl_structures.generate_desert_temple(pos, rot, pr) - elseif param == "desert_well" then - mcl_structures.generate_desert_well(pos, rot) - elseif param == "igloo" then - mcl_structures.generate_igloo(pos, rot, pr) - elseif param == "witch_hut" then - mcl_structures.generate_witch_hut(pos, rot, pr) - elseif param == "boulder" then - mcl_structures.generate_boulder(pos, rot, pr) - elseif param == "fossil" then - mcl_structures.generate_fossil(pos, rot, pr) - elseif param == "ice_spike_small" then - mcl_structures.generate_ice_spike_small(pos, rot, pr) - elseif param == "ice_spike_large" then - mcl_structures.generate_ice_spike_large(pos, rot, pr) - elseif param == "end_exit_portal" then - mcl_structures.generate_end_exit_portal(pos, rot, pr) - elseif param == "end_exit_portal_open" then - mcl_structures.generate_end_exit_portal_open(pos, rot, pr) - elseif param == "end_gateway_portal" then - mcl_structures.generate_end_gateway_portal(pos, rot, pr) - elseif param == "end_portal_shrine" then - mcl_structures.generate_end_portal_shrine(pos, rot, pr) - elseif param == "dungeon" and mcl_dungeons and mcl_dungeons.spawn_dungeon then - mcl_dungeons.spawn_dungeon(pos, rot, pr) - elseif param == "nether_portal" and mcl_portals and mcl_portals.spawn_nether_portal then - mcl_portals.spawn_nether_portal(pos, rot, pr, name) - elseif param == "" then - message = S("Error: No structure type given. Please use “/spawnstruct ”.") - errord = true - else - message = S("Error: Unknown structure type. Please use “/spawnstruct ”.") - errord = true - end - minetest.chat_send_player(name, message) - if errord then - minetest.chat_send_player(name, S("Use /help spawnstruct to see a list of avaiable types.")) - end +minetest.register_on_mods_loaded(function() + -- Debug command + local chatcommand_params = "desert_temple | desert_well | igloo | witch_hut | boulder | ice_spike_small | ice_spike_large | fossil | end_exit_portal | end_exit_portal_open | end_gateway_portal | end_portal_shrine | nether_portal | dungeon" + + for n,_ in pairs(mcl_structures.registered_structures) do + chatcommand_params = chatcommand_params .. " | "..n end -}) + + minetest.register_chatcommand("spawnstruct", { + params = chatcommand_params, + description = S("Generate a pre-defined structure near your position."), + privs = {debug = true}, + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then return end + local pos = player:get_pos() + if not pos then return end + pos = vector.round(pos) + local dir = minetest.yaw_to_dir(player:get_look_horizontal()) + local rot = dir_to_rotation(dir) + local pr = PseudoRandom(pos.x+pos.y+pos.z) + local errord = false + local message = S("Structure placed.") + if param == "desert_temple" then + mcl_structures.generate_desert_temple(pos, rot, pr) + elseif param == "desert_well" then + mcl_structures.generate_desert_well(pos, rot) + elseif param == "igloo" then + mcl_structures.generate_igloo(pos, rot, pr) + elseif param == "witch_hut" then + mcl_structures.generate_witch_hut(pos, rot, pr) + elseif param == "boulder" then + mcl_structures.generate_boulder(pos, rot, pr) + elseif param == "fossil" then + mcl_structures.generate_fossil(pos, rot, pr) + elseif param == "ice_spike_small" then + mcl_structures.generate_ice_spike_small(pos, rot, pr) + elseif param == "ice_spike_large" then + mcl_structures.generate_ice_spike_large(pos, rot, pr) + elseif param == "end_exit_portal" then + mcl_structures.generate_end_exit_portal(pos, rot, pr) + elseif param == "end_exit_portal_open" then + mcl_structures.generate_end_exit_portal_open(pos, rot, pr) + elseif param == "end_gateway_portal" then + mcl_structures.generate_end_gateway_portal(pos, rot, pr) + elseif param == "end_portal_shrine" then + mcl_structures.generate_end_portal_shrine(pos, rot, pr) + elseif param == "dungeon" and mcl_dungeons and mcl_dungeons.spawn_dungeon then + mcl_dungeons.spawn_dungeon(pos, rot, pr) + elseif param == "nether_portal" and mcl_portals and mcl_portals.spawn_nether_portal then + mcl_portals.spawn_nether_portal(pos, rot, pr, name) + elseif param == "" then + message = S("Error: No structure type given. Please use “/spawnstruct ”.") + errord = true + else + for n,d in pairs(mcl_structures.registered_structures) do + if n == param then + mcl_structures.place_structure(pos,d,PseudoRandom(os.clock())) + minetest.chat_send_player(name, message) + return + end + end + message = S("Error: Unknown structure type. Please use “/spawnstruct ”.") + errord = true + end + minetest.chat_send_player(name, message) + if errord then + minetest.chat_send_player(name, S("Use /help spawnstruct to see a list of avaiable types.")) + end + end + }) +end) From a89529237186cd47c9a670f12c2473173aa69741 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 10 Jun 2022 03:12:45 +0200 Subject: [PATCH 06/12] Add API documentation, minor fixes --- mods/MAPGEN/mcl_geodes/init.lua | 2 +- mods/MAPGEN/mcl_structures/API.md | 27 +++++++++++++++++++++++++++ mods/MAPGEN/mcl_structures/api.lua | 1 + mods/MAPGEN/mcl_structures/init.lua | 5 ++--- mods/MAPGEN/mcl_structures/mod.conf | 4 ++-- 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 mods/MAPGEN/mcl_structures/API.md diff --git a/mods/MAPGEN/mcl_geodes/init.lua b/mods/MAPGEN/mcl_geodes/init.lua index 413a8fbba4..d2debf7cd5 100644 --- a/mods/MAPGEN/mcl_geodes/init.lua +++ b/mods/MAPGEN/mcl_geodes/init.lua @@ -8,7 +8,7 @@ local adjacents = { } local function makegeode(pos,pr) - local size = pr:next(4,12) + local size = pr:next(2,8) local p1 = vector.offset(pos,-size,-size,-size) local p2 = vector.offset(pos,size,size,size) local nn = minetest.find_nodes_in_area(p1,p2,{"group:material_stone"}) diff --git a/mods/MAPGEN/mcl_structures/API.md b/mods/MAPGEN/mcl_structures/API.md new file mode 100644 index 0000000000..52d40b642f --- /dev/null +++ b/mods/MAPGEN/mcl_structures/API.md @@ -0,0 +1,27 @@ +# mcl_structures +Structure placement API for MCL2. + +## mcl_structures.register_structure(name,structure definition) +### structure definition +{ + fill_ratio = OR noise = {}, + biomes = {}, + y_min =, + y_max =, + place_on = {}, + spawn_by = {}, + num_spawn_by = + flags = (default: "place_center_x, place_center_z, force_placement") + (same as decoration def) + y_offset =, --can be a number or a function returning a number + filenames = {} OR place_func = function(pos,filename) + -- filenames can be a list of any schematics accepted by mcl_structures.place_schematic + after_place = function(pos) +} +## mcl_structures.registered_structures +Table of the registered structure defintions indexed by name. + +## mcl_structures.place_structure(pos, def, pr) +Places a structure using the mapgen placement function + +## mcl_structures.place_schematic(pos, schematic, rotation, replacements, force_placement, flags, after_placement_callback, pr, callback_param) diff --git a/mods/MAPGEN/mcl_structures/api.lua b/mods/MAPGEN/mcl_structures/api.lua index 5e0858fb1c..be86df5309 100644 --- a/mods/MAPGEN/mcl_structures/api.lua +++ b/mods/MAPGEN/mcl_structures/api.lua @@ -72,6 +72,7 @@ function mcl_structures.register_structure(name,def,nospawn) --nospawn means it end) end minetest.register_node(":"..structblock, {drawtype="airlike", walkable = false, pointable = false,groups = sbgroups}) + def.structblock = structblock mcl_structures.registered_structures[name] = def end diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 665fbf4c06..a82dffbff7 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -630,9 +630,8 @@ minetest.register_on_mods_loaded(function() else for n,d in pairs(mcl_structures.registered_structures) do if n == param then - mcl_structures.place_structure(pos,d,PseudoRandom(os.clock())) - minetest.chat_send_player(name, message) - return + mcl_structures.place_structure(pos,d,pr) + return true,message end end message = S("Error: Unknown structure type. Please use “/spawnstruct ”.") diff --git a/mods/MAPGEN/mcl_structures/mod.conf b/mods/MAPGEN/mcl_structures/mod.conf index 3150c7cec0..c19113ad44 100644 --- a/mods/MAPGEN/mcl_structures/mod.conf +++ b/mods/MAPGEN/mcl_structures/mod.conf @@ -1,4 +1,4 @@ name = mcl_structures -author = Wuzzy -description = Structures for MCL2 +author = Wuzzy, cora +description = Structure placement for MCL2 depends = mcl_loot From a0bed1d8bc260cd02ace7447920b7489013b1163 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 10 Jun 2022 04:34:58 +0200 Subject: [PATCH 07/12] Add proper logging + some fixes --- mods/MAPGEN/mcl_geodes/init.lua | 13 ++++++------- mods/MAPGEN/mcl_structures/API.md | 10 ++++++---- mods/MAPGEN/mcl_structures/api.lua | 28 +++++++++------------------- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/mods/MAPGEN/mcl_geodes/init.lua b/mods/MAPGEN/mcl_geodes/init.lua index d2debf7cd5..db79d2e5ed 100644 --- a/mods/MAPGEN/mcl_geodes/init.lua +++ b/mods/MAPGEN/mcl_geodes/init.lua @@ -8,7 +8,7 @@ local adjacents = { } local function makegeode(pos,pr) - local size = pr:next(2,8) + local size = pr:next(4,7) local p1 = vector.offset(pos,-size,-size,-size) local p2 = vector.offset(pos,size,size,size) local nn = minetest.find_nodes_in_area(p1,p2,{"group:material_stone"}) @@ -47,21 +47,20 @@ local function makegeode(pos,pr) minetest.set_node(vector.offset(v,0,1,0),{name="mcl_amethyst:amethyst_cluster",param2=1}) end end + return true end mcl_structures.register_structure("geode",{ place_on = {"mcl_core:stone"}, - spawn_by = {"air"}, - num_spawn_by = 2, - fill_ratio = 0.002, + fill_ratio = 0.0001, flags = "place_center_x, place_center_z, force_placement", biomes = ocean_biomes, - y_max = mcl_vars.mg_overworld_max, + y_max = -24, y_min = mcl_vars.mg_overworld_min, filenames = schems, y_offset = function(pr) return pr:next(-4,-2) end, place_func = function(pos,def,pr) local p = vector.new(pos.x + pr:next(-30,30),pos.y,pos.z + pr:next(-30,30)) - makegeode(pos,pr) - end, + return makegeode(pos,pr) + end }) diff --git a/mods/MAPGEN/mcl_structures/API.md b/mods/MAPGEN/mcl_structures/API.md index 52d40b642f..23d93c712a 100644 --- a/mods/MAPGEN/mcl_structures/API.md +++ b/mods/MAPGEN/mcl_structures/API.md @@ -1,7 +1,9 @@ # mcl_structures Structure placement API for MCL2. -## mcl_structures.register_structure(name,structure definition) +## mcl_structures.register_structure(name,structure definition,nospawn) +If nospawn is truthy the structure will not be placed by mapgen and the decoration parameters can be omitted. This is intended for secondary structures the placement of which gets triggered by the placement of other structures. It can also be used to register testing structures so they can be used with /spawnstruct. + ### structure definition { fill_ratio = OR noise = {}, @@ -14,9 +16,9 @@ Structure placement API for MCL2. flags = (default: "place_center_x, place_center_z, force_placement") (same as decoration def) y_offset =, --can be a number or a function returning a number - filenames = {} OR place_func = function(pos,filename) - -- filenames can be a list of any schematics accepted by mcl_structures.place_schematic - after_place = function(pos) + filenames = {} OR place_func = function(pos,def,pr) + -- filenames can be a list of any schematics accepted by mcl_structures.place_schematic / minetest.place_schematic + after_place = function(pos,def,pr) } ## mcl_structures.registered_structures Table of the registered structure defintions indexed by name. diff --git a/mods/MAPGEN/mcl_structures/api.lua b/mods/MAPGEN/mcl_structures/api.lua index be86df5309..2235d44053 100644 --- a/mods/MAPGEN/mcl_structures/api.lua +++ b/mods/MAPGEN/mcl_structures/api.lua @@ -1,24 +1,8 @@ mcl_structures.registered_structures = {} ---[[] structure def: -{ - fill_ratio = OR noise = {} - biomes = - y_min = - y_max = - place_on = - spawn_by = - num_spawn_by = - flags = (default: "place_center_x, place_center_z, force_placement") - (same as decoration def) - y_offset = - filenames = {} OR place_func = function(pos,filename) - after_place = function(pos) -} -]]-- - function mcl_structures.place_structure(pos, def, pr) - if not def then return end + if not def then return end + local y_offset = 0 if type(def.y_offset) == "function" then y_offset = def.y_offset(pr) elseif def.y_offset then @@ -28,9 +12,15 @@ function mcl_structures.place_structure(pos, def, pr) local file = def.filenames[pr:next(1,#def.filenames)] local pp = vector.offset(pos,0,y_offset,0) mcl_structures.place_schematic(pp, file, "random", nil, true, "place_center_x,place_center_z",def.after_place,pr,{pos,def}) + minetest.log("action","[mcl_structures] "..def.name.." placed at "..minetest.pos_to_string(pos)) + return true elseif def.place_func and def.place_func(pos,def,pr) then - def.after_place(pos,def,pr) + if not def.after_place or ( def.after_place and def.after_place(pos,def,pr) ) then + minetest.log("action","[mcl_structures] "..def.name.." placed at "..minetest.pos_to_string(pos)) + return true + end end + minetest.log("warning","[mcl_structures] placing "..def.name.." failed at "..minetest.pos_to_string(pos)) end function mcl_structures.register_structure(name,def,nospawn) --nospawn means it will be placed by another (non-nospawn) structure that contains it's structblock i.e. it will not be placed by mapgen directly From fa56ce5d521ab144c24e57b3383fed897f20df63 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 11 Jun 2022 12:24:06 +0200 Subject: [PATCH 08/12] Add outer geode layer uses deepslate until smooth basalt is there --- mods/MAPGEN/mcl_geodes/init.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mods/MAPGEN/mcl_geodes/init.lua b/mods/MAPGEN/mcl_geodes/init.lua index db79d2e5ed..c79dc07ed6 100644 --- a/mods/MAPGEN/mcl_geodes/init.lua +++ b/mods/MAPGEN/mcl_geodes/init.lua @@ -11,16 +11,18 @@ local function makegeode(pos,pr) local size = pr:next(4,7) local p1 = vector.offset(pos,-size,-size,-size) local p2 = vector.offset(pos,size,size,size) + local calcite = {} local nn = minetest.find_nodes_in_area(p1,p2,{"group:material_stone"}) table.sort(nn,function(a, b) return vector.distance(pos, a) < vector.distance(pos, b) end) if not nn[1] then return end + for i=1,math.random(#nn) do minetest.set_node(nn[i],{name="mcl_amethyst:amethyst_block"}) end - local nnn = minetest.find_nodes_in_area(p1,p2,{"mcl_amethyst:amethyst_block"}) - for k,v in pairs(nnn) do + + for k,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 local pp = vector.add(v,vv) @@ -28,6 +30,7 @@ local function makegeode(pos,pr) if an.name ~= "mcl_amethyst:amethyst_block" then if minetest.get_item_group(an.name,"material_stone") > 0 then minetest.set_node(pp,{name="mcl_amethyst:calcite"}) + table.insert(calcite,pp) if pr:next(1,5) == 1 then minetest.set_node(v,{name="mcl_amethyst:budding_amethyst_block"}) end @@ -40,8 +43,13 @@ local function makegeode(pos,pr) if all_amethyst then minetest.set_node(v,{name="air"}) end end - local nnnn = minetest.find_nodes_in_area_under_air(p1,p2,{"mcl_amethyst:amethyst_block"}) - for k,v in pairs(nnnn) 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 + minetest.set_node(vv,{name="mcl_deepslate:deepslate"}) + 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 local r = pr:next(1,50) if r < 10 then minetest.set_node(vector.offset(v,0,1,0),{name="mcl_amethyst:amethyst_cluster",param2=1}) From 1b0053299cbd4119ece9974e150eaab906151e62 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 11 Jun 2022 12:29:53 +0200 Subject: [PATCH 09/12] Do not replace bedrock during geode gen. --- mods/MAPGEN/mcl_geodes/init.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mods/MAPGEN/mcl_geodes/init.lua b/mods/MAPGEN/mcl_geodes/init.lua index c79dc07ed6..5c05bc8741 100644 --- a/mods/MAPGEN/mcl_geodes/init.lua +++ b/mods/MAPGEN/mcl_geodes/init.lua @@ -7,6 +7,12 @@ local adjacents = { vector.new(0,-1,0) } +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 makegeode(pos,pr) local size = pr:next(4,7) local p1 = vector.offset(pos,-size,-size,-size) @@ -19,7 +25,7 @@ local function makegeode(pos,pr) if not nn[1] then return end for i=1,math.random(#nn) do - minetest.set_node(nn[i],{name="mcl_amethyst:amethyst_block"}) + 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 @@ -29,10 +35,10 @@ local function makegeode(pos,pr) local an = minetest.get_node(pp) if an.name ~= "mcl_amethyst:amethyst_block" then if minetest.get_item_group(an.name,"material_stone") > 0 then - minetest.set_node(pp,{name="mcl_amethyst:calcite"}) + set_node_no_bedrock(pp,{name="mcl_amethyst:calcite"}) table.insert(calcite,pp) if pr:next(1,5) == 1 then - minetest.set_node(v,{name="mcl_amethyst:budding_amethyst_block"}) + set_node_no_bedrock(v,{name="mcl_amethyst:budding_amethyst_block"}) end all_amethyst = false elseif an.name ~= "mcl_amethyst:amethyst_block" and an.name ~= "air" then @@ -40,19 +46,19 @@ local function makegeode(pos,pr) end end end - if all_amethyst then minetest.set_node(v,{name="air"}) end + 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 - minetest.set_node(vv,{name="mcl_deepslate:deepslate"}) + set_node_no_bedrock(vv,{name="mcl_deepslate:deepslate"}) 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 local r = pr:next(1,50) if r < 10 then - minetest.set_node(vector.offset(v,0,1,0),{name="mcl_amethyst:amethyst_cluster",param2=1}) + set_node_no_bedrock(vector.offset(v,0,1,0),{name="mcl_amethyst:amethyst_cluster",param2=1}) end end return true From 9c6aafa3c1dcdf693e0849daa36fe5cdf060aba1 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 13 Jun 2022 02:32:26 +0200 Subject: [PATCH 10/12] add surface pools --- mods/MAPGEN/mcl_geodes/init.lua | 2 +- mods/MAPGEN/mcl_surface_pools/init.lua | 90 ++++++++++++++++++++++++++ mods/MAPGEN/mcl_surface_pools/mod.conf | 3 + 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 mods/MAPGEN/mcl_surface_pools/init.lua create mode 100644 mods/MAPGEN/mcl_surface_pools/mod.conf diff --git a/mods/MAPGEN/mcl_geodes/init.lua b/mods/MAPGEN/mcl_geodes/init.lua index 5c05bc8741..2481398092 100644 --- a/mods/MAPGEN/mcl_geodes/init.lua +++ b/mods/MAPGEN/mcl_geodes/init.lua @@ -51,7 +51,7 @@ local function makegeode(pos,pr) 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_deepslate:deepslate"}) + set_node_no_bedrock(vv,{name="mcl_deepslate:deepslate"}) --Replace with smooth basalt when available end end diff --git a/mods/MAPGEN/mcl_surface_pools/init.lua b/mods/MAPGEN/mcl_surface_pools/init.lua new file mode 100644 index 0000000000..8dfa9ca400 --- /dev/null +++ b/mods/MAPGEN/mcl_surface_pools/init.lua @@ -0,0 +1,90 @@ +local adjacents = { + vector.new(1,0,0), + vector.new(1,0,1), + vector.new(1,0,-1), + vector.new(-1,0,0), + vector.new(-1,0,1), + vector.new(-1,0,-1), + vector.new(0,0,1), + vector.new(0,0,-1), + vector.new(0,-1,0) +} + +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) + for i=0,35 do + set_node_no_bedrock(vector.offset(pos,0,i,0),{name="air"}) + end +end + +local function makelake(pos,size,liquid,border,pr) + local node_under = minetest.get_node(vector.offset(pos,0,1,0)) + local p1 = vector.offset(pos,-size,-size,-size) + local p2 = vector.offset(pos,size,size,size) + local nn = minetest.find_nodes_in_area(p1,p2,{"group:material_stone", "group:sand", "group:dirt"}) + table.sort(nn,function(a, b) + return vector.distance(pos, a) < vector.distance(pos, b) + end) + if not nn[1] then return end + local y = pos.y + 1 + local lq = {} + for i=1,pr:next(1,#nn) do + if nn[i].y == y then + set_node_no_bedrock(nn[i],{name=liquid}) + airtower(vector.offset(nn[i],0,1,0)) + table.insert(lq,nn[i]) + end + end + + for k,v in pairs(lq) do + for kk,vv in pairs(adjacents) do + local pp = vector.add(v,vv) + local an = minetest.get_node(pp) + local un = minetest.get_node(vector.offset(pp,0,1,0)) + if not border then + if minetest.get_item_group(an.name,"solid") > 0 then + border = an.name + elseif minetest.get_item_group(minetest.get_node(nn[1]).name,"solid") > 0 then + border = minetest.get_node(nn[1]).name + else + border = "mcl_core:stone" + end + if border == "mcl_core:dirt" then border = "mcl_core:dirt_with_grass" end + end + if an.name ~= liquid then + set_node_no_bedrock(pp,{name=border}) + if un.name ~= liquid then + airtower(vector.offset(pp,0,1,0)) + end + end + end + end + return true +end + +mcl_structures.register_structure("lavapool",{ + place_on = {"group:sand", "group:dirt", "group:stone"}, + fill_ratio = 0.000015, + flags = "place_center_x, place_center_z, force_placement", + y_max = mcl_vars.mg_overworld_max, + y_min = minetest.get_mapgen_setting("water_level"), + place_func = function(pos,def,pr) + return makelake(pos,5,"mcl_core:lava_source","mcl_core:stone",pr) + end +}) + +mcl_structures.register_structure("water_lake",{ + place_on = {"group:dirt","group:stone"}, + fill_ratio = 0.000052, + flags = "place_center_x, place_center_z, force_placement", + y_max = mcl_vars.mg_overworld_max, + y_min = minetest.get_mapgen_setting("water_level"), + place_func = function(pos,def,pr) + return makelake(pos,5,"mcl_core:water_source",nil,pr) + end +}) diff --git a/mods/MAPGEN/mcl_surface_pools/mod.conf b/mods/MAPGEN/mcl_surface_pools/mod.conf new file mode 100644 index 0000000000..bdc4319d45 --- /dev/null +++ b/mods/MAPGEN/mcl_surface_pools/mod.conf @@ -0,0 +1,3 @@ +name = mcl_surface_pools +author = cora +depends = mcl_init, mcl_structures From 726d1f07fa88a4a094a78587dd7ad13db2c87363 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 13 Jun 2022 11:59:15 +0200 Subject: [PATCH 11/12] use noise instead of fill_ratio for distribution --- mods/MAPGEN/mcl_geodes/init.lua | 14 +++++++++++--- mods/MAPGEN/mcl_shipwrecks/init.lua | 12 ++++++++++-- mods/MAPGEN/mcl_structures/api.lua | 2 +- mods/MAPGEN/mcl_surface_pools/init.lua | 22 +++++++++++++++++++--- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/mods/MAPGEN/mcl_geodes/init.lua b/mods/MAPGEN/mcl_geodes/init.lua index 2481398092..84acd973b7 100644 --- a/mods/MAPGEN/mcl_geodes/init.lua +++ b/mods/MAPGEN/mcl_geodes/init.lua @@ -51,7 +51,7 @@ local function makegeode(pos,pr) 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_deepslate:deepslate"}) --Replace with smooth basalt when available + set_node_no_bedrock(vv,{name="mcl_blackstone:basalt_smooth"}) end end @@ -66,7 +66,15 @@ end mcl_structures.register_structure("geode",{ place_on = {"mcl_core:stone"}, - fill_ratio = 0.0001, + noise_params = { + offset = 0, + scale = 0.00022, + spread = {x = 250, y = 250, z = 250}, + seed = 7894353, + octaves = 3, + persist = 0.001, + flags = "absvalue", + }, flags = "place_center_x, place_center_z, force_placement", biomes = ocean_biomes, y_max = -24, @@ -75,6 +83,6 @@ mcl_structures.register_structure("geode",{ y_offset = function(pr) return pr:next(-4,-2) end, place_func = function(pos,def,pr) local p = vector.new(pos.x + pr:next(-30,30),pos.y,pos.z + pr:next(-30,30)) - return makegeode(pos,pr) + return makegeode(p,pr) end }) diff --git a/mods/MAPGEN/mcl_shipwrecks/init.lua b/mods/MAPGEN/mcl_shipwrecks/init.lua index b2c0c3306b..a3861a2c92 100644 --- a/mods/MAPGEN/mcl_shipwrecks/init.lua +++ b/mods/MAPGEN/mcl_shipwrecks/init.lua @@ -158,8 +158,16 @@ mcl_structures.register_structure("shipwreck",{ place_on = {"group:sand","mcl_core:gravel"}, spawn_by = {"group:water"}, num_spawn_by = 4, - fill_ratio = 0.00002, - flags = "place_center_x, place_center_z, force_placement", + noise_params = { + offset = 0, + scale = 0.000022, + spread = {x = 250, y = 250, z = 250}, + seed = 3, + octaves = 3, + persist = 0.001, + flags = "absvalue", + }, + flags = "force_placement", biomes = ocean_biomes, y_max = water_level-4, y_min = mcl_vars.mg_overworld_min, diff --git a/mods/MAPGEN/mcl_structures/api.lua b/mods/MAPGEN/mcl_structures/api.lua index 2235d44053..b3d0491eea 100644 --- a/mods/MAPGEN/mcl_structures/api.lua +++ b/mods/MAPGEN/mcl_structures/api.lua @@ -43,7 +43,7 @@ function mcl_structures.register_structure(name,def,nospawn) --nospawn means it num_spawn_by = def.num_spawn_by, sidelen = 80, fill_ratio = def.fill_ratio, - noise = def.noise, + noise_params = def.noise_params, flags = flags, biomes = def.biomes, y_max = def.y_max, diff --git a/mods/MAPGEN/mcl_surface_pools/init.lua b/mods/MAPGEN/mcl_surface_pools/init.lua index 8dfa9ca400..ed42f52bbd 100644 --- a/mods/MAPGEN/mcl_surface_pools/init.lua +++ b/mods/MAPGEN/mcl_surface_pools/init.lua @@ -17,7 +17,7 @@ local function set_node_no_bedrock(pos,node) end local function airtower(pos) - for i=0,35 do + for i=0,55 do set_node_no_bedrock(vector.offset(pos,0,i,0),{name="air"}) end end @@ -69,7 +69,15 @@ end mcl_structures.register_structure("lavapool",{ place_on = {"group:sand", "group:dirt", "group:stone"}, - fill_ratio = 0.000015, + noise_params = { + offset = 0, + scale = 0.0000022, + spread = {x = 250, y = 250, z = 250}, + seed = 78375213, + octaves = 3, + persist = 0.001, + flags = "absvalue", + }, flags = "place_center_x, place_center_z, force_placement", y_max = mcl_vars.mg_overworld_max, y_min = minetest.get_mapgen_setting("water_level"), @@ -80,7 +88,15 @@ mcl_structures.register_structure("lavapool",{ mcl_structures.register_structure("water_lake",{ place_on = {"group:dirt","group:stone"}, - fill_ratio = 0.000052, + noise_params = { + offset = 0, + scale = 0.000032, + spread = {x = 250, y = 250, z = 250}, + seed = 734341353, + octaves = 3, + persist = 0.001, + flags = "absvalue", + }, flags = "place_center_x, place_center_z, force_placement", y_max = mcl_vars.mg_overworld_max, y_min = minetest.get_mapgen_setting("water_level"), From 92da429f50e3f674df63fdbd67dd08285ab600c2 Mon Sep 17 00:00:00 2001 From: cora Date: Wed, 15 Jun 2022 04:48:26 +0200 Subject: [PATCH 12/12] Fix chatcommand not under mcl_structures in /help --- mods/MAPGEN/mcl_structures/init.lua | 133 ++++++++++++++-------------- 1 file changed, 66 insertions(+), 67 deletions(-) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index a82dffbff7..ffc25d40c9 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -573,74 +573,73 @@ end dofile(modpath.."/api.lua") -minetest.register_on_mods_loaded(function() - -- Debug command - local chatcommand_params = "desert_temple | desert_well | igloo | witch_hut | boulder | ice_spike_small | ice_spike_large | fossil | end_exit_portal | end_exit_portal_open | end_gateway_portal | end_portal_shrine | nether_portal | dungeon" - - for n,_ in pairs(mcl_structures.registered_structures) do - chatcommand_params = chatcommand_params .. " | "..n - end - - minetest.register_chatcommand("spawnstruct", { - params = chatcommand_params, - description = S("Generate a pre-defined structure near your position."), - privs = {debug = true}, - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player then return end - local pos = player:get_pos() - if not pos then return end - pos = vector.round(pos) - local dir = minetest.yaw_to_dir(player:get_look_horizontal()) - local rot = dir_to_rotation(dir) - local pr = PseudoRandom(pos.x+pos.y+pos.z) - local errord = false - local message = S("Structure placed.") - if param == "desert_temple" then - mcl_structures.generate_desert_temple(pos, rot, pr) - elseif param == "desert_well" then - mcl_structures.generate_desert_well(pos, rot) - elseif param == "igloo" then - mcl_structures.generate_igloo(pos, rot, pr) - elseif param == "witch_hut" then - mcl_structures.generate_witch_hut(pos, rot, pr) - elseif param == "boulder" then - mcl_structures.generate_boulder(pos, rot, pr) - elseif param == "fossil" then - mcl_structures.generate_fossil(pos, rot, pr) - elseif param == "ice_spike_small" then - mcl_structures.generate_ice_spike_small(pos, rot, pr) - elseif param == "ice_spike_large" then - mcl_structures.generate_ice_spike_large(pos, rot, pr) - elseif param == "end_exit_portal" then - mcl_structures.generate_end_exit_portal(pos, rot, pr) - elseif param == "end_exit_portal_open" then - mcl_structures.generate_end_exit_portal_open(pos, rot, pr) - elseif param == "end_gateway_portal" then - mcl_structures.generate_end_gateway_portal(pos, rot, pr) - elseif param == "end_portal_shrine" then - mcl_structures.generate_end_portal_shrine(pos, rot, pr) - elseif param == "dungeon" and mcl_dungeons and mcl_dungeons.spawn_dungeon then - mcl_dungeons.spawn_dungeon(pos, rot, pr) - elseif param == "nether_portal" and mcl_portals and mcl_portals.spawn_nether_portal then - mcl_portals.spawn_nether_portal(pos, rot, pr, name) - elseif param == "" then - message = S("Error: No structure type given. Please use “/spawnstruct ”.") - errord = true - else - for n,d in pairs(mcl_structures.registered_structures) do - if n == param then - mcl_structures.place_structure(pos,d,pr) - return true,message - end +-- Debug command +minetest.register_chatcommand("spawnstruct", { + params = "desert_temple | desert_well | igloo | witch_hut | boulder | ice_spike_small | ice_spike_large | fossil | end_exit_portal | end_exit_portal_open | end_gateway_portal | end_portal_shrine | nether_portal | dungeon", + description = S("Generate a pre-defined structure near your position."), + privs = {debug = true}, + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then return end + local pos = player:get_pos() + if not pos then return end + pos = vector.round(pos) + local dir = minetest.yaw_to_dir(player:get_look_horizontal()) + local rot = dir_to_rotation(dir) + local pr = PseudoRandom(pos.x+pos.y+pos.z) + local errord = false + local message = S("Structure placed.") + if param == "desert_temple" then + mcl_structures.generate_desert_temple(pos, rot, pr) + elseif param == "desert_well" then + mcl_structures.generate_desert_well(pos, rot) + elseif param == "igloo" then + mcl_structures.generate_igloo(pos, rot, pr) + elseif param == "witch_hut" then + mcl_structures.generate_witch_hut(pos, rot, pr) + elseif param == "boulder" then + mcl_structures.generate_boulder(pos, rot, pr) + elseif param == "fossil" then + mcl_structures.generate_fossil(pos, rot, pr) + elseif param == "ice_spike_small" then + mcl_structures.generate_ice_spike_small(pos, rot, pr) + elseif param == "ice_spike_large" then + mcl_structures.generate_ice_spike_large(pos, rot, pr) + elseif param == "end_exit_portal" then + mcl_structures.generate_end_exit_portal(pos, rot, pr) + elseif param == "end_exit_portal_open" then + mcl_structures.generate_end_exit_portal_open(pos, rot, pr) + elseif param == "end_gateway_portal" then + mcl_structures.generate_end_gateway_portal(pos, rot, pr) + elseif param == "end_portal_shrine" then + mcl_structures.generate_end_portal_shrine(pos, rot, pr) + elseif param == "dungeon" and mcl_dungeons and mcl_dungeons.spawn_dungeon then + mcl_dungeons.spawn_dungeon(pos, rot, pr) + elseif param == "nether_portal" and mcl_portals and mcl_portals.spawn_nether_portal then + mcl_portals.spawn_nether_portal(pos, rot, pr, name) + elseif param == "" then + message = S("Error: No structure type given. Please use “/spawnstruct ”.") + errord = true + else + for n,d in pairs(mcl_structures.registered_structures) do + if n == param then + mcl_structures.place_structure(pos,d,pr) + return true,message end - message = S("Error: Unknown structure type. Please use “/spawnstruct ”.") - errord = true - end - minetest.chat_send_player(name, message) - if errord then - minetest.chat_send_player(name, S("Use /help spawnstruct to see a list of avaiable types.")) end + message = S("Error: Unknown structure type. Please use “/spawnstruct ”.") + errord = true end - }) + minetest.chat_send_player(name, message) + if errord then + minetest.chat_send_player(name, S("Use /help spawnstruct to see a list of avaiable types.")) + end + end +}) +minetest.register_on_mods_loaded(function() + local p = "" + for n,_ in pairs(mcl_structures.registered_structures) do + p = p .. " | "..n + end + minetest.registered_chatcommands["spawnstruct"].params = minetest.registered_chatcommands["spawnstruct"].params .. p end)