From f61459ae8979febbd32604dcf86b32da289fcff8 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 16 Feb 2022 04:45:42 +0400 Subject: [PATCH] #204 Register all village schematics as structures --- mods/CORE/mcl_mapgen/init.lua | 22 ++++++++++-- mods/MAPGEN/mcl_villages/init.lua | 57 +++++++++++++++++++++---------- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index bc390e597..f24d76880 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -505,11 +505,29 @@ function mcl_mapgen.clamp_to_chunk(x, size) end function mcl_mapgen.get_chunk_beginning(x) - return x - ((x + central_chunk_min_pos) % CS_NODES) + if tonumber(x) then + return x - ((x + central_chunk_min_pos) % CS_NODES) + end + if x.x then + return { + x = mcl_mapgen.get_chunk_beginning(x.x), + y = mcl_mapgen.get_chunk_beginning(x.y), + z = mcl_mapgen.get_chunk_beginning(x.z) + } + end end function mcl_mapgen.get_chunk_ending(x) - return mcl_mapgen.get_chunk_beginning(x) + LAST_NODE_IN_CHUNK + if tonumber(x) then + return mcl_mapgen.get_chunk_beginning(x) + LAST_NODE_IN_CHUNK + end + if x.x then + return { + x = mcl_mapgen.get_chunk_beginning(x.x) + LAST_NODE_IN_CHUNK, + y = mcl_mapgen.get_chunk_beginning(x.y) + LAST_NODE_IN_CHUNK, + z = mcl_mapgen.get_chunk_beginning(x.z) + LAST_NODE_IN_CHUNK + } + end end mcl_mapgen.get_block_seed = get_block_seed diff --git a/mods/MAPGEN/mcl_villages/init.lua b/mods/MAPGEN/mcl_villages/init.lua index 022f0ae73..6f9cca5ab 100644 --- a/mods/MAPGEN/mcl_villages/init.lua +++ b/mods/MAPGEN/mcl_villages/init.lua @@ -7,7 +7,7 @@ local chance_per_chunk = 1 local noise_multiplier = 1 local random_offset = 1 local random_multiply = 19 -local struct_threshold = chance_per_chunk -- 1 +local struct_threshold = chance_per_chunk - 1 local noise_params = { offset = 0, scale = 2, @@ -39,23 +39,6 @@ local schematic_table = { {name = "tavern", mts = schem_path.."tavern.mts", max_num = 0.050, rplc = basic_pseudobiome_villages }, {name = "well", mts = schem_path.."well.mts", max_num = 0.045, rplc = basic_pseudobiome_villages }, } -for k, v in pairs(schematic_table) do - local schem_lua = minetest.serialize_schematic( - v.mts, - "lua", - { - lua_use_comments = false, - lua_num_indent_spaces = 0, - } - ):gsub("mcl_core:stonebrickcarved", "mcl_villages:stonebrickcarved") .. " return schematic" - v.preloaded_schematic = schem_lua - local loaded_schematic = loadstring(schem_lua)() - local size = loaded_schematic.size - v.hwidth = size.x - v.hheight = size.y - v.hdepth = size.z - v.hsize = math.ceil(math.sqrt((size.x/2)^2 + (size.y/2)^2) * 2 + 1) -end local surface_mat = { ["mcl_core:dirt_with_dry_grass"] = { top = "mcl_core:dirt", bottom = "mcl_core:stone" }, ["mcl_core:dirt_with_grass"] = { top = "mcl_core:dirt", bottom = "mcl_core:stone" }, @@ -453,6 +436,44 @@ if mg_name ~= "singlenode" then end, mcl_mapgen.order.VILLAGES) end +for k, v in pairs(schematic_table) do + local schem_lua = minetest.serialize_schematic( + v.mts, + "lua", + { + lua_use_comments = false, + lua_num_indent_spaces = 0, + } + ):gsub("mcl_core:stonebrickcarved", "mcl_villages:stonebrickcarved") .. " return schematic" + v.preloaded_schematic = schem_lua + local loaded_schematic = loadstring(schem_lua)() + local size = loaded_schematic.size + v.hwidth = size.x + v.hheight = size.y + v.hdepth = size.z + v.hsize = math.ceil(math.sqrt((size.x/2)^2 + (size.y/2)^2) * 2 + 1) + mcl_structures.register_structure({ + name = v.name, + place_function = function(pos, rotation, pr, placer) + local minp = mcl_mapgen.get_chunk_beginning(pos) + local maxp = mcl_mapgen.get_chunk_ending(pos) + local surface_pos, surface_material = find_surface(pos, minp, maxp) + local plan = { + [1] = { + pos = pos, + building = schematic_table[k], + rotation = rotation, + surface_mat = surface_material or "mcl_core:snow", + } + } + if surface_material then + terraform(plan, minp, maxp, pr) + end + place_schematics(plan, pr) + end + }) +end + function mcl_villages.get_villages() return villages end