From 37725cc1dcab0b705a418e3b9b18f300ad27da21 Mon Sep 17 00:00:00 2001 From: kay27 Date: Sat, 15 Jan 2022 20:32:48 +0400 Subject: [PATCH] Refactor desert temples and structs in general (unfinished) --- mods/MAPGEN/mcl_mapgen_core/structures.lua | 113 ------------------- mods/MAPGEN/mcl_structures/desert_temple.lua | 86 ++++++++++++++ mods/MAPGEN/mcl_structures/init.lua | 4 +- mods/MAPGEN/mcl_structures/structures.lua | 4 + 4 files changed, 93 insertions(+), 114 deletions(-) create mode 100644 mods/MAPGEN/mcl_structures/desert_temple.lua create mode 100644 mods/MAPGEN/mcl_structures/structures.lua diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua index f265e5e74..5f751db50 100644 --- a/mods/MAPGEN/mcl_mapgen_core/structures.lua +++ b/mods/MAPGEN/mcl_mapgen_core/structures.lua @@ -69,119 +69,6 @@ end --local chunk_has_desert_temple --local chunk_has_igloo -mcl_structures.register_structure({ - name = "desert_temple", - decoration = { - deco_type = "simple", - place_on = {"mcl_core:sand", "mcl_core:sandstone"}, - flags = "all_floors", - fill_ratio = 0.001, - y_min = 5, - y_max = mcl_mapgen.overworld.max, - height = 1, - biomes = { - "ColdTaiga_beach", - "ColdTaiga_beach_water", - "Desert", - "Desert_ocean", - "ExtremeHills_beach", - "FlowerForest_beach", - "Forest_beach", - "MesaBryce_sandlevel", - "MesaPlateauF_sandlevel", - "MesaPlateauFM_sandlevel", - "Savanna", - "Savanna_beach", - "StoneBeach", - "StoneBeach_ocean", - "Taiga_beach", - }, - }, - on_generated = function(minp, maxp, seed, vm_context, pos_list) - local aaa = '' - for _, p in pairs(pos_list) do - if aaa ~= '' then - aaa = aaa .. ', ' - end - aaa = aaa .. minetest.pos_to_string(p) - end - minetest.chat_send_all('generated ' .. minetest.pos_to_string(minp) .. " ... " .. minetest.pos_to_string(maxp) .. ", pos_list = " .. aaa) - local y = 0 - local temple_pos - for _, pos in pairs(pos_list) do - if pos.y > y then - if temple_pos then - minetest.swap_node(temple_pos, {name = 'mcl_core:deadbush'}) - end - temple_pos = pos - y = pos.y - else - minetest.swap_node(pos, {name = 'mcl_core:deadbush'}) - end - end - minetest.chat_send_all('here: ' .. minetest.pos_to_string(temple_pos)) - if not temple_pos then return end - -- if pr:next(1,12000) ~= 1 then return end - mcl_structures.call_struct(temple_pos, "desert_temple", nil, PseudoRandom(vm_context.chunkseed)) - end, -}) - -local red_temple_schematic_file = schematic_path .. "/schematics/mcl_structures_desert_temple.mts" -local red_temple_schematic_lua = minetest.serialize_schematic(red_temple_schematic_file, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic" -red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_colorblocks:hardened_clay_orange", "mcl_colorblocks:hardened_clay_red") -red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_core:sand_stone", "mcl_colorblocks:hardened_clay_orange") -red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_core:redsand", "mcl_core:granit") -red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_core:sand", "mcl_core:redsand") -red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_stairs:stair_sandstone", "mcl_stairs:stair_redsandstone") -red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_stairs:slab_sandstone", "mcl_stairs:slab_redsandstone") -red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_colorblocks:hardened_clay_yellow", "mcl_colorblocks:hardened_clay_pink") -local red_temple_schematic = loadstring(red_temple_schematic_lua)() -mcl_structures.register_structure({ - name = "red_desert_temple", - decoration = { - deco_type = "simple", - place_on = {"mcl_core:redsand", "mcl_colorblocks:hardened_clay_orange"}, - flags = "all_floors", - fill_ratio = 0.001, - y_min = 3, - y_max = mcl_mapgen.overworld.max, - height = 1, - biomes = { - "ColdTaiga_beach", - "ColdTaiga_beach_water", - "Desert", - "Desert_ocean", - "ExtremeHills_beach", - "FlowerForest_beach", - "Forest_beach", - "MesaBryce_sandlevel", - "MesaPlateauF_sandlevel", - "MesaPlateauFM_sandlevel", - "Savanna", - "Savanna_beach", - "StoneBeach", - "StoneBeach_ocean", - "Taiga_beach", - }, - }, - on_generated = function(minp, maxp, seed, vm_context, pos_list) - local y = 0 - local temple_pos - for _, pos in pairs(pos_list) do - if pos.y > y then - temple_pos = pos - y = pos.y - end - end - minetest.chat_send_all('here2: ' .. minetest.pos_to_string(temple_pos)) - if not temple_pos then return end - -- if pr:next(1,12000) ~= 1 then return end - minetest.swap_node(temple_pos, {name="air"}) - temple_pos.y = temple_pos.y - 12 - mcl_structures.place_schematic({pos = temple_pos, schematic = red_temple_schematic, pr = PseudoRandom(vm_context.chunkseed)}) - end, -}) - local octaves = 3 local persistence = 0.6 local offset = 0 diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua new file mode 100644 index 000000000..c0dbd3ca8 --- /dev/null +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -0,0 +1,86 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +local schematic_file = modpath .. "/schematics/mcl_structures_desert_temple.mts" + +local temple_schematic_lua = minetest.serialize_schematic(schematic_file, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic" +local temple_schematic = loadstring(temple_schematic_lua)() + +local red_temple_schematic_lua = minetest.serialize_schematic(schematic_file, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic" +red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_colorblocks:hardened_clay_orange", "mcl_colorblocks:hardened_clay_red") +red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_core:sand_stone", "mcl_colorblocks:hardened_clay_orange") +red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_core:sand", "mcl_core:redsand") +red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_stairs:stair_sandstone", "mcl_stairs:stair_redsandstone") +red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_stairs:slab_sandstone", "mcl_stairs:slab_redsandstone") +red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_colorblocks:hardened_clay_yellow", "mcl_colorblocks:hardened_clay_pink") +local red_temple_schematic = loadstring(red_temple_schematic_lua)() + +function place(pos, rotation, pr) + local pos_below = {x = pos.x, y = pos.y - 1, z = pos.z} + local pos_temple = {x = pos.x, y = pos.y - 12, z = pos.z} + local node_below = minetest.get_node(pos_below) + local nn = node_below.name + if string.find(nn, "red") then + mcl_structures.place_schematic({pos = pos_temple, schematic = red_temple_schematic, pr = pr}) + else + mcl_structures.place_schematic({pos = pos_temple, schematic = temple_schematic, pr = pr}) + end +end + +local node_list = {"mcl_core:sand", "mcl_core:sandstone", "mcl_core:redsand", "mcl_colorblocks:hardened_clay_orange"} + +local function node_counter(pos) + local pos_list = minetest.find_nodes_in_area( + {x = pos.x + 1, y = pos.y - 1, z = pos.z + 1}, + {x = pos.x + 20, y = pos.y - 1, z = pos.z + 20}, + node_list, false + ) + return #pos_list +end + +mcl_structures.register_structure({ + name = "desert_temple", + decoration = { + deco_type = "simple", + place_on = node_list, + flags = "all_floors", + fill_ratio = 0.00001, + y_min = 3, + y_max = mcl_mapgen.overworld.max, + height = 1, + biomes = { + "ColdTaiga_beach", + "ColdTaiga_beach_water", + "Desert", + "Desert_ocean", + "ExtremeHills_beach", + "FlowerForest_beach", + "Forest_beach", + "MesaBryce_sandlevel", + "MesaPlateauF_sandlevel", + "MesaPlateauFM_sandlevel", + "Savanna", + "Savanna_beach", + "StoneBeach", + "StoneBeach_ocean", + "Taiga_beach", + }, + }, + on_generated = function(minp, maxp, seed, vm_context, pos_list) + local pos = pos_list[1] + if #pos_list > 1 then + local count = node_counter(pos) + for i = 2, #pos_list do + local pos_i = pos_list[i] + local count_i = node_counter(pos_i) + if count_i > count then + count = count_i + pos = pos_i + end + end + end + local pr = PseudoRandom(vm_context.chunkseed) + place(pos, nil, pr) + end, + on_place = place, +}) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index b48c7cbda..7bdc72f8a 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -68,7 +68,7 @@ function mcl_structures.register_structure(def) local decoration_id if decoration then minetest.register_node(':' .. name, { - -- drawtype="airlike", + drawtype="airlike", groups = { struct = 1, not_in_creative_inventory = 1, @@ -810,3 +810,5 @@ minetest.register_chatcommand("spawnstruct", { end end }) + +dofile(modpath .. "/structures.lua") diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua new file mode 100644 index 000000000..4039ef6e1 --- /dev/null +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -0,0 +1,4 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +dofile(modpath .. "/desert_temple.lua")