Spawn desert temples from seeds

This commit is contained in:
kay27 2022-01-14 04:25:39 +04:00
parent 9d171a6b7b
commit 096b384676
2 changed files with 156 additions and 92 deletions

View File

@ -67,16 +67,61 @@ end
--local chunk_has_desert_temple --local chunk_has_desert_temple
--local chunk_has_igloo --local chunk_has_igloo
mcl_structures.register_structure({
name = "desert_temple",
decoration = {
minetest.register_node("mcl_mapgen_core:desert_temple", { deco_type = "simple",
-- drawtype="airlike", place_on = {"mcl_core:sand", "mcl_core:sandstone"},
tiles = {"mcl_core_stonebrick_carved.png"}, flags = "all_floors",
groups = { fill_ratio = 0.001,
struct = 1, y_min = 5,
not_in_creative_inventory = 1, 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 local octaves = 3
@ -88,73 +133,9 @@ for i = 1, octaves do
local noise = 1 * (persistence ^ (i - 1)) local noise = 1 * (persistence ^ (i - 1))
max_noise = max_noise + noise max_noise = max_noise + noise
end end
max_noise = max_noise * octaves max_noise = max_noise * octaves
max_noise = offset + scale * max_noise 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) local function spawn_desert_temple(p, nn, pr, vm_context)
if p.y < 5 then return end if p.y < 5 then return end
if nn ~= "mcl_core:sand" and nn ~= "mcl_core:sandstone" 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 noise = perlin_structures:get_2d({x=x0, y=z0})
local amount local amount
if noise < 0 then if noise < 0 then
amount = math_ceil(noise * 9) amount = math_max(math_ceil(noise * 9), -9)
else else
amount = math_floor(noise * 9) amount = math_min(math_floor(noise * 9), 9)
end end
-- local amount = math_floor(perlin_structures:get_2d({x=x0, y=z0}) * 9) -- local amount = math_floor(perlin_structures:get_2d({x=x0, y=z0}) * 9)
local y1 = maxp.y - 9 + amount local y1 = maxp.y - 9 + amount
for x1 = x0, x0 + DIVLEN - 1, 1 do for z1 = z0, z0 + DIVLEN - 1, 1 do for x1 = x0, x0 + DIVLEN - 1, 1 do for z1 = z0, z0 + DIVLEN - 1, 1 do
if not levels[amount] then minetest.set_node({x=x1, y=y1, z=z1}, {name = "mcl_core:glass_"..levels[amount]})
minetest.log("ERROR",tostring(amount))
else
minetest.set_node({x=x1, y=y1, z=z1}, {name = "mcl_core:glass_"..levels[amount]})
end
end end end end
-- Find random positions based on this random -- Find random positions based on this random

View File

@ -3,33 +3,119 @@ local S = minetest.get_translator(modname)
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
mcl_structures = {} mcl_structures = {}
local rotations = { local rotations = {
"0", "0",
"90", "90",
"180", "180",
"270" "270"
} }
local registered_structures = {} 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) 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 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 return
end end
if registered_structures[name] then if registered_structures[name] then
minetest.log('warning', 'Structure '..name..' is already registered - owerwriting') minetest.log('warning', 'Structure '..name..' is already registered - owerwriting')
end 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] = { registered_structures[name] = {
on_place = def.on_place, on_place = def.on_place,
decoration = def.decoration, on_mapgen_prep = on_mapgen_prep,
on_mapgen_prep = def.on_mapgen_prep, on_generated = on_generated,
on_generated = def.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 end
-- It doesN'T remove registered node and decoration!
function mcl_structures.unregister_structure(name) function mcl_structures.unregister_structure(name)
if not registered_structures[name] then if not registered_structures[name] then
minetest.log('warning','Structure '..name..' is not registered - skipping') minetest.log('warning','Structure '..name..' is not registered - skipping')
@ -599,12 +685,13 @@ end
function mcl_structures.generate_desert_temple(pos, rotation, pr) function mcl_structures.generate_desert_temple(pos, rotation, pr)
-- No Generating for the temple ... Why using it ? No Change -- No Generating for the temple ... Why using it ? No Change
local path = modpath.."/schematics/mcl_structures_desert_temple.mts" 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} --local size = {x=22, y=24, z=22}
if newpos == nil then --if newpos == nil then
return -- return
end -- end
mcl_structures.place_schematic(newpos, path, rotation or "random", nil, true, nil, temple_placement_callback, pr) pos.y = pos.y - 12
mcl_structures.place_schematic({pos = pos, schematic = path, rotation = rotation or "random", pr = pr, emerge = true})
end end
local registered_structures = {} local registered_structures = {}