From 096b38467644e132548ac1588b546d83ef15859e Mon Sep 17 00:00:00 2001 From: kay27 Date: Fri, 14 Jan 2022 04:25:39 +0400 Subject: [PATCH] Spawn desert temples from seeds --- mods/MAPGEN/mcl_mapgen_core/structures.lua | 137 +++++++++------------ mods/MAPGEN/mcl_structures/init.lua | 111 +++++++++++++++-- 2 files changed, 156 insertions(+), 92 deletions(-) diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua index b18c31415..b000f77f4 100644 --- a/mods/MAPGEN/mcl_mapgen_core/structures.lua +++ b/mods/MAPGEN/mcl_mapgen_core/structures.lua @@ -67,16 +67,61 @@ end --local chunk_has_desert_temple --local chunk_has_igloo - - - -minetest.register_node("mcl_mapgen_core:desert_temple", { - -- drawtype="airlike", - tiles = {"mcl_core_stonebrick_carved.png"}, - groups = { - struct = 1, - not_in_creative_inventory = 1, +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 octaves = 3 @@ -88,73 +133,9 @@ for i = 1, octaves do local noise = 1 * (persistence ^ (i - 1)) max_noise = max_noise + noise end - max_noise = max_noise * octaves - max_noise = offset + scale * max_noise ---[[function structures.register_structure( - name, -- "desert_temple" - place_on, -- {"mcl_core:sand", "mcl_core:sandstone"} - flags, -- "all_floors" -]] - - -minetest.register_decoration({ - decoration = "mcl_mapgen_core:desert_temple", - deco_type = "simple", - place_on = {"mcl_core:sand", "mcl_core:sandstone"}, - flags = "all_floors", ---[[ noise_params = { - offset = offset, - scale = scale, - spread = { - x = 1, - y = 1, - z = 1, - }, - seed = 329, - octaves = octaves, - persistence = persistence, - lacunarity = 2.0, - flags = "eased", - }, - noise_threshold = 1000,-- * 0.9, -]] - 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", - }, -}) - ---minetest.register_lbm( --- name = "mcl_mapgen_core:process_struct_seed", --- nodenames = { --- "group:struct", --- } --- run_at_everly_load = true, --- action = function(pos, node) --- end, ---) - - local function spawn_desert_temple(p, nn, pr, vm_context) if p.y < 5 then return end if nn ~= "mcl_core:sand" and nn ~= "mcl_core:sandstone" then return end @@ -381,19 +362,15 @@ local levels = { local noise = perlin_structures:get_2d({x=x0, y=z0}) local amount if noise < 0 then - amount = math_ceil(noise * 9) + amount = math_max(math_ceil(noise * 9), -9) else - amount = math_floor(noise * 9) + amount = math_min(math_floor(noise * 9), 9) end -- local amount = math_floor(perlin_structures:get_2d({x=x0, y=z0}) * 9) local y1 = maxp.y - 9 + amount for x1 = x0, x0 + DIVLEN - 1, 1 do for z1 = z0, z0 + DIVLEN - 1, 1 do - if not levels[amount] then - minetest.log("ERROR",tostring(amount)) - else - minetest.set_node({x=x1, y=y1, z=z1}, {name = "mcl_core:glass_"..levels[amount]}) - end + minetest.set_node({x=x1, y=y1, z=z1}, {name = "mcl_core:glass_"..levels[amount]}) end end -- Find random positions based on this random diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index d54cd600f..3bea78cef 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -3,33 +3,119 @@ local S = minetest.get_translator(modname) local modpath = minetest.get_modpath(modname) mcl_structures = {} - local rotations = { "0", "90", "180", "270" } - local registered_structures = {} +local use_process_mapgen_block_lvm = false +local use_process_mapgen_chunk = false +local lvm_callbacks = {} +local chunk_callbacks = {} +function process_mapgen_block_lvm(vm_context) + local nodes = minetest.find_nodes_in_area(vm_context.minp, vm_context.maxp, {"group:struct"}, true) + -- if #nodes == 0 then return end + for node_name, pos_list in pairs(nodes) do + local lvm_callback = lvm_callbacks[node_name] + if lvm_callback then + lvm_callback(vm_context, pos_list) + end + end +end + +function process_mapgen_chunk(minp, maxp, seed, vm_context) + local nodes = minetest.find_nodes_in_area(minp, maxp, {"group:struct"}, true) + minetest.log("warning", "found " .. tostring(#nodes)) + -- if #nodes == 0 then return end + for node_name, pos_list in pairs(nodes) do + local chunk_callback = chunk_callbacks[node_name] + if chunk_callback then + chunk_callback(minp, maxp, seed, vm_context, pos_list) + end + end +end + +-------------------------------------------------------------------------------------- +-- mcl_structures.register_structure(struct_def) +-- struct_def: +-- name - name like 'desert_temple' +-- decoration - decoration definition if needed +-- on_mapgen_prep - callback if needed +-- on_generated - next callback if needed +-- on_place - placer function(pos, rotation, pr) +-- order_number - (optional) function mcl_structures.register_structure(def) - local name = def.name + local name = "mcl_structures:" .. def.name + local decoration = def.decoration + local on_mapgen_prep = def.on_mapgen_prep + local on_generated = def.on_generated if not name then - minetest.log('warning', 'Structure name is not passed for registering - ignoring') + minetest.log('warning', 'Structure name is not passed for registration - ignoring') return end if registered_structures[name] then minetest.log('warning', 'Structure '..name..' is already registered - owerwriting') end + local decoration_id + if decoration then + minetest.register_node(':' .. name, { + -- drawtype="airlike", + groups = { + struct = 1, + not_in_creative_inventory = 1, + }, + }) + decoration_id = minetest.register_decoration({ + deco_type = decoration.deco_type, + place_on = decoration.place_on, + sidelen = decoration.sidelen, + fill_ratio = decoration.fill_ratio, + noise_params = decoration.noise_params, + biomes = decoration.biomes, + y_min = decoration.y_min, + y_max = decoration.y_max, + spawn_by = decoration.spawn_by, + num_spawn_by = decoration.num_spawn_by, + flags = decoration.flags, + decoration = name, + height = decoration.height, + height_max = decoration.height_max, + param2 = decoration.param2, + param2_max = decoration.param2_max, + place_offset_y = decoration.place_offset_y, + schematic = decoration.schematic, + replacements = decoration.replacements, + flags = decoration.flags, + rotation = decoration.rotation, + }) + end registered_structures[name] = { on_place = def.on_place, - decoration = def.decoration, - on_mapgen_prep = def.on_mapgen_prep, - on_generated = def.on_generated, + on_mapgen_prep = on_mapgen_prep, + on_generated = on_generated, + decoration_id = decoration_id, } + if on_mapgen_prep then + lvm_callbacks[name] = on_mapgen_prep + if not use_process_mapgen_block_lvm then + use_process_mapgen_block_lvm = true + mcl_mapgen.register_mapgen_block_lvm(process_mapgen_block_lvm, mcl_mapgen.order.BUILDINGS) + end + end + if on_generated then + minetest.log("warning", "GERISTERED!!!") + chunk_callbacks[name] = on_generated + if not use_process_mapgen_chunk then + use_process_mapgen_chunk = true + mcl_mapgen.register_mapgen(process_mapgen_chunk, mcl_mapgen.order.BUILDINGS) + end + end end +-- It doesN'T remove registered node and decoration! function mcl_structures.unregister_structure(name) if not registered_structures[name] then minetest.log('warning','Structure '..name..' is not registered - skipping') @@ -599,12 +685,13 @@ end function mcl_structures.generate_desert_temple(pos, rotation, pr) -- No Generating for the temple ... Why using it ? No Change local path = modpath.."/schematics/mcl_structures_desert_temple.mts" - local newpos = {x=pos.x,y=pos.y-12,z=pos.z} + --local newpos = {x=pos.x,y=pos.y-12,z=pos.z} --local size = {x=22, y=24, z=22} - if newpos == nil then - return - end - mcl_structures.place_schematic(newpos, path, rotation or "random", nil, true, nil, temple_placement_callback, pr) + --if newpos == nil then + -- return + -- end + pos.y = pos.y - 12 + mcl_structures.place_schematic({pos = pos, schematic = path, rotation = rotation or "random", pr = pr, emerge = true}) end local registered_structures = {}