#204 Register all village schematics as structures

This commit is contained in:
kay27 2022-02-16 04:45:42 +04:00
parent c21f9b4c40
commit f61459ae89
2 changed files with 59 additions and 20 deletions

View File

@ -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

View File

@ -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