From 49ac211f87ebd104cea33794a1c51b8618c6c272 Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 25 Apr 2021 23:31:52 +0400 Subject: [PATCH 01/61] [mapgen] Add undebugged `CORE/mcl_mapgen` mod for further integration --- mods/CORE/mcl_mapgen/API.md | 54 +++++++++++++ mods/CORE/mcl_mapgen/init.lua | 146 ++++++++++++++++++++++++++++++++++ mods/CORE/mcl_mapgen/mod.conf | 4 + 3 files changed, 204 insertions(+) create mode 100644 mods/CORE/mcl_mapgen/API.md create mode 100644 mods/CORE/mcl_mapgen/init.lua create mode 100644 mods/CORE/mcl_mapgen/mod.conf diff --git a/mods/CORE/mcl_mapgen/API.md b/mods/CORE/mcl_mapgen/API.md new file mode 100644 index 000000000..364bc3205 --- /dev/null +++ b/mods/CORE/mcl_mapgen/API.md @@ -0,0 +1,54 @@ +# mcl_mapgen +============ +This mod helps to avoid problems caused by Minetest's 'chunk-in-shell' feature of mapgen.cpp. +It also queues your generators to run them in proper order. + + +========================================================================= +## mcl_mapgen.register_chunk_generator(chunk_callback_function, priority) +========================================================================= +UNSAFE! See below. Registers callback function to be called when current chunk generation is finished. + `callback_function`: chunk callback function definition, see below; + `priority`: order number - the less, the earlier. +### Chunk callback function definition: + `function(minp, maxp, seed)`: + `minp` & `maxp`: minimum and maximum chunk position; + `seed`: seed of this mapchunk. + + +======================================================================= +## mcl_mapgen.register_chunk_generator_lvm(callback_function, priority) +======================================================================= +UNSAFE! See below. Registers callback function to be called when current chunk generation is finished. +`vm_context` passes into callback function and should be returned back. + `callback_function`: chunk callback LVM function definition, see below; + `priority`: order number - the less, the earlier. +### Chunk callback LVM function definition: + Function MUST RETURN `vm_context`. It passes into next callback function from the queue. + `function(vm_context)`: + `vm_context` is a table which already contains some LVM data and some of them can be added in callback function: + `minp` & `maxp`: minimum and maximum chunk position; + `seed`: seed of this mapchunk. + + +=================================================================== +## mcl_mapgen.register_block_generator(callback_function, priority) +=================================================================== +Registers callback function to be called when block (usually 16x16x16 nodes) generation is finished. + `callback_function`: block callback function definition, see below; + `priority`: order number - the less, the earlier. + + +======================================================================= +## mcl_mapgen.register_block_generator_lvm(callback_function, priority) +======================================================================= +Registers callback function to be called when block (usually 16x16x16 nodes) generation is finished. +`vm_context` passes into callback function and should be returned back. + `callback_function`: block callback LVM function definition, see below; + `priority`: order number - the less, the earlier. + + +=============================== +## mcl_mapgen.get_far_node(pos) +=============================== +Returns node if it is generated. Otherwise returns `{name = "ignore"}`. diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua new file mode 100644 index 000000000..2572ce442 --- /dev/null +++ b/mods/CORE/mcl_mapgen/init.lua @@ -0,0 +1,146 @@ +mcl_mapgen = {} + +local lvm_block_queue, lvm_chunk_queue, node_block_queue, node_chunk_queue = {}, {}, {}, {} -- Generators' queues +local lvm, block, lvm_block, lvm_chunk, param2, nodes_block, nodes_chunk = 0, 0, 0, 0, 0, 0 -- Requirements: 0 means none; greater than 0 means 'required' +local lvm_buffer, lvm_param2_buffer = {}, {} -- Static buffer pointers +local BS, CS = mcl_vars.MAP_BLOCKSIZE, mcl_vars.chunksize -- Mapblock size (in nodes), Mapchunk size (in blocks) +local LAST_BLOCK, LAST_NODE = CS - 1, BS - 1 -- First mapblock in chunk (node in mapblock) has number 0, last has THIS number. It's for runtime optimization +local offset = math.floor(mcl_vars.central_chunk_offset_in_nodes / BS) -- Central mapchunk offset (in blocks) + +local DEFAULT_PRIORITY = 5000 + +local minetest_log, math_floor = minetest.log, math.floor + +function mcl_mapgen.register_chunk_generator(callback_function, priority) + nodes_chunk = nodes_chunk + 1 + node_chunk_queue[nodes_chunk] = {i = priority or DEFAULT_PRIORITY, f = callback_function} + table.sort(node_chunk_queue, function(a, b) return (a.i <= b.i) end) +end +function mcl_mapgen.register_chunk_generator_lvm(callback_function, priority) + lvm = lvm + 1 + lvm_chunk_queue[lvm_chunk] = {i = priority or DEFAULT_PRIORITY, f = callback_function} + table.sort(lvm_chunk_queue, function(a, b) return (a.i <= b.i) end) +end +function mcl_mapgen.register_block_generator(callback_function, priority) + block = block + 1 + nodes_block = nodes_block + 1 + node_block_queue[nodes_block] = {i = priority or DEFAULT_PRIORITY, f = callback_function} + table.sort(node_block_queue, function(a, b) return (a.i <= b.i) end) +end +function mcl_mapgen.register_block_generator_lvm(callback_function, priority) + block = block + 1 + lvm = lvm + 1 + lvm_block = lvm_block + 1 + lvm_block_queue[lvm_block] = {i = priority or DEFAULT_PRIORITY, f = callback_function} + table.sort(lvm_block_queue, function(a, b) return (a.i <= b.i) end) +end + + +local blocks = minetest.deserialize( storage:get_string("mapgen_blocks") or "return {}") or {} +minetest.register_on_shutdown(function() storage:set_string("mapgen_blocks", minetest.serialize(blocks)) end) + +local vm_context-- here will be many references and flags, like: param2, light_data, heightmap, biomemap, heatmap, humiditymap, gennotify, write_lvm, write_param2, shadow +local data, data2, area +local current_blocks = {} + +minetest.register_on_generated(function(minp, maxp, blockseed) + local minp, maxp, blockseed = minp, maxp, blockseed + minetest_log("verbose", "[mcl_mapgen] New chunk: minp=" .. minetest.pos_to_string(minp) .. ", maxp=" .. minetest.pos_to_string(maxp) .. ", blockseed=" .. blockseed) + + local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") + + if lvm > 0 then + vm_context = {lvm_param2_buffer = lvm_param2_buffer, vm = vm, emin = emin, emax = emax, minp = minp, maxp = maxp, blockseed = blockseed} + data = vm:get_data(lvm_buffer) + vm_context.data = data + area = VoxelArea:new({MinEdge=emin, MaxEdge=emax}) + vm_context.area = area + for _, v in pairs(lvm_chunk_queue) do + vm_context = v.f(vm_context) + end + end + + if block > 0 then + local x0, y0, z0 = minp.x, minp.y, minp.z + local bx0, by0, bz0 = math_floor(x0/BS), math_floor(y0/BS), math_floor(z0/BS) + local x1, y1, z1, x2, y2, z2 = emin.x, emin.y, emin.z, emax.x, emax.y, emax.z + local x, y, z = x1, y1, z1 -- iterate 7x7x7 mapchunk, {x,y,z} - first node pos. of mapblock + local bx, by, bz -- block coords (in blocs) + local box, boy, boz -- block offsets in chunks (in blocks) + while x < x2 do + bx = math_floor(x/BS) + local block_pos_offset_removed = bx - offset + box = block_pos_offset_removed % CS + if not blocks[bx] then blocks[bx]={} end + local total_mapgen_block_writes_through_x = (box > 0 and box < LAST_BLOCK) and 4 or 8 + while y < y2 do + by = math_floor(y/BS) + block_pos_offset_removed = by - offset + boy = block_pos_offset_removed % CS + if not blocks[bx][by] then blocks[bx][by]={} end + local total_mapgen_block_writes_through_y = (boy > 0 and boy < LAST_BLOCK) and math_floor(total_mapgen_block_writes_through_x / 2) or total_mapgen_block_writes_through_x + while z < z2 do + bz = math_floor(z/BS) + block_pos_offset_removed = bz - offset + boz = block_pos_offset_removed % CS + local total_mapgen_block_writes = (boz > 0 and boz < LAST_BLOCK) and math_floor(total_mapgen_block_writes_through_y / 2) or total_mapgen_block_writes_through_y + local current_mapgen_block_writes = blocks[bx][by][bz] and (blocks[bx][by][bz] + 1) or 1 + if current_mapgen_block_writes == total_mapgen_block_writes then + -- this block shouldn't be overwritten anymore, no need to keep it in memory + blocks[bx][by][bz] = nil + vm_context.seed = blockseed + box * 7 + boy * 243 + boz * 11931 + if lvm_block > 0 then + vm_context.minp, vm_content.maxp = {x=x, y=y, z=z}, {x=x+LAST_NODE, y=y+LAST_NODE, z=z+LAST_NODE} + for _, v in pairs(lvm_block_queue) do + vm_context = v.f(vm_context) + end + end + if nodes_block > 0 then + current_blocks[#current_blocks+1] = { minp = {x=x, y=y, z=z}, maxp = {x=pos.x+LAST_NODE, y=pos.y+LAST_NODE, z=pos.z+LAST_NODE}, seed = seed } + end + else + blocks[bx][by][bz] = current_mapgen_block_writes + end + z = z + BS + end + if next(blocks[bx][by]) == nil then blocks[bx][by] = nil end + z = z1 + y = y + BS + end + if next(blocks[bx]) == nil then blocks[bx] = nil end + y = y1 + x = x + BS + end + end + + if vm_context.write then + vm:set_data(data) + end + if vm_context.write_param2 then + vm:set_param2_data(data2) + end + vm:calc_lighting(p1, p2, shadow) + vm:write_to_map() + vm:update_liquids() + + for _, v in pairs(node_chunk_queue) do + v.f(minp, maxp, blockseed) + end + + for i, b in pairs(current_blocks) do + for _, v in pairs(node_block_queue) do + v.f(b.minp, b.maxp, b.seed) + end + current_blocks[id] = nil + end +end) + +minetest.register_on_generated = mcl_mapgen.register_chunk_generator + +function mcl_mapgen.get_far_node(p) + local p = p + local node = minetest_get_node(p) + if node.name ~= "ignore" then return node end + minetest_get_voxel_manip():read_from_map(p, p) + return minetest_get_node(p) +end diff --git a/mods/CORE/mcl_mapgen/mod.conf b/mods/CORE/mcl_mapgen/mod.conf new file mode 100644 index 000000000..4f896b3cf --- /dev/null +++ b/mods/CORE/mcl_mapgen/mod.conf @@ -0,0 +1,4 @@ +name = mcl_mapgen +author = kay27 +description = MineClone 2 MapGen Basic Stuff +depends = mcl_init From abc3a1f13928c75864afc5b3d4e033e20333fe44 Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 26 Apr 2021 03:35:54 +0400 Subject: [PATCH 02/61] [mapgen] To be continued... (this version won't run) --- mods/CORE/mcl_mapgen/init.lua | 4 +- mods/MAPGEN/mcl_mapgen_core/init.lua | 104 +++------------------------ mods/MAPGEN/mcl_mapgen_core/mod.conf | 2 +- 3 files changed, 11 insertions(+), 99 deletions(-) diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 2572ce442..f6bb8fa08 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -1,7 +1,7 @@ mcl_mapgen = {} local lvm_block_queue, lvm_chunk_queue, node_block_queue, node_chunk_queue = {}, {}, {}, {} -- Generators' queues -local lvm, block, lvm_block, lvm_chunk, param2, nodes_block, nodes_chunk = 0, 0, 0, 0, 0, 0 -- Requirements: 0 means none; greater than 0 means 'required' +local lvm, block, lvm_block, lvm_chunk, param2, nodes_block, nodes_chunk = 0, 0, 0, 0, 0, 0, 0 -- Requirements: 0 means none; greater than 0 means 'required' local lvm_buffer, lvm_param2_buffer = {}, {} -- Static buffer pointers local BS, CS = mcl_vars.MAP_BLOCKSIZE, mcl_vars.chunksize -- Mapblock size (in nodes), Mapchunk size (in blocks) local LAST_BLOCK, LAST_NODE = CS - 1, BS - 1 -- First mapblock in chunk (node in mapblock) has number 0, last has THIS number. It's for runtime optimization @@ -35,7 +35,7 @@ function mcl_mapgen.register_block_generator_lvm(callback_function, priority) table.sort(lvm_block_queue, function(a, b) return (a.i <= b.i) end) end - +local storage = minetest.get_mod_storage() local blocks = minetest.deserialize( storage:get_string("mapgen_blocks") or "return {}") or {} minetest.register_on_shutdown(function() storage:set_string("mapgen_blocks", minetest.serialize(blocks)) end) diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 90b272506..f46d303fd 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1,8 +1,4 @@ mcl_mapgen_core = {} -local registered_generators = {} - -local lvm, nodes, param2 = 0, 0, 0 -local lvm_buffer = {} -- -- Aliases for map generator outputs @@ -1194,11 +1190,14 @@ local perlin_structures local perlin_vines, perlin_vines_fine, perlin_vines_upwards, perlin_vines_length, perlin_vines_density local perlin_clay -local function generate_clay(minp, maxp, blockseed, voxelmanip_data, voxelmanip_area, lvm_used) +-- Generate Clay +mcl_mapgen.register_chunk_generator_lvm(function(c) + local minp, maxp, blockseed, voxelmanip_data, voxelmanip_area, lvm_used = c.minp, c.maxp, c.blockseed, c.data, c.area, c.write or false -- TODO: Make clay generation reproducible for same seed. if maxp.y < -5 or minp.y > 0 then - return lvm_used + return c end + minetest.log("warning", "CLAY!") local pr = PseudoRandom(blockseed) @@ -1244,8 +1243,9 @@ local function generate_clay(minp, maxp, blockseed, voxelmanip_data, voxelmanip_ end end end - return lvm_used -end + c.write = lvm_used + return c +end) local function generate_end_exit_portal(pos) local dragon_entity = minetest.add_entity(vector.add(pos, vector.new(3, 11, 3)), "mobs_mc:enderdragon"):get_luaentity() @@ -1814,94 +1814,6 @@ local generate_nether_decorations = function(minp, maxp, seed) end -minetest.register_on_generated(function(minp, maxp, blockseed) - minetest.log("action", "[mcl_mapgen_core] Generating chunk " .. minetest.pos_to_string(minp) .. " ... " .. minetest.pos_to_string(maxp)) - local p1, p2 = {x=minp.x, y=minp.y, z=minp.z}, {x=maxp.x, y=maxp.y, z=maxp.z} - if lvm > 0 then - local lvm_used, shadow = false, false - local lb2 = {} -- param2 - local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") - local e1, e2 = {x=emin.x, y=emin.y, z=emin.z}, {x=emax.x, y=emax.y, z=emax.z} - local data2 - local data = vm:get_data(lvm_buffer) - if param2 > 0 then - data2 = vm:get_param2_data(lb2) - end - local area = VoxelArea:new({MinEdge=e1, MaxEdge=e2}) - - for _, rec in pairs(registered_generators) do - if rec.vf then - local lvm_used0, shadow0 = rec.vf(vm, data, data2, e1, e2, area, p1, p2, blockseed) - if lvm_used0 then - lvm_used = true - end - if shadow0 then - shadow = true - end - end - end - - if lvm_used then - -- Write stuff - vm:set_data(data) - if param2 > 0 then - vm:set_param2_data(data2) - end - vm:calc_lighting(p1, p2, shadow) - vm:write_to_map() - vm:update_liquids() - end - end - - if nodes > 0 then - for _, rec in pairs(registered_generators) do - if rec.nf then - rec.nf(p1, p2, blockseed) - end - end - end - - mcl_vars.add_chunk(minp) -end) - -minetest.register_on_generated=function(node_function) - mcl_mapgen_core.register_generator("mod_"..tostring(#registered_generators+1), nil, node_function) -end - -function mcl_mapgen_core.register_generator(id, lvm_function, node_function, priority, needs_param2) - if not id then return end - - local priority = priority or 5000 - - if lvm_function then lvm = lvm + 1 end - if lvm_function then nodes = nodes + 1 end - if needs_param2 then param2 = param2 + 1 end - - local new_record = { - i = priority, - vf = lvm_function, - nf = node_function, - needs_param2 = needs_param2, - } - - registered_generators[id] = new_record - table.sort( - registered_generators, - function(a, b) - return (a.i < b.i) or ((a.i == b.i) and (a.vf ~= nil) and (b.vf == nil)) - end) -end - -function mcl_mapgen_core.unregister_generator(id) - if not registered_generators[id] then return end - local rec = registered_generators[id] - registered_generators[id] = nil - if rec.vf then lvm = lvm - 1 end - if rec.nf then nodes = nodes - 1 end - if rec.needs_param2 then param2 = param2 - 1 end - if rec.needs_level0 then level0 = level0 - 1 end -end - -- Generate basic layer-based nodes: void, bedrock, realm barrier, lava seas, etc. -- Also perform some basic node replacements. diff --git a/mods/MAPGEN/mcl_mapgen_core/mod.conf b/mods/MAPGEN/mcl_mapgen_core/mod.conf index 9f7d9ebaa..2ea3e45bb 100644 --- a/mods/MAPGEN/mcl_mapgen_core/mod.conf +++ b/mods/MAPGEN/mcl_mapgen_core/mod.conf @@ -1,5 +1,5 @@ name = mcl_mapgen_core author = Wuzzy description = The core of the MCL2 mapgen -depends = mcl_init, mcl_core, biomeinfo, mcl_worlds, mcl_cocoas, mcl_sponges, mcl_ocean, mcl_stairs, mcl_monster_eggs, mcl_structures +depends = mcl_mapgen, mcl_core, biomeinfo, mcl_worlds, mcl_cocoas, mcl_sponges, mcl_ocean, mcl_stairs, mcl_monster_eggs, mcl_structures optional_depends = mclx_core From 942d70ee623a9c5c66b451e8779d294dfdf90cd7 Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 26 Apr 2021 04:09:14 +0400 Subject: [PATCH 03/61] [mapgen] temporarily delay chorus nodes grow --- mods/MAPGEN/mcl_biomes/init.lua | 11 ++++++----- mods/MAPGEN/mcl_dungeons/init.lua | 2 +- mods/MAPGEN/mcl_mapgen_core/init.lua | 12 ++++++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/mods/MAPGEN/mcl_biomes/init.lua b/mods/MAPGEN/mcl_biomes/init.lua index f583d87b6..9facd83b3 100644 --- a/mods/MAPGEN/mcl_biomes/init.lua +++ b/mods/MAPGEN/mcl_biomes/init.lua @@ -3971,13 +3971,14 @@ if mg_name ~= "singlenode" then -- Overworld decorations for v6 are handled in mcl_mapgen_core if deco_id_chorus_plant then - mcl_mapgen_core.register_generator("chorus_grow", nil, function(minp, maxp, blockseed) - local gennotify = minetest.get_mapgen_object("gennotify") - --local poslist = {} - for _, pos in ipairs(gennotify["decoration#"..deco_id_chorus_plant] or {}) do + mcl_mapgen.register_chunk_generator_lvm(function(c) + c.gennotify = c.gennotify or minetest.get_mapgen_object("gennotify") + local gennotify = c.gennotify + for _, pos in pairs(gennotify["decoration#"..deco_id_chorus_plant] or {}) do local realpos = { x = pos.x, y = pos.y + 1, z = pos.z } - mcl_end.grow_chorus_plant(realpos) + minetest.after(1, mcl_end.grow_chorus_plant, realpos) end + return c end) end diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index 58e23b12e..63433d08d 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -416,4 +416,4 @@ function mcl_dungeons.spawn_dungeon(p1, _, pr) emerge_area(p1, p2, ecb_spawn_dungeon, {p1=p1, p2=p2, dim=dim, pr=pr, dontcheck=true}) end -mcl_mapgen_core.register_generator("dungeons", nil, dungeons_nodes, 999999) +mcl_mapgen.register_chunk_generator(dungeons_nodes, 999999) diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index f46d303fd..031a568f7 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1890,8 +1890,11 @@ local function set_layers(data, area, content_id, check, min, max, minp, maxp, l end -- Below the bedrock, generate air/void -local function basic(vm, data, data2, emin, emax, area, minp, maxp, blockseed) - local biomemap --ymin, ymax +local function basic(c) + local vm, data, emin, emax, area, minp, maxp, blockseed = c.vm, c.data, c.emin, c.emax, c.area, c.minp, c.maxp, c.blockseed + c.data2 = c.data2 or vm:get_data_param2(lvm_buffer_param2) + local data2 = c.data2 + local lvm_used = false local pr = PseudoRandom(blockseed) @@ -1935,7 +1938,8 @@ local function basic(vm, data, data2, emin, emax, area, minp, maxp, blockseed) -- Clay, vines, cocoas lvm_used = generate_clay(minp, maxp, blockseed, data, area, lvm_used) - biomemap = minetest.get_mapgen_object("biomemap") + c.biomemap = c.biomemap or minetest.get_mapgen_object("biomemap") + lvm_used = generate_tree_decorations(minp, maxp, blockseed, data, data2, area, biomemap, lvm_used, pr) ----- Interactive block fixing section ----- @@ -2098,5 +2102,5 @@ local function basic(vm, data, data2, emin, emax, area, minp, maxp, blockseed) return lvm_used, shadow end -mcl_mapgen_core.register_generator("main", basic, nil, 1, true) +mcl_mapgen.register_chunk_generator_lvm(basic, 1) From 269e560db1ff8e8ef21475aff7fd6e6553c7cfad Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 26 Apr 2021 20:14:36 +0400 Subject: [PATCH 04/61] [mapgen] Fix old-style API calls, make the code runnable --- mods/MAPGEN/mcl_strongholds/init.lua | 10 ++++------ mods/MAPGEN/mcl_villages/init.lua | 2 +- mods/MAPGEN/tsm_railcorridors/init.lua | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/mods/MAPGEN/mcl_strongholds/init.lua b/mods/MAPGEN/mcl_strongholds/init.lua index e465b2e40..42544e1ed 100644 --- a/mods/MAPGEN/mcl_strongholds/init.lua +++ b/mods/MAPGEN/mcl_strongholds/init.lua @@ -66,8 +66,10 @@ local init_strongholds = function() strongholds_inited = true end +init_strongholds() + -- Stronghold generation for register_on_generated. -local generate_strongholds = function(minp, maxp, blockseed) +mcl_mapgen.register_chunk_generator(function(minp, maxp, blockseed) local pr = PseudoRandom(blockseed) for s=1, #strongholds do if not strongholds[s].generated then @@ -99,8 +101,4 @@ local generate_strongholds = function(minp, maxp, blockseed) end end end -end - -init_strongholds() - -mcl_mapgen_core.register_generator("strongholds", nil, generate_strongholds, 999999) +end, 999999) diff --git a/mods/MAPGEN/mcl_villages/init.lua b/mods/MAPGEN/mcl_villages/init.lua index ccc3f585d..f1b1de906 100644 --- a/mods/MAPGEN/mcl_villages/init.lua +++ b/mods/MAPGEN/mcl_villages/init.lua @@ -78,7 +78,7 @@ end -- Disable natural generation in singlenode. local mg_name = minetest.get_mapgen_setting("mg_name") if mg_name ~= "singlenode" then - mcl_mapgen_core.register_generator("villages", nil, function(minp, maxp, blockseed) + mcl_mapgen.register_chunk_generator(function(minp, maxp, blockseed) -- don't build settlement underground if maxp.y < 0 then return end -- randomly try to build settlements diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index 2414cc962..f5a8b4908 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -1089,7 +1089,7 @@ local function create_corridor_system(main_cave_coords) end -- The rail corridor algorithm starts here -mcl_mapgen_core.register_generator("railcorridors", nil, function(minp, maxp, blockseed, _pr) +mcl_mapgen.register_chunk_generator(function(minp, maxp, blockseed, _pr) -- We re-init the randomizer for every mapchunk as we start generating in the middle of each mapchunk. -- We can't use the mapgen seed as this would make the algorithm depending on the order the mapchunk generate. InitRandomizer(blockseed) From 3f20d8c1f0891010debcc7bdc79e6f3e5af6a061 Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 26 Apr 2021 20:37:13 +0400 Subject: [PATCH 05/61] [mapgen] ... and make it unrunnable back --- mods/CORE/mcl_init/init.lua | 56 ----------------------------- mods/CORE/mcl_mapgen/init.lua | 66 +++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 56 deletions(-) diff --git a/mods/CORE/mcl_init/init.lua b/mods/CORE/mcl_init/init.lua index 066e555df..7441267d9 100644 --- a/mods/CORE/mcl_init/init.lua +++ b/mods/CORE/mcl_init/init.lua @@ -30,62 +30,6 @@ local minecraft_height_limit = 256 local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" local singlenode = mg_name == "singlenode" --- Calculate mapgen_edge_min/mapgen_edge_max -mcl_vars.chunksize = math.max(1, tonumber(minetest.get_mapgen_setting("chunksize")) or 5) -mcl_vars.MAP_BLOCKSIZE = math.max(1, core.MAP_BLOCKSIZE or 16) -mcl_vars.mapgen_limit = math.max(1, tonumber(minetest.get_mapgen_setting("mapgen_limit")) or 31000) -mcl_vars.MAX_MAP_GENERATION_LIMIT = math.max(1, core.MAX_MAP_GENERATION_LIMIT or 31000) -local central_chunk_offset = -math.floor(mcl_vars.chunksize / 2) -mcl_vars.central_chunk_offset_in_nodes = central_chunk_offset * mcl_vars.MAP_BLOCKSIZE -mcl_vars.chunk_size_in_nodes = mcl_vars.chunksize * mcl_vars.MAP_BLOCKSIZE -local central_chunk_min_pos = central_chunk_offset * mcl_vars.MAP_BLOCKSIZE -local central_chunk_max_pos = central_chunk_min_pos + mcl_vars.chunk_size_in_nodes - 1 -local ccfmin = central_chunk_min_pos - mcl_vars.MAP_BLOCKSIZE -- Fullminp/fullmaxp of central chunk, in nodes -local ccfmax = central_chunk_max_pos + mcl_vars.MAP_BLOCKSIZE -local mapgen_limit_b = math.floor(math.min(mcl_vars.mapgen_limit, mcl_vars.MAX_MAP_GENERATION_LIMIT) / mcl_vars.MAP_BLOCKSIZE) -local mapgen_limit_min = -mapgen_limit_b * mcl_vars.MAP_BLOCKSIZE -local mapgen_limit_max = (mapgen_limit_b + 1) * mcl_vars.MAP_BLOCKSIZE - 1 -local numcmin = math.max(math.floor((ccfmin - mapgen_limit_min) / mcl_vars.chunk_size_in_nodes), 0) -- Number of complete chunks from central chunk -local numcmax = math.max(math.floor((mapgen_limit_max - ccfmax) / mcl_vars.chunk_size_in_nodes), 0) -- fullminp/fullmaxp to effective mapgen limits. -mcl_vars.mapgen_edge_min = central_chunk_min_pos - numcmin * mcl_vars.chunk_size_in_nodes -mcl_vars.mapgen_edge_max = central_chunk_max_pos + numcmax * mcl_vars.chunk_size_in_nodes - -local function coordinate_to_block(x) - return math.floor(x / mcl_vars.MAP_BLOCKSIZE) -end - -local function coordinate_to_chunk(x) - return math.floor((coordinate_to_block(x) - central_chunk_offset) / mcl_vars.chunksize) -end - -function mcl_vars.pos_to_block(pos) - return { - x = coordinate_to_block(pos.x), - y = coordinate_to_block(pos.y), - z = coordinate_to_block(pos.z) - } -end - -function mcl_vars.pos_to_chunk(pos) - return { - x = coordinate_to_chunk(pos.x), - y = coordinate_to_chunk(pos.y), - z = coordinate_to_chunk(pos.z) - } -end - -local k_positive = math.ceil(mcl_vars.MAX_MAP_GENERATION_LIMIT / mcl_vars.chunk_size_in_nodes) -local k_positive_z = k_positive * 2 -local k_positive_y = k_positive_z * k_positive_z - -function mcl_vars.get_chunk_number(pos) -- unsigned int - local c = mcl_vars.pos_to_chunk(pos) - return - (c.y + k_positive) * k_positive_y + - (c.z + k_positive) * k_positive_z + - c.x + k_positive -end - if not superflat and not singlenode then -- Normal mode --[[ Realm stacking (h is for height) diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index f6bb8fa08..056da9146 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -144,3 +144,69 @@ function mcl_mapgen.get_far_node(p) minetest_get_voxel_manip():read_from_map(p, p) return minetest_get_node(p) end + +-- Calculate mapgen_edge_min/mapgen_edge_max +local function calculate_mapgen_basics() + mcl_mapgen.CS = math.max(1, tonumber(minetest.get_mapgen_setting("chunksize")) or 5) + mcl_mapgen.BS = math.max(1, core.MAP_BLOCKSIZE or 16) + mcl_mapgen.LIMIT = math.max(1, tonumber(minetest.get_mapgen_setting("mapgen_limit")) or 31000) + mcl_mapgen.MAX_LIMIT = math.max(1, core.MAX_MAP_GENERATION_LIMIT or 31000) + mcl_mapgen.OFFSET = - math.floor(mcl_mapgen.CS / 2) + mcl_mapgen.OFFSET_NODES = mcl_mapgen.OFFSET * mcl_mapgen.BS + mcl_mapgen.CS_NODES = mcl_mapgen.CS * mcl_mapgen.BS + + local central_chunk_min_pos = mcl_mapgen.OFFSET * mcl_mapgen.BS + local central_chunk_max_pos = central_chunk_min_pos + mcl_mapgen.CS_NODES - 1 + + local ccfmin = central_chunk_min_pos - mcl_mapgen.BS -- Fullminp/fullmaxp of central chunk, in nodes + local ccfmax = central_chunk_max_pos + mcl_mapgen.BS + + local mapgen_limit_b = math.floor(math.min(mcl_mapgen.LIMIT, mcl_mapgen.MAX_LIMIT) / mcl_mapgen.BS) + local mapgen_limit_min = - mapgen_limit_b * mcl_mapgen.BS + local mapgen_limit_max = (mapgen_limit_b + 1) * mcl_mapgen.BS - 1 + + local numcmin = math.max(math.floor((ccfmin - mapgen_limit_min) / mcl_vars.chunk_size_in_nodes), 0) -- Number of complete chunks from central chunk + local numcmax = math.max(math.floor((mapgen_limit_max - ccfmax) / mcl_vars.chunk_size_in_nodes), 0) -- fullminp/fullmaxp to effective mapgen limits. + + mcl_mapgen.EDGE_MIN = central_chunk_min_pos - numcmin * mcl_mapgen.CS_NODES + mcl_mapgen.EDGE_MAX = central_chunk_max_pos + numcmax * mcl_mapgen.CS_NODES +end + +local function coordinate_to_block(x) + return math_floor(x / mcl_mapgen.BS) +end + +local function coordinate_to_chunk(x) + return math_floor((coordinate_to_block(x) - central_chunk_offset) / mcl_vars.chunksize) +end + +function mcl_mapgen.pos_to_block(pos) + return { + x = coordinate_to_block(pos.x), + y = coordinate_to_block(pos.y), + z = coordinate_to_block(pos.z) + } +end + +function mcl_mapgen.pos_to_chunk(pos) + return { + x = coordinate_to_chunk(pos.x), + y = coordinate_to_chunk(pos.y), + z = coordinate_to_chunk(pos.z) + } +end + +calculate_mapgen_basics() + +local k_positive = math.ceil(mcl_mapgen.MAX_LIMIT / mcl_vars.chunk_size_in_nodes) +local k_positive_z = k_positive * 2 +local k_positive_y = k_positive_z * k_positive_z + +function mcl_mapgen.get_chunk_number(pos) -- unsigned int + local c = mcl_mapgen.pos_to_chunk(pos) + return + (c.y + k_positive) * k_positive_y + + (c.z + k_positive) * k_positive_z + + c.x + k_positive +end + From 29727136ac1975751c8a395e51d0653589de3f1b Mon Sep 17 00:00:00 2001 From: kay27 Date: Tue, 27 Apr 2021 01:30:07 +0400 Subject: [PATCH 06/61] [mapgen] redesign the code --- mods/CORE/mcl_init/init.lua | 174 -------- mods/CORE/mcl_mapgen/init.lua | 517 +++++++++++++---------- mods/ENTITIES/mcl_mobs/api.lua | 15 +- mods/ENTITIES/mcl_mobs/mod.conf | 2 +- mods/ITEMS/mcl_portals/mod.conf | 2 +- mods/ITEMS/mcl_portals/portal_nether.lua | 6 +- mods/MAPGEN/mcl_dungeons/init.lua | 2 +- mods/MAPGEN/mcl_dungeons/mod.conf | 2 +- mods/MAPGEN/mcl_mapgen_core/init.lua | 2 +- mods/PLAYER/mcl_spawn/init.lua | 2 +- mods/PLAYER/mcl_spawn/mod.conf | 2 +- 11 files changed, 317 insertions(+), 409 deletions(-) diff --git a/mods/CORE/mcl_init/init.lua b/mods/CORE/mcl_init/init.lua index 7441267d9..cd88b8dfc 100644 --- a/mods/CORE/mcl_init/init.lua +++ b/mods/CORE/mcl_init/init.lua @@ -24,97 +24,6 @@ mcl_vars.inventory_header = "" -- Tool wield size mcl_vars.tool_wield_scale = { x = 1.8, y = 1.8, z = 1 } --- Mapgen variables -local mg_name = minetest.get_mapgen_setting("mg_name") -local minecraft_height_limit = 256 -local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" -local singlenode = mg_name == "singlenode" - -if not superflat and not singlenode then - -- Normal mode - --[[ Realm stacking (h is for height) - - Overworld (h>=256) - - Void (h>=1000) - - Realm Barrier (h=11), to allow escaping the End - - End (h>=256) - - Void (h>=1000) - - Nether (h=128) - - Void (h>=1000) - ]] - - -- Overworld - mcl_vars.mg_overworld_min = -62 - mcl_vars.mg_overworld_max_official = mcl_vars.mg_overworld_min + minecraft_height_limit - mcl_vars.mg_bedrock_overworld_min = mcl_vars.mg_overworld_min - mcl_vars.mg_bedrock_overworld_max = mcl_vars.mg_bedrock_overworld_min + 4 - mcl_vars.mg_lava_overworld_max = mcl_vars.mg_overworld_min + 10 - mcl_vars.mg_lava = true - mcl_vars.mg_bedrock_is_rough = true - -elseif singlenode then - mcl_vars.mg_overworld_min = -66 - mcl_vars.mg_overworld_max_official = mcl_vars.mg_overworld_min + minecraft_height_limit - mcl_vars.mg_bedrock_overworld_min = mcl_vars.mg_overworld_min - mcl_vars.mg_bedrock_overworld_max = mcl_vars.mg_bedrock_overworld_min - mcl_vars.mg_lava = false - mcl_vars.mg_lava_overworld_max = mcl_vars.mg_overworld_min - mcl_vars.mg_bedrock_is_rough = false -else - -- Classic superflat - local ground = minetest.get_mapgen_setting("mgflat_ground_level") - ground = tonumber(ground) - if not ground then - ground = 8 - end - mcl_vars.mg_overworld_min = ground - 3 - mcl_vars.mg_overworld_max_official = mcl_vars.mg_overworld_min + minecraft_height_limit - mcl_vars.mg_bedrock_overworld_min = mcl_vars.mg_overworld_min - mcl_vars.mg_bedrock_overworld_max = mcl_vars.mg_bedrock_overworld_min - mcl_vars.mg_lava = false - mcl_vars.mg_lava_overworld_max = mcl_vars.mg_overworld_min - mcl_vars.mg_bedrock_is_rough = false -end - -mcl_vars.mg_overworld_max = mcl_vars.mapgen_edge_max - --- The Nether (around Y = -29000) -mcl_vars.mg_nether_min = -29067 -- Carefully chosen to be at a mapchunk border -mcl_vars.mg_nether_max = mcl_vars.mg_nether_min + 128 -mcl_vars.mg_bedrock_nether_bottom_min = mcl_vars.mg_nether_min -mcl_vars.mg_bedrock_nether_top_max = mcl_vars.mg_nether_max -if not superflat then - mcl_vars.mg_bedrock_nether_bottom_max = mcl_vars.mg_bedrock_nether_bottom_min + 4 - mcl_vars.mg_bedrock_nether_top_min = mcl_vars.mg_bedrock_nether_top_max - 4 - mcl_vars.mg_lava_nether_max = mcl_vars.mg_nether_min + 31 -else - -- Thin bedrock in classic superflat mapgen - mcl_vars.mg_bedrock_nether_bottom_max = mcl_vars.mg_bedrock_nether_bottom_min - mcl_vars.mg_bedrock_nether_top_min = mcl_vars.mg_bedrock_nether_top_max - mcl_vars.mg_lava_nether_max = mcl_vars.mg_nether_min + 2 -end -if mg_name == "flat" then - if superflat then - mcl_vars.mg_flat_nether_floor = mcl_vars.mg_bedrock_nether_bottom_max + 4 - mcl_vars.mg_flat_nether_ceiling = mcl_vars.mg_bedrock_nether_bottom_max + 52 - else - mcl_vars.mg_flat_nether_floor = mcl_vars.mg_lava_nether_max + 4 - mcl_vars.mg_flat_nether_ceiling = mcl_vars.mg_lava_nether_max + 52 - end -end - --- The End (surface at ca. Y = -27000) -mcl_vars.mg_end_min = -27073 -- Carefully chosen to be at a mapchunk border -mcl_vars.mg_end_max_official = mcl_vars.mg_end_min + minecraft_height_limit -mcl_vars.mg_end_max = mcl_vars.mg_overworld_min - 2000 -mcl_vars.mg_end_platform_pos = { x = 100, y = mcl_vars.mg_end_min + 74, z = 0 } - --- Realm barrier used to safely separate the End from the void below the Overworld -mcl_vars.mg_realm_barrier_overworld_end_max = mcl_vars.mg_end_max -mcl_vars.mg_realm_barrier_overworld_end_min = mcl_vars.mg_end_max - 11 - --- Use MineClone 2-style dungeons -mcl_vars.mg_dungeons = true - -- Set default stack sizes minetest.nodedef_default.stack_max = 64 minetest.craftitemdef_default.stack_max = 64 @@ -122,86 +31,3 @@ minetest.craftitemdef_default.stack_max = 64 -- Set random seed for all other mods (Remember to make sure no other mod calls this function) math.randomseed(os.time()) -local chunks = {} -- intervals of chunks generated -function mcl_vars.add_chunk(pos) - local n = mcl_vars.get_chunk_number(pos) -- unsigned int - local prev - for i, d in pairs(chunks) do - if n <= d[2] then -- we've found it - if (n == d[2]) or (n >= d[1]) then return end -- already here - if n == d[1]-1 then -- right before: - if prev and (prev[2] == n-1) then - prev[2] = d[2] - table.remove(chunks, i) - return - end - d[1] = n - return - end - if prev and (prev[2] == n-1) then --join to previous - prev[2] = n - return - end - table.insert(chunks, i, {n, n}) -- insert new interval before i - return - end - prev = d - end - chunks[#chunks+1] = {n, n} -end -function mcl_vars.is_generated(pos) - local n = mcl_vars.get_chunk_number(pos) -- unsigned int - for i, d in pairs(chunks) do - if n <= d[2] then - return (n >= d[1]) - end - end - return false -end - --- "Trivial" (actually NOT) function to just read the node and some stuff to not just return "ignore", like mt 5.4 does. --- p: Position, if it's wrong, {name="error"} node will return. --- force: optional (default: false) - Do the maximum to still read the node within us_timeout. --- us_timeout: optional (default: 244 = 0.000244 s = 1/80/80/80), set it at least to 3000000 to let mapgen to finish its job. --- --- returns node definition, eg. {name="air"}. Unfortunately still can return {name="ignore"}. -function mcl_vars.get_node(p, force, us_timeout) - -- check initial circumstances - if not p or not p.x or not p.y or not p.z then return {name="error"} end - - -- try common way - local node = minetest.get_node(p) - if node.name ~= "ignore" then - return node - end - - -- copy table to get sure it won't changed by other threads - local pos = {x=p.x,y=p.y,z=p.z} - - -- try LVM - minetest.get_voxel_manip():read_from_map(pos, pos) - node = minetest.get_node(pos) - if node.name ~= "ignore" or not force then - return node - end - - -- all ways failed - need to emerge (or forceload if generated) - local us_timeout = us_timeout or 244 - if mcl_vars.is_generated(pos) then - minetest.chat_send_all("IMPOSSIBLE! Please report this to MCL2 issue tracker!") - minetest.forceload_block(pos) - else - minetest.emerge_area(pos, pos) - end - - local t = minetest.get_us_time() - - node = minetest.get_node(pos) - - while (not node or node.name == "ignore") and (minetest.get_us_time() - t < us_timeout) do - node = minetest.get_node(pos) - end - - return node - -- it still can return "ignore", LOL, even if force = true, but only after time out -end diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 056da9146..f5c6a16f9 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -1,212 +1,305 @@ -mcl_mapgen = {} - -local lvm_block_queue, lvm_chunk_queue, node_block_queue, node_chunk_queue = {}, {}, {}, {} -- Generators' queues -local lvm, block, lvm_block, lvm_chunk, param2, nodes_block, nodes_chunk = 0, 0, 0, 0, 0, 0, 0 -- Requirements: 0 means none; greater than 0 means 'required' -local lvm_buffer, lvm_param2_buffer = {}, {} -- Static buffer pointers -local BS, CS = mcl_vars.MAP_BLOCKSIZE, mcl_vars.chunksize -- Mapblock size (in nodes), Mapchunk size (in blocks) -local LAST_BLOCK, LAST_NODE = CS - 1, BS - 1 -- First mapblock in chunk (node in mapblock) has number 0, last has THIS number. It's for runtime optimization -local offset = math.floor(mcl_vars.central_chunk_offset_in_nodes / BS) -- Central mapchunk offset (in blocks) - -local DEFAULT_PRIORITY = 5000 - -local minetest_log, math_floor = minetest.log, math.floor - -function mcl_mapgen.register_chunk_generator(callback_function, priority) - nodes_chunk = nodes_chunk + 1 - node_chunk_queue[nodes_chunk] = {i = priority or DEFAULT_PRIORITY, f = callback_function} - table.sort(node_chunk_queue, function(a, b) return (a.i <= b.i) end) -end -function mcl_mapgen.register_chunk_generator_lvm(callback_function, priority) - lvm = lvm + 1 - lvm_chunk_queue[lvm_chunk] = {i = priority or DEFAULT_PRIORITY, f = callback_function} - table.sort(lvm_chunk_queue, function(a, b) return (a.i <= b.i) end) -end -function mcl_mapgen.register_block_generator(callback_function, priority) - block = block + 1 - nodes_block = nodes_block + 1 - node_block_queue[nodes_block] = {i = priority or DEFAULT_PRIORITY, f = callback_function} - table.sort(node_block_queue, function(a, b) return (a.i <= b.i) end) -end -function mcl_mapgen.register_block_generator_lvm(callback_function, priority) - block = block + 1 - lvm = lvm + 1 - lvm_block = lvm_block + 1 - lvm_block_queue[lvm_block] = {i = priority or DEFAULT_PRIORITY, f = callback_function} - table.sort(lvm_block_queue, function(a, b) return (a.i <= b.i) end) -end - -local storage = minetest.get_mod_storage() -local blocks = minetest.deserialize( storage:get_string("mapgen_blocks") or "return {}") or {} -minetest.register_on_shutdown(function() storage:set_string("mapgen_blocks", minetest.serialize(blocks)) end) - -local vm_context-- here will be many references and flags, like: param2, light_data, heightmap, biomemap, heatmap, humiditymap, gennotify, write_lvm, write_param2, shadow -local data, data2, area -local current_blocks = {} - -minetest.register_on_generated(function(minp, maxp, blockseed) - local minp, maxp, blockseed = minp, maxp, blockseed - minetest_log("verbose", "[mcl_mapgen] New chunk: minp=" .. minetest.pos_to_string(minp) .. ", maxp=" .. minetest.pos_to_string(maxp) .. ", blockseed=" .. blockseed) - - local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") - - if lvm > 0 then - vm_context = {lvm_param2_buffer = lvm_param2_buffer, vm = vm, emin = emin, emax = emax, minp = minp, maxp = maxp, blockseed = blockseed} - data = vm:get_data(lvm_buffer) - vm_context.data = data - area = VoxelArea:new({MinEdge=emin, MaxEdge=emax}) - vm_context.area = area - for _, v in pairs(lvm_chunk_queue) do - vm_context = v.f(vm_context) - end - end - - if block > 0 then - local x0, y0, z0 = minp.x, minp.y, minp.z - local bx0, by0, bz0 = math_floor(x0/BS), math_floor(y0/BS), math_floor(z0/BS) - local x1, y1, z1, x2, y2, z2 = emin.x, emin.y, emin.z, emax.x, emax.y, emax.z - local x, y, z = x1, y1, z1 -- iterate 7x7x7 mapchunk, {x,y,z} - first node pos. of mapblock - local bx, by, bz -- block coords (in blocs) - local box, boy, boz -- block offsets in chunks (in blocks) - while x < x2 do - bx = math_floor(x/BS) - local block_pos_offset_removed = bx - offset - box = block_pos_offset_removed % CS - if not blocks[bx] then blocks[bx]={} end - local total_mapgen_block_writes_through_x = (box > 0 and box < LAST_BLOCK) and 4 or 8 - while y < y2 do - by = math_floor(y/BS) - block_pos_offset_removed = by - offset - boy = block_pos_offset_removed % CS - if not blocks[bx][by] then blocks[bx][by]={} end - local total_mapgen_block_writes_through_y = (boy > 0 and boy < LAST_BLOCK) and math_floor(total_mapgen_block_writes_through_x / 2) or total_mapgen_block_writes_through_x - while z < z2 do - bz = math_floor(z/BS) - block_pos_offset_removed = bz - offset - boz = block_pos_offset_removed % CS - local total_mapgen_block_writes = (boz > 0 and boz < LAST_BLOCK) and math_floor(total_mapgen_block_writes_through_y / 2) or total_mapgen_block_writes_through_y - local current_mapgen_block_writes = blocks[bx][by][bz] and (blocks[bx][by][bz] + 1) or 1 - if current_mapgen_block_writes == total_mapgen_block_writes then - -- this block shouldn't be overwritten anymore, no need to keep it in memory - blocks[bx][by][bz] = nil - vm_context.seed = blockseed + box * 7 + boy * 243 + boz * 11931 - if lvm_block > 0 then - vm_context.minp, vm_content.maxp = {x=x, y=y, z=z}, {x=x+LAST_NODE, y=y+LAST_NODE, z=z+LAST_NODE} - for _, v in pairs(lvm_block_queue) do - vm_context = v.f(vm_context) - end - end - if nodes_block > 0 then - current_blocks[#current_blocks+1] = { minp = {x=x, y=y, z=z}, maxp = {x=pos.x+LAST_NODE, y=pos.y+LAST_NODE, z=pos.z+LAST_NODE}, seed = seed } - end - else - blocks[bx][by][bz] = current_mapgen_block_writes - end - z = z + BS - end - if next(blocks[bx][by]) == nil then blocks[bx][by] = nil end - z = z1 - y = y + BS - end - if next(blocks[bx]) == nil then blocks[bx] = nil end - y = y1 - x = x + BS - end - end - - if vm_context.write then - vm:set_data(data) - end - if vm_context.write_param2 then - vm:set_param2_data(data2) - end - vm:calc_lighting(p1, p2, shadow) - vm:write_to_map() - vm:update_liquids() - - for _, v in pairs(node_chunk_queue) do - v.f(minp, maxp, blockseed) - end - - for i, b in pairs(current_blocks) do - for _, v in pairs(node_block_queue) do - v.f(b.minp, b.maxp, b.seed) - end - current_blocks[id] = nil - end -end) - -minetest.register_on_generated = mcl_mapgen.register_chunk_generator - -function mcl_mapgen.get_far_node(p) - local p = p - local node = minetest_get_node(p) - if node.name ~= "ignore" then return node end - minetest_get_voxel_manip():read_from_map(p, p) - return minetest_get_node(p) -end - --- Calculate mapgen_edge_min/mapgen_edge_max -local function calculate_mapgen_basics() - mcl_mapgen.CS = math.max(1, tonumber(minetest.get_mapgen_setting("chunksize")) or 5) - mcl_mapgen.BS = math.max(1, core.MAP_BLOCKSIZE or 16) - mcl_mapgen.LIMIT = math.max(1, tonumber(minetest.get_mapgen_setting("mapgen_limit")) or 31000) - mcl_mapgen.MAX_LIMIT = math.max(1, core.MAX_MAP_GENERATION_LIMIT or 31000) - mcl_mapgen.OFFSET = - math.floor(mcl_mapgen.CS / 2) - mcl_mapgen.OFFSET_NODES = mcl_mapgen.OFFSET * mcl_mapgen.BS - mcl_mapgen.CS_NODES = mcl_mapgen.CS * mcl_mapgen.BS - - local central_chunk_min_pos = mcl_mapgen.OFFSET * mcl_mapgen.BS - local central_chunk_max_pos = central_chunk_min_pos + mcl_mapgen.CS_NODES - 1 - - local ccfmin = central_chunk_min_pos - mcl_mapgen.BS -- Fullminp/fullmaxp of central chunk, in nodes - local ccfmax = central_chunk_max_pos + mcl_mapgen.BS - - local mapgen_limit_b = math.floor(math.min(mcl_mapgen.LIMIT, mcl_mapgen.MAX_LIMIT) / mcl_mapgen.BS) - local mapgen_limit_min = - mapgen_limit_b * mcl_mapgen.BS - local mapgen_limit_max = (mapgen_limit_b + 1) * mcl_mapgen.BS - 1 - - local numcmin = math.max(math.floor((ccfmin - mapgen_limit_min) / mcl_vars.chunk_size_in_nodes), 0) -- Number of complete chunks from central chunk - local numcmax = math.max(math.floor((mapgen_limit_max - ccfmax) / mcl_vars.chunk_size_in_nodes), 0) -- fullminp/fullmaxp to effective mapgen limits. - - mcl_mapgen.EDGE_MIN = central_chunk_min_pos - numcmin * mcl_mapgen.CS_NODES - mcl_mapgen.EDGE_MAX = central_chunk_max_pos + numcmax * mcl_mapgen.CS_NODES -end - -local function coordinate_to_block(x) - return math_floor(x / mcl_mapgen.BS) -end - -local function coordinate_to_chunk(x) - return math_floor((coordinate_to_block(x) - central_chunk_offset) / mcl_vars.chunksize) -end - -function mcl_mapgen.pos_to_block(pos) - return { - x = coordinate_to_block(pos.x), - y = coordinate_to_block(pos.y), - z = coordinate_to_block(pos.z) - } -end - -function mcl_mapgen.pos_to_chunk(pos) - return { - x = coordinate_to_chunk(pos.x), - y = coordinate_to_chunk(pos.y), - z = coordinate_to_chunk(pos.z) - } -end - -calculate_mapgen_basics() - -local k_positive = math.ceil(mcl_mapgen.MAX_LIMIT / mcl_vars.chunk_size_in_nodes) -local k_positive_z = k_positive * 2 -local k_positive_y = k_positive_z * k_positive_z - -function mcl_mapgen.get_chunk_number(pos) -- unsigned int - local c = mcl_mapgen.pos_to_chunk(pos) - return - (c.y + k_positive) * k_positive_y + - (c.z + k_positive) * k_positive_z + - c.x + k_positive -end - +mcl_mapgen = {} + + +-- Calculate mapgen_edge_min/mapgen_edge_max +mcl_mapgen.CS = math.max(1, tonumber(minetest.get_mapgen_setting("chunksize")) or 5) +mcl_mapgen.BS = math.max(1, core.MAP_BLOCKSIZE or 16) +mcl_mapgen.LIMIT = math.max(1, tonumber(minetest.get_mapgen_setting("mapgen_limit")) or 31000) +mcl_mapgen.MAX_LIMIT = math.max(1, core.MAX_MAP_GENERATION_LIMIT or 31000) +mcl_mapgen.OFFSET = - math.floor(mcl_mapgen.CS / 2) +mcl_mapgen.OFFSET_NODES = mcl_mapgen.OFFSET * mcl_mapgen.BS +mcl_mapgen.CS_NODES = mcl_mapgen.CS * mcl_mapgen.BS + +local central_chunk_min_pos = mcl_mapgen.OFFSET * mcl_mapgen.BS +local central_chunk_max_pos = central_chunk_min_pos + mcl_mapgen.CS_NODES - 1 + +local ccfmin = central_chunk_min_pos - mcl_mapgen.BS -- Fullminp/fullmaxp of central chunk, in nodes +local ccfmax = central_chunk_max_pos + mcl_mapgen.BS + +local mapgen_limit_b = math.floor(math.min(mcl_mapgen.LIMIT, mcl_mapgen.MAX_LIMIT) / mcl_mapgen.BS) +local mapgen_limit_min = - mapgen_limit_b * mcl_mapgen.BS +local mapgen_limit_max = (mapgen_limit_b + 1) * mcl_mapgen.BS - 1 + +local numcmin = math.max(math.floor((ccfmin - mapgen_limit_min) / mcl_vars.chunk_size_in_nodes), 0) -- Number of complete chunks from central chunk +local numcmax = math.max(math.floor((mapgen_limit_max - ccfmax) / mcl_vars.chunk_size_in_nodes), 0) -- fullminp/fullmaxp to effective mapgen limits. + +mcl_mapgen.EDGE_MIN = central_chunk_min_pos - numcmin * mcl_mapgen.CS_NODES +mcl_mapgen.EDGE_MAX = central_chunk_max_pos + numcmax * mcl_mapgen.CS_NODES +------------------------------------------ + + +local lvm_block_queue, lvm_chunk_queue, node_block_queue, node_chunk_queue = {}, {}, {}, {} -- Generators' queues +local lvm, block, lvm_block, lvm_chunk, param2, nodes_block, nodes_chunk = 0, 0, 0, 0, 0, 0, 0 -- Requirements: 0 means none; greater than 0 means 'required' +local lvm_buffer, lvm_param2_buffer = {}, {} -- Static buffer pointers +local BS, CS = mcl_mapgen.BS, mcl_mapgen.CS -- Mapblock size (in nodes), Mapchunk size (in blocks) +local LAST_BLOCK, LAST_NODE = CS - 1, BS - 1 -- First mapblock in chunk (node in mapblock) has number 0, last has THIS number. It's for runtime optimization +local offset = math.floor(mcl_vars.central_chunk_offset_in_nodes / BS) -- Central mapchunk offset (in blocks) + +local DEFAULT_PRIORITY = 5000 + +local minetest_log, math_floor = minetest.log, math.floor + +function mcl_mapgen.register_chunk_generator(callback_function, priority) + nodes_chunk = nodes_chunk + 1 + node_chunk_queue[nodes_chunk] = {i = priority or DEFAULT_PRIORITY, f = callback_function} + table.sort(node_chunk_queue, function(a, b) return (a.i <= b.i) end) +end +function mcl_mapgen.register_chunk_generator_lvm(callback_function, priority) + lvm = lvm + 1 + lvm_chunk_queue[lvm_chunk] = {i = priority or DEFAULT_PRIORITY, f = callback_function} + table.sort(lvm_chunk_queue, function(a, b) return (a.i <= b.i) end) +end +function mcl_mapgen.register_block_generator(callback_function, priority) + block = block + 1 + nodes_block = nodes_block + 1 + node_block_queue[nodes_block] = {i = priority or DEFAULT_PRIORITY, f = callback_function} + table.sort(node_block_queue, function(a, b) return (a.i <= b.i) end) +end +function mcl_mapgen.register_block_generator_lvm(callback_function, priority) + block = block + 1 + lvm = lvm + 1 + lvm_block = lvm_block + 1 + lvm_block_queue[lvm_block] = {i = priority or DEFAULT_PRIORITY, f = callback_function} + table.sort(lvm_block_queue, function(a, b) return (a.i <= b.i) end) +end + +local storage = minetest.get_mod_storage() +local blocks = minetest.deserialize( storage:get_string("mapgen_blocks") or "return {}") or {} +minetest.register_on_shutdown(function() storage:set_string("mapgen_blocks", minetest.serialize(blocks)) end) + +local vm_context-- here will be many references and flags, like: param2, light_data, heightmap, biomemap, heatmap, humiditymap, gennotify, write_lvm, write_param2, shadow +local data, data2, area +local current_blocks = {} + +minetest.register_on_generated(function(minp, maxp, blockseed) + local minp, maxp, blockseed = minp, maxp, blockseed + minetest_log("verbose", "[mcl_mapgen] New chunk: minp=" .. minetest.pos_to_string(minp) .. ", maxp=" .. minetest.pos_to_string(maxp) .. ", blockseed=" .. blockseed) + + local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") + + if lvm > 0 then + vm_context = {lvm_param2_buffer = lvm_param2_buffer, vm = vm, emin = emin, emax = emax, minp = minp, maxp = maxp, blockseed = blockseed} + data = vm:get_data(lvm_buffer) + vm_context.data = data + area = VoxelArea:new({MinEdge=emin, MaxEdge=emax}) + vm_context.area = area + for _, v in pairs(lvm_chunk_queue) do + vm_context = v.f(vm_context) + end + end + + if block > 0 then + local x0, y0, z0 = minp.x, minp.y, minp.z + local bx0, by0, bz0 = math_floor(x0/BS), math_floor(y0/BS), math_floor(z0/BS) + local x1, y1, z1, x2, y2, z2 = emin.x, emin.y, emin.z, emax.x, emax.y, emax.z + local x, y, z = x1, y1, z1 -- iterate 7x7x7 mapchunk, {x,y,z} - first node pos. of mapblock + local bx, by, bz -- block coords (in blocs) + local box, boy, boz -- block offsets in chunks (in blocks) + while x < x2 do + bx = math_floor(x/BS) + local block_pos_offset_removed = bx - offset + box = block_pos_offset_removed % CS + if not blocks[bx] then blocks[bx]={} end + local total_mapgen_block_writes_through_x = (box > 0 and box < LAST_BLOCK) and 4 or 8 + while y < y2 do + by = math_floor(y/BS) + block_pos_offset_removed = by - offset + boy = block_pos_offset_removed % CS + if not blocks[bx][by] then blocks[bx][by]={} end + local total_mapgen_block_writes_through_y = (boy > 0 and boy < LAST_BLOCK) and math_floor(total_mapgen_block_writes_through_x / 2) or total_mapgen_block_writes_through_x + while z < z2 do + bz = math_floor(z/BS) + block_pos_offset_removed = bz - offset + boz = block_pos_offset_removed % CS + local total_mapgen_block_writes = (boz > 0 and boz < LAST_BLOCK) and math_floor(total_mapgen_block_writes_through_y / 2) or total_mapgen_block_writes_through_y + local current_mapgen_block_writes = blocks[bx][by][bz] and (blocks[bx][by][bz] + 1) or 1 + if current_mapgen_block_writes == total_mapgen_block_writes then + -- this block shouldn't be overwritten anymore, no need to keep it in memory + blocks[bx][by][bz] = nil + vm_context.seed = blockseed + box * 7 + boy * 243 + boz * 11931 + if lvm_block > 0 then + vm_context.minp, vm_content.maxp = {x=x, y=y, z=z}, {x=x+LAST_NODE, y=y+LAST_NODE, z=z+LAST_NODE} + for _, v in pairs(lvm_block_queue) do + vm_context = v.f(vm_context) + end + end + if nodes_block > 0 then + current_blocks[#current_blocks+1] = { minp = {x=x, y=y, z=z}, maxp = {x=pos.x+LAST_NODE, y=pos.y+LAST_NODE, z=pos.z+LAST_NODE}, seed = seed } + end + else + blocks[bx][by][bz] = current_mapgen_block_writes + end + z = z + BS + end + if next(blocks[bx][by]) == nil then blocks[bx][by] = nil end + z = z1 + y = y + BS + end + if next(blocks[bx]) == nil then blocks[bx] = nil end + y = y1 + x = x + BS + end + end + + if vm_context.write then + vm:set_data(data) + end + if vm_context.write_param2 then + vm:set_param2_data(data2) + end + vm:calc_lighting(p1, p2, shadow) + vm:write_to_map() + vm:update_liquids() + + for _, v in pairs(node_chunk_queue) do + v.f(minp, maxp, blockseed) + end + + for i, b in pairs(current_blocks) do + for _, v in pairs(node_block_queue) do + v.f(b.minp, b.maxp, b.seed) + end + current_blocks[id] = nil + end +end) + +minetest.register_on_generated = mcl_mapgen.register_chunk_generator + +function mcl_mapgen.get_far_node(p) + local p = p + local node = minetest_get_node(p) + if node.name ~= "ignore" then return node end + minetest_get_voxel_manip():read_from_map(p, p) + return minetest_get_node(p) +end + +local function coordinate_to_block(x) + return math_floor(x / mcl_mapgen.BS) +end + +local function coordinate_to_chunk(x) + return math_floor((coordinate_to_block(x) - central_chunk_offset) / mcl_mapgen.CS) +end + +function mcl_mapgen.pos_to_block(pos) + return { + x = coordinate_to_block(pos.x), + y = coordinate_to_block(pos.y), + z = coordinate_to_block(pos.z) + } +end + +function mcl_mapgen.pos_to_chunk(pos) + return { + x = coordinate_to_chunk(pos.x), + y = coordinate_to_chunk(pos.y), + z = coordinate_to_chunk(pos.z) + } +end + +local k_positive = math.ceil(mcl_mapgen.MAX_LIMIT / mcl_vars.chunk_size_in_nodes) +local k_positive_z = k_positive * 2 +local k_positive_y = k_positive_z * k_positive_z + +function mcl_mapgen.get_chunk_number(pos) -- unsigned int + local c = mcl_mapgen.pos_to_chunk(pos) + return + (c.y + k_positive) * k_positive_y + + (c.z + k_positive) * k_positive_z + + c.x + k_positive +end + + + + + +-- Mapgen variables +local mg_name = minetest.get_mapgen_setting("mg_name") +local minecraft_height_limit = 256 +local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" +local singlenode = mg_name == "singlenode" + +if not superflat and not singlenode then + -- Normal mode + --[[ Realm stacking (h is for height) + - Overworld (h>=256) + - Void (h>=1000) + - Realm Barrier (h=11), to allow escaping the End + - End (h>=256) + - Void (h>=1000) + - Nether (h=128) + - Void (h>=1000) + ]] + + -- Overworld + mcl_vars.mg_overworld_min = -62 + mcl_vars.mg_overworld_max_official = mcl_vars.mg_overworld_min + minecraft_height_limit + mcl_vars.mg_bedrock_overworld_min = mcl_vars.mg_overworld_min + mcl_vars.mg_bedrock_overworld_max = mcl_vars.mg_bedrock_overworld_min + 4 + mcl_vars.mg_lava_overworld_max = mcl_vars.mg_overworld_min + 10 + mcl_vars.mg_lava = true + mcl_vars.mg_bedrock_is_rough = true + +elseif singlenode then + mcl_vars.mg_overworld_min = -66 + mcl_vars.mg_overworld_max_official = mcl_vars.mg_overworld_min + minecraft_height_limit + mcl_vars.mg_bedrock_overworld_min = mcl_vars.mg_overworld_min + mcl_vars.mg_bedrock_overworld_max = mcl_vars.mg_bedrock_overworld_min + mcl_vars.mg_lava = false + mcl_vars.mg_lava_overworld_max = mcl_vars.mg_overworld_min + mcl_vars.mg_bedrock_is_rough = false +else + -- Classic superflat + local ground = minetest.get_mapgen_setting("mgflat_ground_level") + ground = tonumber(ground) + if not ground then + ground = 8 + end + mcl_vars.mg_overworld_min = ground - 3 + mcl_vars.mg_overworld_max_official = mcl_vars.mg_overworld_min + minecraft_height_limit + mcl_vars.mg_bedrock_overworld_min = mcl_vars.mg_overworld_min + mcl_vars.mg_bedrock_overworld_max = mcl_vars.mg_bedrock_overworld_min + mcl_vars.mg_lava = false + mcl_vars.mg_lava_overworld_max = mcl_vars.mg_overworld_min + mcl_vars.mg_bedrock_is_rough = false +end + +mcl_vars.mg_overworld_max = mcl_mapgen.EDGE_MAX + +-- The Nether (around Y = -29000) +mcl_vars.mg_nether_min = -29067 -- Carefully chosen to be at a mapchunk border +mcl_vars.mg_nether_max = mcl_vars.mg_nether_min + 128 +mcl_vars.mg_bedrock_nether_bottom_min = mcl_vars.mg_nether_min +mcl_vars.mg_bedrock_nether_top_max = mcl_vars.mg_nether_max +if not superflat then + mcl_vars.mg_bedrock_nether_bottom_max = mcl_vars.mg_bedrock_nether_bottom_min + 4 + mcl_vars.mg_bedrock_nether_top_min = mcl_vars.mg_bedrock_nether_top_max - 4 + mcl_vars.mg_lava_nether_max = mcl_vars.mg_nether_min + 31 +else + -- Thin bedrock in classic superflat mapgen + mcl_vars.mg_bedrock_nether_bottom_max = mcl_vars.mg_bedrock_nether_bottom_min + mcl_vars.mg_bedrock_nether_top_min = mcl_vars.mg_bedrock_nether_top_max + mcl_vars.mg_lava_nether_max = mcl_vars.mg_nether_min + 2 +end +if mg_name == "flat" then + if superflat then + mcl_vars.mg_flat_nether_floor = mcl_vars.mg_bedrock_nether_bottom_max + 4 + mcl_vars.mg_flat_nether_ceiling = mcl_vars.mg_bedrock_nether_bottom_max + 52 + else + mcl_vars.mg_flat_nether_floor = mcl_vars.mg_lava_nether_max + 4 + mcl_vars.mg_flat_nether_ceiling = mcl_vars.mg_lava_nether_max + 52 + end +end + +-- The End (surface at ca. Y = -27000) +mcl_vars.mg_end_min = -27073 -- Carefully chosen to be at a mapchunk border +mcl_vars.mg_end_max_official = mcl_vars.mg_end_min + minecraft_height_limit +mcl_vars.mg_end_max = mcl_vars.mg_overworld_min - 2000 +mcl_vars.mg_end_platform_pos = { x = 100, y = mcl_vars.mg_end_min + 74, z = 0 } + +-- Realm barrier used to safely separate the End from the void below the Overworld +mcl_vars.mg_realm_barrier_overworld_end_max = mcl_vars.mg_end_max +mcl_vars.mg_realm_barrier_overworld_end_min = mcl_vars.mg_end_max - 11 + +-- Use MineClone 2-style dungeons +mcl_vars.mg_dungeons = true diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 3f635ece0..16ab55a28 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -919,19 +919,8 @@ end -- check if within physical map limits (-30911 to 30927) -local within_limits, wmin, wmax = nil, -30913, 30928 -within_limits = function(pos, radius) - if mcl_vars then - if mcl_vars.mapgen_edge_min and mcl_vars.mapgen_edge_max then - wmin, wmax = mcl_vars.mapgen_edge_min, mcl_vars.mapgen_edge_max - within_limits = function(pos, radius) - return pos - and (pos.x - radius) > wmin and (pos.x + radius) < wmax - and (pos.y - radius) > wmin and (pos.y + radius) < wmax - and (pos.z - radius) > wmin and (pos.z + radius) < wmax - end - end - end +local wmin, wmax = mcl_mapgen.EDGE_MIN, mcl_mapgen.EDGE_MAX +local function within_limits(pos, radius) return pos and (pos.x - radius) > wmin and (pos.x + radius) < wmax and (pos.y - radius) > wmin and (pos.y + radius) < wmax diff --git a/mods/ENTITIES/mcl_mobs/mod.conf b/mods/ENTITIES/mcl_mobs/mod.conf index 0d622f6a9..d6089dac6 100644 --- a/mods/ENTITIES/mcl_mobs/mod.conf +++ b/mods/ENTITIES/mcl_mobs/mod.conf @@ -1,5 +1,5 @@ name = mcl_mobs author = PilzAdam description = Adds a mob API for mods to add animals or monsters, etc. -depends = mcl_particles +depends = mcl_mapgen, mcl_particles optional_depends = mcl_weather, mcl_explosions, mcl_hunger, mcl_worlds, invisibility, lucky_block, cmi, doc_identifier, mcl_armor, mcl_portals, mcl_experience diff --git a/mods/ITEMS/mcl_portals/mod.conf b/mods/ITEMS/mcl_portals/mod.conf index d99344a76..e2ebc0385 100644 --- a/mods/ITEMS/mcl_portals/mod.conf +++ b/mods/ITEMS/mcl_portals/mod.conf @@ -1,4 +1,4 @@ name = mcl_portals description = Adds buildable portals to the Nether and End dimensions. -depends = mcl_nether, mcl_end, mcl_particles, mcl_spawn +depends = mcl_mapgen, mcl_nether, mcl_end, mcl_particles, mcl_spawn optional_depends = awards, doc diff --git a/mods/ITEMS/mcl_portals/portal_nether.lua b/mods/ITEMS/mcl_portals/portal_nether.lua index a121f719c..7fd0191fa 100644 --- a/mods/ITEMS/mcl_portals/portal_nether.lua +++ b/mods/ITEMS/mcl_portals/portal_nether.lua @@ -19,7 +19,7 @@ local W_MIN, W_MAX = 4, 23 local H_MIN, H_MAX = 5, 23 local N_MIN, N_MAX = 6, (W_MAX-2) * (H_MAX-2) local TRAVEL_X, TRAVEL_Y, TRAVEL_Z = 8, 1, 8 -local LIM_MIN, LIM_MAX = mcl_vars.mapgen_edge_min, mcl_vars.mapgen_edge_max +local LIM_MIN, LIM_MAX = mcl_mapgen.EDGE_MIN, mcl_mapgen.EDGE_MAX local PLAYER_COOLOFF, MOB_COOLOFF = 3, 14 -- for this many seconds they won't teleported again local TOUCH_CHATTER_TIME = 1 -- prevent multiple teleportation attempts caused by multiple portal touches, for this number of seconds local CHATTER_US = TOUCH_CHATTER_TIME * 1000000 @@ -522,8 +522,8 @@ local function create_portal(pos, limit1, limit2, name, obj) -- so we'll emerge single chunk only: 5x5x5 blocks, 80x80x80 nodes maximum -- and maybe one more chunk from below if (SCAN_2_MAP_CHUNKS = true) - local pos1 = add(mul(mcl_vars.pos_to_chunk(pos), mcl_vars.chunk_size_in_nodes), mcl_vars.central_chunk_offset_in_nodes) - local pos2 = add(pos1, mcl_vars.chunk_size_in_nodes - 1) + local pos1 = add(mul(mcl_mapgen.pos_to_chunk(pos), mcl_mapgen.CS_NODES), mcl_mapgen.OFFSET_NODES) + local pos2 = add(pos1, mcl_mapgen.CS_NODES - 1) if not SCAN_2_MAP_CHUNKS then if limit1 and limit1.x and limit1.y and limit1.z then diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index 63433d08d..40af11d37 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -40,7 +40,7 @@ local max_y = mcl_vars.mg_overworld_max - 1 -- Calculate the number of dungeon spawn attempts -- In Minecraft, there 8 dungeon spawn attempts Minecraft chunk (16*256*16 = 65536 blocks). -- Minetest chunks don't have this size, so scale the number accordingly. -local attempts = math_ceil(((mcl_vars.chunksize * mcl_vars.MAP_BLOCKSIZE) ^ 3) / 8192) -- 63 = 80*80*80/8192 +local attempts = math_ceil((mcl_mapgen.CS_NODES ^ 3) / 8192) -- 63 = 80*80*80/8192 local dungeonsizes = { { x=5, y=4, z=5}, diff --git a/mods/MAPGEN/mcl_dungeons/mod.conf b/mods/MAPGEN/mcl_dungeons/mod.conf index fe02286fa..e7a7d921c 100644 --- a/mods/MAPGEN/mcl_dungeons/mod.conf +++ b/mods/MAPGEN/mcl_dungeons/mod.conf @@ -1,4 +1,4 @@ name = mcl_dungeons author = Wuzzy description = Generates random dungeons in the world -depends = mcl_init, mcl_core, mcl_chests, mcl_mobs, mcl_mobspawners, mcl_mapgen_core, mobs_mc +depends = mcl_mapgen, mcl_core, mcl_chests, mcl_mobs, mcl_mobspawners, mcl_mapgen_core, mobs_mc diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 031a568f7..b14e1c2c7 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1899,7 +1899,7 @@ local function basic(c) local pr = PseudoRandom(blockseed) -- The Void below the Nether: - lvm_used = set_layers(data, area, c_void , nil, mcl_vars.mapgen_edge_min , mcl_vars.mg_nether_min -1, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.EDGE_MIN , mcl_vars.mg_nether_min -1, minp, maxp, lvm_used, pr) -- [[ THE NETHER: mcl_vars.mg_nether_min mcl_vars.mg_nether_max ]] diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index b8c746d1f..34105c094 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -81,7 +81,7 @@ local dir_step = storage:get_int("mcl_spawn_dir_step") or 0 local dir_ind = storage:get_int("mcl_spawn_dir_ind") or 1 local emerge_pos1, emerge_pos2 -local spawn_limit = mcl_vars.mapgen_edge_max +local spawn_limit = mcl_mapgen.EDGE_MAX --Functions diff --git a/mods/PLAYER/mcl_spawn/mod.conf b/mods/PLAYER/mcl_spawn/mod.conf index 954f831db..2c7953fe7 100644 --- a/mods/PLAYER/mcl_spawn/mod.conf +++ b/mods/PLAYER/mcl_spawn/mod.conf @@ -1,4 +1,4 @@ name = mcl_spawn author = Wuzzy description = Set and get the player's respawn position -depends = mcl_init +depends = mcl_mapgen From c23bb1d59dbcba9a1d1ba678591f1cdd4e620ccd Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 28 Apr 2021 03:03:47 +0400 Subject: [PATCH 07/61] [mapgen] rebalance mapgen/init core code --- mods/CORE/mcl_mapgen/init.lua | 166 ++++++------ mods/CORE/mcl_worlds/init.lua | 32 +-- mods/ENTITIES/mobs_mc_gameconfig/init.lua | 12 +- mods/ITEMS/mcl_portals/portal_nether.lua | 16 +- mods/MAPGEN/mcl_biomes/init.lua | 306 +++++++++++----------- mods/MAPGEN/mcl_biomes/mod.conf | 2 +- mods/MAPGEN/mcl_dungeons/init.lua | 6 +- mods/MAPGEN/mcl_mapgen_core/init.lua | 88 +++---- mods/MAPGEN/mcl_structures/init.lua | 6 +- mods/MAPGEN/mcl_villages/buildings.lua | 4 +- mods/MAPGEN/mcl_villages/utils.lua | 2 +- mods/MAPGEN/tsm_railcorridors/init.lua | 2 +- 12 files changed, 316 insertions(+), 326 deletions(-) diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index f5c6a16f9..74461a5fa 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -1,12 +1,17 @@ mcl_mapgen = {} +mcl_mapgen.overworld = {} +mcl_mapgen.nether = {} +mcl_mapgen.end = {} +local minetest_log, math_floor = minetest.log, math.floor +local minetest_get_node = minetest.get_node -- Calculate mapgen_edge_min/mapgen_edge_max mcl_mapgen.CS = math.max(1, tonumber(minetest.get_mapgen_setting("chunksize")) or 5) mcl_mapgen.BS = math.max(1, core.MAP_BLOCKSIZE or 16) mcl_mapgen.LIMIT = math.max(1, tonumber(minetest.get_mapgen_setting("mapgen_limit")) or 31000) mcl_mapgen.MAX_LIMIT = math.max(1, core.MAX_MAP_GENERATION_LIMIT or 31000) -mcl_mapgen.OFFSET = - math.floor(mcl_mapgen.CS / 2) +mcl_mapgen.OFFSET = - math_floor(mcl_mapgen.CS / 2) mcl_mapgen.OFFSET_NODES = mcl_mapgen.OFFSET * mcl_mapgen.BS mcl_mapgen.CS_NODES = mcl_mapgen.CS * mcl_mapgen.BS @@ -16,15 +21,17 @@ local central_chunk_max_pos = central_chunk_min_pos + mcl_mapgen.CS_NODES - 1 local ccfmin = central_chunk_min_pos - mcl_mapgen.BS -- Fullminp/fullmaxp of central chunk, in nodes local ccfmax = central_chunk_max_pos + mcl_mapgen.BS -local mapgen_limit_b = math.floor(math.min(mcl_mapgen.LIMIT, mcl_mapgen.MAX_LIMIT) / mcl_mapgen.BS) +local mapgen_limit_b = math_floor(math.min(mcl_mapgen.LIMIT, mcl_mapgen.MAX_LIMIT) / mcl_mapgen.BS) local mapgen_limit_min = - mapgen_limit_b * mcl_mapgen.BS local mapgen_limit_max = (mapgen_limit_b + 1) * mcl_mapgen.BS - 1 -local numcmin = math.max(math.floor((ccfmin - mapgen_limit_min) / mcl_vars.chunk_size_in_nodes), 0) -- Number of complete chunks from central chunk -local numcmax = math.max(math.floor((mapgen_limit_max - ccfmax) / mcl_vars.chunk_size_in_nodes), 0) -- fullminp/fullmaxp to effective mapgen limits. +local numcmin = math.max(math_floor((ccfmin - mapgen_limit_min) / mcl_mapgen.CS_NODES), 0) -- Number of complete chunks from central chunk +local numcmax = math.max(math_floor((mapgen_limit_max - ccfmax) / mcl_mapgen.CS_NODES), 0) -- fullminp/fullmaxp to effective mapgen limits. mcl_mapgen.EDGE_MIN = central_chunk_min_pos - numcmin * mcl_mapgen.CS_NODES mcl_mapgen.EDGE_MAX = central_chunk_max_pos + numcmax * mcl_mapgen.CS_NODES + +minetest_log("action", "[mcl_mapgen] World edges are: mcl_mapgen.EDGE_MIN = " .. tostring(mcl_mapgen.EDGE_MIN) .. ", mcl_mapgen.EDGE_MAX = " .. tostring(mcl_mapgen.EDGE_MAX)) ------------------------------------------ @@ -33,12 +40,10 @@ local lvm, block, lvm_block, lvm_chunk, param2, nodes_block, nodes_chunk = 0, 0, local lvm_buffer, lvm_param2_buffer = {}, {} -- Static buffer pointers local BS, CS = mcl_mapgen.BS, mcl_mapgen.CS -- Mapblock size (in nodes), Mapchunk size (in blocks) local LAST_BLOCK, LAST_NODE = CS - 1, BS - 1 -- First mapblock in chunk (node in mapblock) has number 0, last has THIS number. It's for runtime optimization -local offset = math.floor(mcl_vars.central_chunk_offset_in_nodes / BS) -- Central mapchunk offset (in blocks) +local offset = mcl_mapgen.OFFSET -- Central mapchunk offset (in blocks) local DEFAULT_PRIORITY = 5000 -local minetest_log, math_floor = minetest.log, math.floor - function mcl_mapgen.register_chunk_generator(callback_function, priority) nodes_chunk = nodes_chunk + 1 node_chunk_queue[nodes_chunk] = {i = priority or DEFAULT_PRIORITY, f = callback_function} @@ -141,15 +146,17 @@ minetest.register_on_generated(function(minp, maxp, blockseed) end end - if vm_context.write then - vm:set_data(data) + if lvm > 0 then + if vm_context.write then + vm:set_data(data) + end + if vm_context.write_param2 then + vm:set_param2_data(data2) + end + vm:calc_lighting(minp, maxp, vm_context.shadow) -- TODO: check boundaries + vm:write_to_map() + vm:update_liquids() end - if vm_context.write_param2 then - vm:set_param2_data(data2) - end - vm:calc_lighting(p1, p2, shadow) - vm:write_to_map() - vm:update_liquids() for _, v in pairs(node_chunk_queue) do v.f(minp, maxp, blockseed) @@ -174,11 +181,11 @@ function mcl_mapgen.get_far_node(p) end local function coordinate_to_block(x) - return math_floor(x / mcl_mapgen.BS) + return math_floor(x / BS) end local function coordinate_to_chunk(x) - return math_floor((coordinate_to_block(x) - central_chunk_offset) / mcl_mapgen.CS) + return math_floor((coordinate_to_block(x) - offset) / CS) end function mcl_mapgen.pos_to_block(pos) @@ -197,7 +204,7 @@ function mcl_mapgen.pos_to_chunk(pos) } end -local k_positive = math.ceil(mcl_mapgen.MAX_LIMIT / mcl_vars.chunk_size_in_nodes) +local k_positive = math.ceil(mcl_mapgen.MAX_LIMIT / mcl_mapgen.CS_NODES) local k_positive_z = k_positive * 2 local k_positive_y = k_positive_z * k_positive_z @@ -210,96 +217,79 @@ function mcl_mapgen.get_chunk_number(pos) -- unsigned int end - - - -- Mapgen variables -local mg_name = minetest.get_mapgen_setting("mg_name") -local minecraft_height_limit = 256 -local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" -local singlenode = mg_name == "singlenode" +mcl_mapgen.name = minetest.get_mapgen_setting("mg_name") +mcl_mapgen.superflat = mcl_mapgen.name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" +mcl_mapgen.singlenode = mcl_mapgen.name == "singlenode" +mcl_mapgen.normal = not mcl_mapgen.superflat and not mcl_mapgen.singlenode +local superflat, singlenode, normal = mcl_mapgen.superflat, mcl_mapgen.singlenode, mcl_mapgen.normal -if not superflat and not singlenode then - -- Normal mode - --[[ Realm stacking (h is for height) - - Overworld (h>=256) - - Void (h>=1000) - - Realm Barrier (h=11), to allow escaping the End - - End (h>=256) - - Void (h>=1000) - - Nether (h=128) - - Void (h>=1000) - ]] +minetest_log("action", "[mcl_mapgen] Mapgen mode: " .. normal and "normal" or (superflat and "superflat" or "singlenode")) - -- Overworld - mcl_vars.mg_overworld_min = -62 - mcl_vars.mg_overworld_max_official = mcl_vars.mg_overworld_min + minecraft_height_limit - mcl_vars.mg_bedrock_overworld_min = mcl_vars.mg_overworld_min - mcl_vars.mg_bedrock_overworld_max = mcl_vars.mg_bedrock_overworld_min + 4 - mcl_vars.mg_lava_overworld_max = mcl_vars.mg_overworld_min + 10 - mcl_vars.mg_lava = true - mcl_vars.mg_bedrock_is_rough = true +mcl_mapgen.minecraft_height_limit = 256 -elseif singlenode then - mcl_vars.mg_overworld_min = -66 - mcl_vars.mg_overworld_max_official = mcl_vars.mg_overworld_min + minecraft_height_limit - mcl_vars.mg_bedrock_overworld_min = mcl_vars.mg_overworld_min - mcl_vars.mg_bedrock_overworld_max = mcl_vars.mg_bedrock_overworld_min - mcl_vars.mg_lava = false - mcl_vars.mg_lava_overworld_max = mcl_vars.mg_overworld_min - mcl_vars.mg_bedrock_is_rough = false -else - -- Classic superflat - local ground = minetest.get_mapgen_setting("mgflat_ground_level") - ground = tonumber(ground) - if not ground then - ground = 8 - end - mcl_vars.mg_overworld_min = ground - 3 - mcl_vars.mg_overworld_max_official = mcl_vars.mg_overworld_min + minecraft_height_limit - mcl_vars.mg_bedrock_overworld_min = mcl_vars.mg_overworld_min - mcl_vars.mg_bedrock_overworld_max = mcl_vars.mg_bedrock_overworld_min - mcl_vars.mg_lava = false - mcl_vars.mg_lava_overworld_max = mcl_vars.mg_overworld_min - mcl_vars.mg_bedrock_is_rough = false +mcl_mapgen.bedrock_is_rough = normal + +--[[ Realm stacking (h is for height) +- Overworld (h>=256) +- Void (h>=1000) +- Realm Barrier (h=11), to allow escaping the End +- End (h>=256) +- Void (h>=1000) +- Nether (h=128) +- Void (h>=1000) +]] + +-- Overworld +mcl_mapgen.overworld.min = -62 +if superflat then + mcl_mapgen.ground = tonumber(minetest.get_mapgen_setting("mgflat_ground_level")) or 8 + mcl_mapgen.overworld.min = ground - 3 end +-- if singlenode then mcl_mapgen.overworld.min = -66 end -- DONT KNOW WHY +mcl_mapgen.overworld.max = mcl_mapgen.EDGE_MAX + +mcl_mapgen.overworld.bedrock_min = mcl_mapgen.overworld.min +mcl_mapgen.overworld.bedrock_max = mcl_mapgen.overworld.bedrock_min + (mcl_mapgen.bedrock_is_rough and 4 or 0) + +mcl_mapgen.lava = normal +mcl_mapgen.lava_overworld_max = mcl_mapgen.overworld.min + (normal and 10 or 0) -mcl_vars.mg_overworld_max = mcl_mapgen.EDGE_MAX -- The Nether (around Y = -29000) -mcl_vars.mg_nether_min = -29067 -- Carefully chosen to be at a mapchunk border -mcl_vars.mg_nether_max = mcl_vars.mg_nether_min + 128 -mcl_vars.mg_bedrock_nether_bottom_min = mcl_vars.mg_nether_min -mcl_vars.mg_bedrock_nether_top_max = mcl_vars.mg_nether_max +mcl_mapgen.nether.min = -29067 -- Carefully chosen to be at a mapchunk border +mcl_mapgen.nether.max = mcl_mapgen.nether.min + 128 +mcl_mapgen.nether.bedrock_bottom_min = mcl_mapgen.nether.min +mcl_mapgen.nether.bedrock_top_max = mcl_mapgen.nether.max if not superflat then - mcl_vars.mg_bedrock_nether_bottom_max = mcl_vars.mg_bedrock_nether_bottom_min + 4 - mcl_vars.mg_bedrock_nether_top_min = mcl_vars.mg_bedrock_nether_top_max - 4 - mcl_vars.mg_lava_nether_max = mcl_vars.mg_nether_min + 31 + mcl_mapgen.nether.bedrock_bottom_max = mcl_vars.mg_bedrock_nether_bottom_min + 4 + mcl_mapgen.nether.bedrock_top_min = mcl_vars.mg_bedrock_nether_top_max - 4 + mcl_mapgen.nether.lava_max = mcl_mapgen.nether.min + 31 else -- Thin bedrock in classic superflat mapgen - mcl_vars.mg_bedrock_nether_bottom_max = mcl_vars.mg_bedrock_nether_bottom_min - mcl_vars.mg_bedrock_nether_top_min = mcl_vars.mg_bedrock_nether_top_max - mcl_vars.mg_lava_nether_max = mcl_vars.mg_nether_min + 2 + mcl_mapgen.nether.bedrock_bottom_max = mcl_vars.mg_bedrock_nether_bottom_min + mcl_mapgen.nether.bedrock_top_min = mcl_vars.mg_bedrock_nether_top_max + mcl_mapgen.nether.lava_max = mcl_mapgen.nether.min + 2 end -if mg_name == "flat" then +if mcl_mapgen.name == "flat" then if superflat then - mcl_vars.mg_flat_nether_floor = mcl_vars.mg_bedrock_nether_bottom_max + 4 - mcl_vars.mg_flat_nether_ceiling = mcl_vars.mg_bedrock_nether_bottom_max + 52 + mcl_mapgen.nether.flat_nether_floor = mcl_mapgen.nether.bedrock_nether_bottom_max + 4 + mcl_mapgen.nether.flat_nether_ceiling = mcl_mapgen.nether.bedrock_nether_bottom_max + 52 else - mcl_vars.mg_flat_nether_floor = mcl_vars.mg_lava_nether_max + 4 - mcl_vars.mg_flat_nether_ceiling = mcl_vars.mg_lava_nether_max + 52 + mcl_mapgen.nether.flat_nether_floor = mcl_mapgen.nether.lava_nether_max + 4 + mcl_mapgen.nether.flat_nether_ceiling = mcl_mapgen.nether.lava_nether_max + 52 end end -- The End (surface at ca. Y = -27000) -mcl_vars.mg_end_min = -27073 -- Carefully chosen to be at a mapchunk border -mcl_vars.mg_end_max_official = mcl_vars.mg_end_min + minecraft_height_limit -mcl_vars.mg_end_max = mcl_vars.mg_overworld_min - 2000 -mcl_vars.mg_end_platform_pos = { x = 100, y = mcl_vars.mg_end_min + 74, z = 0 } +mcl_mapgen.end.min = -27073 -- Carefully chosen to be at a mapchunk border +mcl_mapgen.end.max_official = mcl_mapgen.end.min + mcl_mapgen.minecraft_height_limit +mcl_mapgen.end.max = mcl_mapgen.overworld.min - 2000 +mcl_vars.mg_end_platform_pos = { x = 100, y = mcl_mapgen.end.min + 74, z = 0 } -- Realm barrier used to safely separate the End from the void below the Overworld -mcl_vars.mg_realm_barrier_overworld_end_max = mcl_vars.mg_end_max -mcl_vars.mg_realm_barrier_overworld_end_min = mcl_vars.mg_end_max - 11 +mcl_vars.mg_realm_barrier_overworld_end_max = mcl_mapgen.end.max +mcl_vars.mg_realm_barrier_overworld_end_min = mcl_mapgen.end.max - 11 -- Use MineClone 2-style dungeons mcl_vars.mg_dungeons = true diff --git a/mods/CORE/mcl_worlds/init.lua b/mods/CORE/mcl_worlds/init.lua index 6cdeaab7e..a9d9ea050 100644 --- a/mods/CORE/mcl_worlds/init.lua +++ b/mods/CORE/mcl_worlds/init.lua @@ -3,25 +3,25 @@ mcl_worlds = {} -- For a given position, returns a 2-tuple: -- 1st return value: true if pos is in void -- 2nd return value: true if it is in the deadly part of the void +local min1, min2, min3 = mcl_mapgen.overworld.min, mcl_mapgen.end.min, mcl_mapgen.nether.min +local max1, max2, max3 = mcl_mapgen.overworld.max, mcl_mapgen.end.max, mcl_mapgen.nether.max+128 function mcl_worlds.is_in_void(pos) - local void = - not ((pos.y < mcl_vars.mg_overworld_max and pos.y > mcl_vars.mg_overworld_min) or - (pos.y < mcl_vars.mg_nether_max+128 and pos.y > mcl_vars.mg_nether_min) or - (pos.y < mcl_vars.mg_end_max and pos.y > mcl_vars.mg_end_min)) + local y = pos.y + local void = not ((y < max1 and y > min1) or (y < max2 and y > min2) or (y < max3 and y > min3)) local void_deadly = false local deadly_tolerance = 64 -- the player must be this many nodes “deep” into the void to be damaged if void then -- Overworld → Void → End → Void → Nether → Void - if pos.y < mcl_vars.mg_overworld_min and pos.y > mcl_vars.mg_end_max then - void_deadly = pos.y < mcl_vars.mg_overworld_min - deadly_tolerance - elseif pos.y < mcl_vars.mg_end_min and pos.y > mcl_vars.mg_nether_max+128 then + if y < mcl_vars.min1 and y > max2 then + void_deadly = y < min1 - deadly_tolerance + elseif y < min2 and y > max3 then -- The void between End and Nether. Like usual, but here, the void -- *above* the Nether also has a small tolerance area, so player -- can fly above the Nether without getting hurt instantly. - void_deadly = (pos.y < mcl_vars.mg_end_min - deadly_tolerance) and (pos.y > mcl_vars.mg_nether_max+128 + deadly_tolerance) - elseif pos.y < mcl_vars.mg_nether_min then - void_deadly = pos.y < mcl_vars.mg_nether_min - deadly_tolerance + void_deadly = (y < min2 - deadly_tolerance) and (y > max3 + deadly_tolerance) + elseif y < min3 then + void_deadly = y < min3 - deadly_tolerance end end return void, void_deadly @@ -33,12 +33,12 @@ end -- If the Y coordinate is not located in any dimension, it will return: -- nil, "void" function mcl_worlds.y_to_layer(y) - if y >= mcl_vars.mg_overworld_min then - return y - mcl_vars.mg_overworld_min, "overworld" - elseif y >= mcl_vars.mg_nether_min and y <= mcl_vars.mg_nether_max+128 then - return y - mcl_vars.mg_nether_min, "nether" - elseif y >= mcl_vars.mg_end_min and y <= mcl_vars.mg_end_max then - return y - mcl_vars.mg_end_min, "end" + if y >= min1 then + return y - min1, "overworld" + elseif y >= min3 and y <= max3 then + return y - min3, "nether" + elseif y >= min2 and y <= max2 then + return y - min2, "end" else return nil, "void" end diff --git a/mods/ENTITIES/mobs_mc_gameconfig/init.lua b/mods/ENTITIES/mobs_mc_gameconfig/init.lua index 06d7eb87f..dd310c1b3 100644 --- a/mods/ENTITIES/mobs_mc_gameconfig/init.lua +++ b/mods/ENTITIES/mobs_mc_gameconfig/init.lua @@ -233,15 +233,15 @@ mobs_mc.override.spawn_height = { water = tonumber(minetest.settings:get("water_level")) or 0, -- Water level in the Overworld -- Overworld boundaries (inclusive) - overworld_min = mcl_vars.mg_overworld_min, - overworld_max = mcl_vars.mg_overworld_max, + overworld_min = mcl_mapgen.overworld.min, + overworld_max = mcl_mapgen.overworld.max, -- Nether boundaries (inclusive) - nether_min = mcl_vars.mg_nether_min, - nether_max = mcl_vars.mg_nether_max, + nether_min = mcl_mapgen.nether.min, + nether_max = mcl_mapgen.nether.max, -- End boundaries (inclusive) - end_min = mcl_vars.mg_end_min, - end_max = mcl_vars.mg_end_max, + end_min = mcl_mapgen.end.min, + end_max = mcl_mapgen.end.max, } diff --git a/mods/ITEMS/mcl_portals/portal_nether.lua b/mods/ITEMS/mcl_portals/portal_nether.lua index 7fd0191fa..ee38264da 100644 --- a/mods/ITEMS/mcl_portals/portal_nether.lua +++ b/mods/ITEMS/mcl_portals/portal_nether.lua @@ -27,7 +27,7 @@ local DELAY = 3 -- seconds before teleporting in Nether portal in Survival mo local DISTANCE_MAX = 128 local PORTAL = "mcl_portals:portal" local OBSIDIAN = "mcl_core:obsidian" -local O_Y_MIN, O_Y_MAX = max(mcl_vars.mg_overworld_min, -31), min(mcl_vars.mg_overworld_max, 2048) +local O_Y_MIN, O_Y_MAX = max(mcl_mapgen.overworld.min, -31), min(mcl_mapgen.overworld.max, 2048) local N_Y_MIN, N_Y_MAX = mcl_vars.mg_bedrock_nether_bottom_min, mcl_vars.mg_bedrock_nether_top_min - H_MIN -- Alpha and particles @@ -66,7 +66,7 @@ minetest.register_on_shutdown(function() storage:set_string("nether_exits_keys", minetest.serialize(keys)) end) -local get_node = mcl_vars.get_node +local get_node = mcl_mapgen.get_far_node local set_node = minetest.set_node local registered_nodes = minetest.registered_nodes local is_protected = minetest.is_protected @@ -414,7 +414,7 @@ local function create_portal_2(pos1, name, obj) end local exit = build_nether_portal(pos1, W_MIN-2, H_MIN-2, orientation, name) finalize_teleport(obj, exit) - local cn = mcl_vars.get_chunk_number(pos1) + local cn = mcl_mapgen.get_chunk_number(pos1) chunks[cn] = nil if queue[cn] then for next_obj, _ in pairs(queue[cn]) do @@ -428,9 +428,9 @@ end local function get_lava_level(pos, pos1, pos2) if pos.y > -1000 then - return max(min(mcl_vars.mg_lava_overworld_max, pos2.y-1), pos1.y+1) + return max(min(mcl_mapgen.overworld.lava_max, pos2.y-1), pos1.y+1) end - return max(min(mcl_vars.mg_lava_nether_max, pos2.y-1), pos1.y+1) + return max(min(mcl_mapgen.nether.lava_max, pos2.y-1), pos1.y+1) end local function ecb_scan_area_2(blockpos, action, calls_remaining, param) @@ -509,7 +509,7 @@ local function ecb_scan_area_2(blockpos, action, calls_remaining, param) end local function create_portal(pos, limit1, limit2, name, obj) - local cn = mcl_vars.get_chunk_number(pos) + local cn = mcl_mapgen.get_chunk_number(pos) if chunks[cn] then local q = queue[cn] or {} q[obj] = true @@ -537,8 +537,8 @@ local function create_portal(pos, limit1, limit2, name, obj) end -- Basically the copy of code above, with minor additions to continue the search in single additional chunk below: - local next_chunk_1 = {x = pos1.x, y = pos1.y - mcl_vars.chunk_size_in_nodes, z = pos1.z} - local next_chunk_2 = add(next_chunk_1, mcl_vars.chunk_size_in_nodes - 1) + local next_chunk_1 = {x = pos1.x, y = pos1.y - mcl_mapgen.CS_NODES, z = pos1.z} + local next_chunk_2 = add(next_chunk_1, mcl_mapgen.CS_NODES - 1) local next_pos = {x = pos.x, y=max(next_chunk_2.y, limit1.y), z = pos.z} if limit1 and limit1.x and limit1.y and limit1.z then pos1 = {x = max(min(limit1.x, pos.x), pos1.x), y = max(min(limit1.y, pos.y), pos1.y), z = max(min(limit1.z, pos.z), pos1.z)} diff --git a/mods/MAPGEN/mcl_biomes/init.lua b/mods/MAPGEN/mcl_biomes/init.lua index 9facd83b3..3cfeea048 100644 --- a/mods/MAPGEN/mcl_biomes/init.lua +++ b/mods/MAPGEN/mcl_biomes/init.lua @@ -32,8 +32,8 @@ local function register_classic_superflat_biome() node_filler = "mcl_core:dirt", depth_filler = 3, node_stone = "mcl_core:dirt", - y_min = mcl_vars.mg_overworld_min - 512, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min - 512, + y_max = mcl_mapgen.overworld.max, humidity_point = 50, heat_point = 50, _mcl_biome_type = "medium", @@ -136,7 +136,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 24, heat_point = -5, _mcl_biome_type = "snowy", @@ -170,7 +170,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 3, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 58, heat_point = 8, _mcl_biome_type = "snowy", @@ -241,7 +241,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 76, heat_point = 10, _mcl_biome_type = "cold", @@ -273,7 +273,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 100, heat_point = 8, _mcl_biome_type = "cold", @@ -306,7 +306,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 4, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 10, heat_point = 45, _mcl_biome_type = "cold", @@ -356,7 +356,7 @@ local function register_biomes() node_riverbed = "mcl_core:gravel", depth_riverbed = 3, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 0, heat_point = 25, _mcl_biome_type = "cold", @@ -409,7 +409,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 4, y_min = 42, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 24, heat_point = 25, _mcl_biome_type = "cold", @@ -439,7 +439,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 1, y_min = -7, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 0, heat_point = 8, _mcl_biome_type = "cold", @@ -475,7 +475,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 24, heat_point = 8, _mcl_biome_type = "snowy", @@ -507,7 +507,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 3, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 39, heat_point = 58, _mcl_biome_type = "medium", @@ -554,7 +554,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 28, heat_point = 45, _mcl_biome_type = "medium", @@ -586,7 +586,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 58, heat_point = 22, _mcl_biome_type = "cold", @@ -633,7 +633,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 61, heat_point = 45, _mcl_biome_type = "medium", @@ -680,7 +680,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 3, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 44, heat_point = 32, _mcl_biome_type = "medium", @@ -727,7 +727,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 78, heat_point = 31, _mcl_biome_type = "medium", @@ -759,7 +759,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 77, heat_point = 27, _mcl_biome_type = "medium", @@ -792,7 +792,7 @@ local function register_biomes() depth_riverbed = 2, node_stone = "mcl_core:sandstone", y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 26, heat_point = 94, _mcl_biome_type = "hot", @@ -824,7 +824,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 94, heat_point = 27, _mcl_biome_type = "medium", @@ -857,7 +857,7 @@ local function register_biomes() depth_riverbed = 1, node_stone = "mcl_colorblocks:hardened_clay", y_min = 11, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 0, heat_point = 100, _mcl_biome_type = "hot", @@ -907,7 +907,7 @@ local function register_biomes() depth_riverbed = 1, node_stone = "mcl_colorblocks:hardened_clay", y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = -5, heat_point = 100, _mcl_biome_type = "hot", @@ -979,7 +979,7 @@ local function register_biomes() depth_riverbed = 1, node_stone = "mcl_colorblocks:hardened_clay", y_min = 30, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 0, heat_point = 60, _mcl_biome_type = "hot", @@ -1049,7 +1049,7 @@ local function register_biomes() depth_riverbed = 1, node_stone = "mcl_colorblocks:hardened_clay", y_min = 30, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = -5, heat_point = 60, _mcl_biome_type = "hot", @@ -1101,7 +1101,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 36, heat_point = 79, _mcl_biome_type = "hot", @@ -1150,7 +1150,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 48, heat_point = 100, _mcl_biome_type = "hot", @@ -1182,7 +1182,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 88, heat_point = 81, _mcl_biome_type = "medium", @@ -1231,7 +1231,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 92, heat_point = 81, _mcl_biome_type = "medium", @@ -1279,7 +1279,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 88, heat_point = 76, _mcl_biome_type = "medium", @@ -1314,7 +1314,7 @@ local function register_biomes() node_riverbed = "mcl_core:sand", depth_riverbed = 2, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, humidity_point = 90, heat_point = 79, _mcl_biome_type = "medium", @@ -1464,7 +1464,7 @@ local function register_biomes() name = biome .. "_underground", heat_point = minetest.registered_biomes[biome].heat_point, humidity_point = minetest.registered_biomes[biome].humidity_point, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = DEEP_OCEAN_MIN - 1, _mcl_biome_type = minetest.registered_biomes[biome]._mcl_biome_type, _mcl_palette_index = minetest.registered_biomes[biome]._mcl_palette_index, @@ -1485,10 +1485,10 @@ local function register_dimension_biomes() node_water = "air", node_river_water = "air", node_cave_liquid = "air", - y_min = mcl_vars.mg_nether_min, + y_min = mcl_mapgen.nether.min, -- FIXME: For some reason the Nether stops generating early if this constant is not added. -- Figure out why. - y_max = mcl_vars.mg_nether_max + 80, + y_max = mcl_mapgen.nether.max + 80, heat_point = 100, humidity_point = 0, _mcl_biome_type = "hot", @@ -1505,8 +1505,8 @@ local function register_dimension_biomes() node_cave_liquid = "air", -- FIXME: For some reason the End stops generating early if this constant is not added. -- Figure out why. - y_min = mcl_vars.mg_end_min, - y_max = mcl_vars.mg_end_max + 80, + y_min = mcl_mapgen.end.min, + y_max = mcl_mapgen.end.max + 80, heat_point = 50, humidity_point = 50, _mcl_biome_type = "medium", @@ -1551,7 +1551,7 @@ local function register_biome_ores() clust_scarcity = monster_egg_scarcity, clust_num_ores = 3, clust_size = 2, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(61), biomes = { "ExtremeHills", "ExtremeHills_beach", "ExtremeHills_ocean", "ExtremeHills_deep_ocean", "ExtremeHills_underground", @@ -1590,8 +1590,8 @@ local function register_biomelike_ores() clust_scarcity = 1, clust_num_ores = 12, clust_size = 10, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_threshold = 0.2, noise_params = {offset=0, scale=15, spread={x=130, y=130, z=130}, seed=24, octaves=3, persist=0.70}, biomes = { "MegaTaiga" }, @@ -1603,8 +1603,8 @@ local function register_biomelike_ores() wherein = {"mcl_core:dirt_with_grass", "mcl_core:dirt"}, column_height_max = 1, column_midpoint_factor = 0.0, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_threshold = 0.0, noise_params = {offset=0, scale=15, spread={x=250, y=250, z=250}, seed=24, octaves=3, persist=0.70}, biomes = { "MesaPlateauF_grasstop" }, @@ -1616,8 +1616,8 @@ local function register_biomelike_ores() clust_scarcity = 1500, clust_num_ores = 25, clust_size = 7, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_params = { offset = 0, scale = 1, @@ -1636,8 +1636,8 @@ local function register_biomelike_ores() wherein = {"mcl_core:dirt_with_grass", "mcl_core:dirt"}, column_height_max = 1, column_midpoint_factor = 0.0, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_threshold = -2.5, noise_params = {offset=1, scale=15, spread={x=250, y=250, z=250}, seed=24, octaves=3, persist=0.80}, biomes = { "MesaPlateauFM_grasstop" }, @@ -1649,8 +1649,8 @@ local function register_biomelike_ores() clust_scarcity = 1800, clust_num_ores = 65, clust_size = 15, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_params = { offset = 0, scale = 1, @@ -1670,8 +1670,8 @@ local function register_biomelike_ores() wherein = {"group:hardened_clay", "group:sand","mcl_core:coarse_dirt"}, clust_scarcity = 4000, clust_size = 5, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_params = { offset = 0, scale = 1, @@ -1690,8 +1690,8 @@ local function register_biomelike_ores() wherein = {"mcl_colorblocks:hardened_clay_orange"}, clust_scarcity = 300, clust_size = 8, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_params = { offset = 0, scale = 1, @@ -1712,8 +1712,8 @@ local function register_biomelike_ores() clust_scarcity = 1, clust_num_ores = 12, clust_size = 10, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_threshold = 0.1, noise_params = {offset=0, scale=15, spread={x=130, y=130, z=130}, seed=95, octaves=3, persist=0.70}, biomes = { "MesaPlateauFM" }, @@ -1724,8 +1724,8 @@ local function register_biomelike_ores() wherein = {"group:hardened_clay"}, clust_scarcity = 1500, clust_size = 4, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_params = { offset = 0, scale = 1, @@ -1748,8 +1748,8 @@ local function register_biomelike_ores() clust_scarcity = 5000, clust_num_ores = 12, clust_size = 4, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_threshold = 0.2, noise_params = {offset=0, scale=5, spread={x=250, y=250, z=250}, seed=64, octaves=3, persist=0.60}, biomes = { "ExtremeHillsM" }, @@ -1947,7 +1947,7 @@ local function register_dimension_ores() wherein = {"mcl_nether:netherrack", "mcl_core:stone"}, clust_scarcity = 13 * 13 * 13, clust_size = 5, - y_min = mcl_vars.mg_nether_min, + y_min = mcl_mapgen.nether.min, y_max = mcl_worlds.layer_to_y(64, "nether"), noise_threshold = 0.0, noise_params = { @@ -2010,7 +2010,7 @@ local function register_dimension_ores() clust_scarcity = 26 * 26 * 26, clust_size = 5, y_min = mcl_vars.mg_lava_nether_max + 10, - y_max = mcl_vars.mg_nether_max, + y_max = mcl_mapgen.nether.max, noise_threshold = 0.0, noise_params = { offset = 0.5, @@ -2053,8 +2053,8 @@ local function register_dimension_ores() clust_scarcity = 850, clust_num_ores = 4, -- MC cluster amount: 4-10 clust_size = 3, - y_min = mcl_vars.mg_nether_min, - y_max = mcl_vars.mg_nether_max, + y_min = mcl_mapgen.nether.min, + y_max = mcl_mapgen.nether.max, }) minetest.register_ore({ ore_type = "scatter", @@ -2063,8 +2063,8 @@ local function register_dimension_ores() clust_scarcity = 1650, clust_num_ores = 8, -- MC cluster amount: 4-10 clust_size = 4, - y_min = mcl_vars.mg_nether_min, - y_max = mcl_vars.mg_nether_max, + y_min = mcl_mapgen.nether.min, + y_max = mcl_mapgen.nether.max, }) end @@ -2076,7 +2076,7 @@ local function register_dimension_ores() clust_scarcity = 500, clust_num_ores = 1, clust_size = 1, - y_min = mcl_vars.mg_nether_min, + y_min = mcl_mapgen.nether.min, y_max = mcl_vars.mg_lava_nether_max + 1, }) @@ -2109,7 +2109,7 @@ local function register_dimension_ores() clust_num_ores = 1, clust_size = 1, y_min = mcl_vars.mg_lava_nether_max + 49, - y_max = mcl_vars.mg_nether_max, + y_max = mcl_mapgen.nether.max, }) --[[ THE END ]] @@ -2129,11 +2129,11 @@ local function register_dimension_ores() ore_type = "stratum", ore = "mcl_end:end_stone", wherein = end_wherein, - y_min = mcl_vars.mg_end_min+64, - y_max = mcl_vars.mg_end_min+80, + y_min = mcl_mapgen.end.min+64, + y_max = mcl_mapgen.end.min+80, noise_params = { - offset = mcl_vars.mg_end_min+70, + offset = mcl_mapgen.end.min+70, scale = -1, spread = {x=126, y=126, z=126}, seed = mg_seed+9999, @@ -2156,11 +2156,11 @@ local function register_dimension_ores() ore_type = "stratum", ore = "mcl_end:end_stone", wherein = end_wherein, - y_min = mcl_vars.mg_end_min+64, - y_max = mcl_vars.mg_end_min+80, + y_min = mcl_mapgen.end.min+64, + y_max = mcl_mapgen.end.min+80, noise_params = { - offset = mcl_vars.mg_end_min+72, + offset = mcl_mapgen.end.min+72, scale = -3, spread = {x=84, y=84, z=84}, seed = mg_seed+999, @@ -2182,11 +2182,11 @@ local function register_dimension_ores() ore_type = "stratum", ore = "mcl_end:end_stone", wherein = end_wherein, - y_min = mcl_vars.mg_end_min+64, - y_max = mcl_vars.mg_end_min+80, + y_min = mcl_mapgen.end.min+64, + y_max = mcl_mapgen.end.min+80, noise_params = { - offset = mcl_vars.mg_end_min+70, + offset = mcl_mapgen.end.min+70, scale = -2, spread = {x=84, y=84, z=84}, seed = mg_seed+99, @@ -2239,7 +2239,7 @@ local function register_grass_decoration(grasstype, offset, scale, biomes) noise_params = noise, biomes = { biomes[b] }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = node, param2 = param2, }) @@ -2306,7 +2306,7 @@ local function register_decorations() }, biomes = {"IcePlainsSpikes"}, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_ice_spike_large.mts", rotation = "random", flags = "place_center_x, place_center_z", @@ -2327,7 +2327,7 @@ local function register_decorations() }, biomes = {"IcePlainsSpikes"}, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_ice_spike_small.mts", rotation = "random", flags = "place_center_x, place_center_z", @@ -2350,7 +2350,7 @@ local function register_decorations() }, biomes = {"Forest"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_large_"..i..".mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2370,7 +2370,7 @@ local function register_decorations() }, biomes = {"ExtremeHills", "ExtremeHillsM", "ExtremeHills+", "ExtremeHills+_snowtop"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_large_"..i..".mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2391,7 +2391,7 @@ local function register_decorations() }, biomes = {"Forest"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_classic.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2410,7 +2410,7 @@ local function register_decorations() }, biomes = {"FlowerForest"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_classic.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2429,7 +2429,7 @@ local function register_decorations() }, biomes = {"ExtremeHills", "ExtremeHillsM", "ExtremeHills+", "ExtremeHills+_snowtop"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_classic.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2449,7 +2449,7 @@ local function register_decorations() }, biomes = {"ExtremeHills+", "ExtremeHills+_snowtop"}, y_min = 50, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_classic.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2468,7 +2468,7 @@ local function register_decorations() }, biomes = {"MesaPlateauF_grasstop"}, y_min = 30, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_classic.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2487,7 +2487,7 @@ local function register_decorations() }, biomes = {"MesaPlateauFM_grasstop"}, y_min = 30, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_classic.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2507,7 +2507,7 @@ local function register_decorations() }, biomes = {"IcePlains"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_classic.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2519,7 +2519,7 @@ local function register_decorations() fill_ratio = 0.004, biomes = {"Jungle", "JungleM"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_classic.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2531,7 +2531,7 @@ local function register_decorations() fill_ratio = 0.0004, biomes = {"JungleEdge", "JungleEdgeM", "Savanna"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_classic.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2553,7 +2553,7 @@ local function register_decorations() }, biomes = {"Forest"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_balloon.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2574,7 +2574,7 @@ local function register_decorations() }, biomes = {"Swampland", "Swampland_shore"}, y_min = 0, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_oak_swamp.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2591,7 +2591,7 @@ local function register_decorations() fill_ratio = 0.00125, biomes = {"Jungle"}, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_jungle_tree_huge_"..i..".mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2603,7 +2603,7 @@ local function register_decorations() fill_ratio = 0.004, biomes = {"JungleM"}, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_jungle_tree_huge_"..i..".mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2618,7 +2618,7 @@ local function register_decorations() fill_ratio = 0.045, biomes = {"Jungle"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_jungle_tree.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2630,7 +2630,7 @@ local function register_decorations() fill_ratio = 0.0045, biomes = {"JungleEdge", "JungleEdgeM"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_jungle_tree.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2643,7 +2643,7 @@ local function register_decorations() fill_ratio = 0.09, biomes = {"JungleM"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_jungle_tree.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2668,7 +2668,7 @@ local function register_decorations() }, biomes = biomes, y_min = y, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/"..sprucename, flags = "place_center_x, place_center_z", }) @@ -2722,7 +2722,7 @@ local function register_decorations() }, biomes = {"Taiga", "ColdTaiga"}, y_min = 2, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_spruce_lollipop.mts", flags = "place_center_x, place_center_z", }) @@ -2742,7 +2742,7 @@ local function register_decorations() }, biomes = {"Taiga", "ColdTaiga"}, y_min = 3, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_spruce_matchstick.mts", flags = "place_center_x, place_center_z", }) @@ -2762,7 +2762,7 @@ local function register_decorations() }, biomes = {"IcePlains"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_spruce_5.mts", flags = "place_center_x, place_center_z", }) @@ -2776,7 +2776,7 @@ local function register_decorations() fill_ratio = 0.0002, biomes = {"Savanna", "SavannaM"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_acacia_"..a..".mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2798,7 +2798,7 @@ local function register_decorations() }, biomes = {"BirchForest"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_birch.mts", flags = "place_center_x, place_center_z", }) @@ -2816,7 +2816,7 @@ local function register_decorations() }, biomes = {"BirchForestM"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_birch_tall.mts", flags = "place_center_x, place_center_z", }) @@ -2835,7 +2835,7 @@ local function register_decorations() }, biomes = {"Forest", "FlowerForest"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_birch.mts", flags = "place_center_x, place_center_z", }) @@ -2855,7 +2855,7 @@ local function register_decorations() }, biomes = {"RoofedForest"}, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_dark_oak.mts", flags = "place_center_x, place_center_z", rotation = "random", @@ -2877,7 +2877,7 @@ local function register_decorations() fill_ratio = ratio_mushroom_huge, biomes = { "RoofedForest" }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_brown.mts", flags = "place_center_x, place_center_z", rotation = "0", @@ -2889,7 +2889,7 @@ local function register_decorations() fill_ratio = ratio_mushroom_giant, biomes = { "RoofedForest" }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_giant_brown.mts", flags = "place_center_x, place_center_z", rotation = "0", @@ -2902,7 +2902,7 @@ local function register_decorations() fill_ratio = ratio_mushroom_mycelium_huge, biomes = { "MushroomIsland", "MushroomIslandShore" }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_brown.mts", flags = "place_center_x, place_center_z", rotation = "0", @@ -2914,7 +2914,7 @@ local function register_decorations() fill_ratio = ratio_mushroom_mycelium_giant, biomes = { "MushroomIsland", "MushroomIslandShore" }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_giant_brown.mts", flags = "place_center_x, place_center_z", rotation = "0", @@ -2928,7 +2928,7 @@ local function register_decorations() fill_ratio = ratio_mushroom_huge, biomes = { "RoofedForest" }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_red.mts", flags = "place_center_x, place_center_z", rotation = "0", @@ -2940,7 +2940,7 @@ local function register_decorations() fill_ratio = ratio_mushroom_giant, biomes = { "RoofedForest" }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_giant_red.mts", flags = "place_center_x, place_center_z", rotation = "0", @@ -2953,7 +2953,7 @@ local function register_decorations() fill_ratio = ratio_mushroom_mycelium_huge, biomes = { "MushroomIsland", "MushroomIslandShore" }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_red.mts", flags = "place_center_x, place_center_z", rotation = "0", @@ -2965,7 +2965,7 @@ local function register_decorations() fill_ratio = ratio_mushroom_mycelium_giant, biomes = { "MushroomIsland", "MushroomIslandShore" }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_giant_red.mts", flags = "place_center_x, place_center_z", rotation = "0", @@ -2986,7 +2986,7 @@ local function register_decorations() }, biomes = {"MegaTaiga", "MegaSpruceTaiga"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_boulder.mts", flags = "place_center_x, place_center_z", }) @@ -3006,7 +3006,7 @@ local function register_decorations() }, biomes = {"MegaTaiga", "MegaSpruceTaiga"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_boulder_small.mts", flags = "place_center_x, place_center_z", }) @@ -3025,7 +3025,7 @@ local function register_decorations() persist = 0.6 }, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_core:cactus", biomes = {"Desert", "Mesa","Mesa_sandlevel", @@ -3049,7 +3049,7 @@ local function register_decorations() persist = 0.7 }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_core:reeds", height = 1, height_max = 3, @@ -3070,7 +3070,7 @@ local function register_decorations() }, biomes = {"Swampland", "Swampland_shore"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_core:reeds", height = 1, height_max = 3, @@ -3104,7 +3104,7 @@ local function register_decorations() persist = 0.6, }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, biomes = { biomes[b] }, }) end @@ -3139,7 +3139,7 @@ local function register_decorations() persist = 0.66, }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, biomes = biomes[b], }) end @@ -3188,7 +3188,7 @@ local function register_decorations() persist = 0.62, }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, flags = "", biomes = b, }) @@ -3216,7 +3216,7 @@ local function register_decorations() }, biomes = {"Jungle"}, y_min = 3, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = jungle_bush_schematic, flags = "place_center_x, place_center_z", }) @@ -3234,7 +3234,7 @@ local function register_decorations() }, biomes = {"JungleM"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = jungle_bush_schematic, flags = "place_center_x, place_center_z", }) @@ -3252,7 +3252,7 @@ local function register_decorations() }, biomes = {"JungleEdge", "JungleEdgeM"}, y_min = 3, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = jungle_bush_schematic, flags = "place_center_x, place_center_z", }) @@ -3275,7 +3275,7 @@ local function register_decorations() }, biomes = {"MegaTaiga", "MegaSpruceTaiga", "Taiga"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = { size = {x = 3, y = 3, z = 1}, data = { @@ -3308,7 +3308,7 @@ local function register_decorations() }, biomes = {"ColdTaiga"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = { size = {x = 3, y = 3, z = 1}, data = { @@ -3341,7 +3341,7 @@ local function register_decorations() }, biomes = {"BirchForest", "BirchForestM",}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = { size = {x = 3, y = 3, z = 1}, data = { @@ -3367,7 +3367,7 @@ local function register_decorations() fill_ratio = 0.005, biomes = {"Jungle", "JungleM"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = { size = {x = 3, y = 3, z = 1}, data = { @@ -3400,7 +3400,7 @@ local function register_decorations() }, biomes = {"Forest"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = { size = {x = 3, y = 3, z = 1}, data = { @@ -3473,7 +3473,7 @@ local function register_decorations() persist = 0.6 }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_farming:melon", biomes = { "Jungle" }, }) @@ -3490,7 +3490,7 @@ local function register_decorations() persist = 0.6 }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_farming:melon", biomes = { "JungleM" }, }) @@ -3507,7 +3507,7 @@ local function register_decorations() persist = 0.6 }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_farming:melon", biomes = { "JungleEdge", "JungleEdgeM" }, }) @@ -3526,7 +3526,7 @@ local function register_decorations() persist = 0.6 }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_farming:melon", biomes = { "JungleEdgeM" }, }) @@ -3548,7 +3548,7 @@ local function register_decorations() persist = 0.666 }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, }) -- Grasses and ferns @@ -3623,7 +3623,7 @@ local function register_decorations() persist = 0.666 }, flags = "force_placement", - y_min = mcl_vars.mg_lava_overworld_max + 5, + y_min = mcl_mapgen.overworld.lava_max + 5, y_max = -20, }) @@ -3642,7 +3642,7 @@ local function register_decorations() }, biomes = {"IcePlains"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = { size = { x=1, y=2, z=1 }, data = { @@ -3665,7 +3665,7 @@ local function register_decorations() }, biomes = {"ExtremeHills+_snowtop"}, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, schematic = { size = { x=1, y=2, z=1 }, data = { @@ -3690,7 +3690,7 @@ local function register_decorations() persist = 0.6 }, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, biomes = {"Desert", "Mesa", "Mesa_sandlevel", "MesaPlateauF", "MesaPlateauF_sandlevel", "MesaPlateauF_grasstop","MesaBryce","Taiga", "MegaTaiga"}, decoration = "mcl_core:deadbush", height = 1, @@ -3708,7 +3708,7 @@ local function register_decorations() persist = 0.6 }, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, biomes = {"MesaPlateauFM_grasstop"}, decoration = "mcl_core:deadbush", height = 1, @@ -3726,7 +3726,7 @@ local function register_decorations() persist = 0.6 }, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, biomes = {"MesaPlateauFM","MesaPlateauFM_sandlevel"}, decoration = "mcl_core:deadbush", height = 1, @@ -3744,7 +3744,7 @@ local function register_decorations() persist = 0.6 }, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, biomes = {"MesaPlateauFM", "MesaPlateauFM_sandlevel", "MesaPlateauFM_grasstop"}, decoration = "mcl_core:deadbush", height = 1, @@ -3758,8 +3758,8 @@ local function register_decorations() fill_ratio = 0.009, biomes = {"MushroomIsland", "MushroomIslandShore"}, noise_threshold = 2.0, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_mushrooms:mushroom_red", }) minetest.register_decoration({ @@ -3768,8 +3768,8 @@ local function register_decorations() sidelen = 80, fill_ratio = 0.009, biomes = {"MushroomIsland", "MushroomIslandShore"}, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_mushrooms:mushroom_brown", }) @@ -3780,8 +3780,8 @@ local function register_decorations() sidelen = 80, fill_ratio = 0.003, biomes = {"Taiga", "MegaTaiga", "MegaSpruceTaiga"}, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_mushrooms:mushroom_red", }) minetest.register_decoration({ @@ -3790,8 +3790,8 @@ local function register_decorations() sidelen = 80, fill_ratio = 0.003, biomes = {"Taiga", "MegaTaiga", "MegaSpruceTaiga"}, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_mushrooms:mushroom_brown", }) @@ -3814,7 +3814,7 @@ local function register_decorations() persist = 0.66, }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = mushrooms[m], spawn_by = { "mcl_core:tree", "mcl_core:sprucetree", "mcl_core:darktree", "mcl_core:birchtree" }, num_spawn_by = 1, @@ -3834,7 +3834,7 @@ local function register_decorations() persist = 0.6, }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = mushrooms[m], biomes = { "Swampland"}, spawn_by = { "mcl_core:tree", "mcl_core:sprucetree", "mcl_core:darktree", "mcl_core:birchtree" }, @@ -3859,7 +3859,7 @@ local function register_decorations() persist = 0.6 }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, biomes = biomes, decoration = "mcl_flowers:"..name, }) @@ -3878,7 +3878,7 @@ local function register_decorations() persist = 0.6, }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, biomes = {"FlowerForest"}, decoration = "mcl_flowers:"..name, }) @@ -3925,8 +3925,8 @@ local function register_dimension_decorations() octaves = 3, persist = 0.6 }, - y_min = mcl_vars.mg_end_min, - y_max = mcl_vars.mg_end_max, + y_min = mcl_mapgen.end.min, + y_max = mcl_mapgen.end.max, decoration = "mcl_end:chorus_flower", height = 1, biomes = { "End" }, diff --git a/mods/MAPGEN/mcl_biomes/mod.conf b/mods/MAPGEN/mcl_biomes/mod.conf index 0c6095f3d..d389640a8 100644 --- a/mods/MAPGEN/mcl_biomes/mod.conf +++ b/mods/MAPGEN/mcl_biomes/mod.conf @@ -1,4 +1,4 @@ name = mcl_biomes author = maikerumine description = Adds the various biomes and biome-related things for non-v6 map generators. -depends = mcl_init, mcl_mapgen_core, mcl_core, mcl_worlds, mcl_farming, mcl_flowers, mcl_end, mcl_ocean +depends = mcl_mapgen, mcl_mapgen_core, mcl_core, mcl_worlds, mcl_farming, mcl_flowers, mcl_end, mcl_ocean diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index 40af11d37..b52a72ee6 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -32,11 +32,11 @@ local math_max = math.max local math_ceil = math.ceil --custom mcl_vars -local get_node = mcl_vars.get_node +local get_node = mcl_mapgen.get_far_node -local min_y = math_max(mcl_vars.mg_overworld_min, mcl_vars.mg_bedrock_overworld_max) + 1 -local max_y = mcl_vars.mg_overworld_max - 1 +local min_y = math_max(mcl_mapgen.overworld.min, mcl_vars.mg_bedrock_overworld_max) + 1 +local max_y = mcl_mapgen.overworld.max - 1 -- Calculate the number of dungeon spawn attempts -- In Minecraft, there 8 dungeon spawn attempts Minecraft chunk (16*256*16 = 65536 blocks). -- Minetest chunks don't have this size, so scale the number accordingly. diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index b14e1c2c7..563b62050 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -97,8 +97,8 @@ for s=1, #specialstones do clust_scarcity = 15*15*15, clust_num_ores = 33, clust_size = 5, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_params = { offset = 0, scale = 1, @@ -117,8 +117,8 @@ for s=1, #specialstones do clust_scarcity = 10*10*10, clust_num_ores = 58, clust_size = 7, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_params = { offset = 0, scale = 1, @@ -142,8 +142,8 @@ minetest.register_ore({ clust_scarcity = 15*15*15, clust_num_ores = 33, clust_size = 4, - y_min = mcl_vars.mg_overworld_min, - y_max = mcl_vars.mg_overworld_max, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, noise_params = { offset = 0, scale = 1, @@ -164,7 +164,7 @@ minetest.register_ore({ clust_scarcity = 14*14*14, clust_num_ores = 33, clust_size = 5, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(111), noise_params = { offset = 0, @@ -191,7 +191,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_scarcity = 525*3, clust_num_ores = 5, clust_size = 3, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(50), }) minetest.register_ore({ @@ -201,7 +201,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_scarcity = 510*3, clust_num_ores = 8, clust_size = 3, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(50), }) minetest.register_ore({ @@ -211,7 +211,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_scarcity = 500*3, clust_num_ores = 12, clust_size = 3, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(50), }) @@ -289,7 +289,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_scarcity = 830, clust_num_ores = 5, clust_size = 3, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(39), }) minetest.register_ore({ @@ -315,7 +315,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_scarcity = 4775, clust_num_ores = 5, clust_size = 3, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(30), }) minetest.register_ore({ @@ -325,7 +325,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_scarcity = 6560, clust_num_ores = 7, clust_size = 3, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(30), }) @@ -353,7 +353,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_scarcity = 10000, clust_num_ores = 4, clust_size = 3, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(12), }) minetest.register_ore({ @@ -363,7 +363,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_scarcity = 5000, clust_num_ores = 2, clust_size = 2, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(12), }) minetest.register_ore({ @@ -373,7 +373,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_scarcity = 10000, clust_num_ores = 8, clust_size = 3, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(12), }) @@ -411,7 +411,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_scarcity = 500, clust_num_ores = 4, clust_size = 3, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(13), }) minetest.register_ore({ @@ -421,7 +421,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_scarcity = 800, clust_num_ores = 7, clust_size = 4, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(13), }) @@ -462,7 +462,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_scarcity = 14340, clust_num_ores = 1, clust_size = 1, - y_min = mcl_vars.mg_overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = mcl_worlds.layer_to_y(29), }) -- Rare spawn @@ -678,7 +678,7 @@ local function register_mgv6_decorations() persist = 0.6 }, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_core:cactus", height = 1, height_max = 3, @@ -698,7 +698,7 @@ local function register_mgv6_decorations() persist = 0.7 }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_core:reeds", height = 1, height_max = 3, @@ -728,7 +728,7 @@ local function register_mgv6_decorations() persist = 0.0, }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, }) -- Large ferns @@ -757,7 +757,7 @@ local function register_mgv6_decorations() persist = 0.66, }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, }) -- Large flowers @@ -1006,7 +1006,7 @@ local function register_mgv6_decorations() persist = 0.666 }, flags = "force_placement", - y_min = mcl_vars.mg_lava_overworld_max + 5, + y_min = mcl_mapgen.overworld.lava_max + 5, y_max = -20, }) @@ -1038,7 +1038,7 @@ local function register_mgv6_decorations() persist = 0.6 }, y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = mushrooms[m], spawn_by = { "mcl_core:tree", "mcl_core:sprucetree", "mcl_core:darktree", "mcl_core:birchtree", }, num_spawn_by = 1, @@ -1059,7 +1059,7 @@ local function register_mgv6_decorations() persist = 0.6 }, y_min = 4, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_core:deadbush", }) @@ -1068,7 +1068,7 @@ local function register_mgv6_decorations() offset = 0 end if y_max == nil then - y_max = mcl_vars.mg_overworld_max + y_max = mcl_mapgen.overworld.max end minetest.register_decoration({ deco_type = "simple", @@ -1111,7 +1111,7 @@ local function register_mgv6_decorations() sidelen = 16, fill_ratio = 11.0, -- complete coverage y_min = 1, - y_max = mcl_vars.mg_overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_core:snow", }) @@ -1719,7 +1719,7 @@ local generate_underground_mushrooms = function(minp, maxp, seed) local pr_shroom = PseudoRandom(seed-24359) -- Generate rare underground mushrooms -- TODO: Make them appear in groups, use Perlin noise - local min, max = mcl_vars.mg_lava_overworld_max + 4, 0 + local min, max = mcl_mapgen.overworld.lava_max + 4, 0 if minp.y > max or maxp.y < min then return end @@ -1752,7 +1752,7 @@ end local generate_nether_decorations = function(minp, maxp, seed) local pr_nether = PseudoRandom(seed+667) - if minp.y > mcl_vars.mg_nether_max or maxp.y < mcl_vars.mg_nether_min then + if minp.y > mcl_mapgen.nether.max or maxp.y < mcl_mapgen.nether.min then return end @@ -1899,23 +1899,23 @@ local function basic(c) local pr = PseudoRandom(blockseed) -- The Void below the Nether: - lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.EDGE_MIN , mcl_vars.mg_nether_min -1, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.EDGE_MIN , mcl_mapgen.nether.min -1, minp, maxp, lvm_used, pr) - -- [[ THE NETHER: mcl_vars.mg_nether_min mcl_vars.mg_nether_max ]] + -- [[ THE NETHER: mcl_mapgen.nether.min mcl_mapgen.nether.max ]] -- The Air on the Nether roof, https://git.minetest.land/MineClone2/MineClone2/issues/1186 - lvm_used = set_layers(data, area, c_air , nil, mcl_vars.mg_nether_max +1, mcl_vars.mg_nether_max + 128 , minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_air , nil, mcl_mapgen.nether.max +1, mcl_mapgen.nether.max + 128 , minp, maxp, lvm_used, pr) -- The Void above the Nether below the End: - lvm_used = set_layers(data, area, c_void , nil, mcl_vars.mg_nether_max + 128 +1, mcl_vars.mg_end_min -1, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.nether.max + 128 +1, mcl_mapgen.end.min -1, minp, maxp, lvm_used, pr) - -- [[ THE END: mcl_vars.mg_end_min mcl_vars.mg_end_max ]] + -- [[ THE END: mcl_mapgen.end.min mcl_mapgen.end.max ]] -- The Void above the End below the Realm barrier: - lvm_used = set_layers(data, area, c_void , nil, mcl_vars.mg_end_max +1, mcl_vars.mg_realm_barrier_overworld_end_min-1, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.end.max +1, mcl_vars.mg_realm_barrier_overworld_end_min-1, minp, maxp, lvm_used, pr) -- Realm barrier between the Overworld void and the End lvm_used = set_layers(data, area, c_realm_barrier, nil, mcl_vars.mg_realm_barrier_overworld_end_min , mcl_vars.mg_realm_barrier_overworld_end_max , minp, maxp, lvm_used, pr) -- The Void above Realm barrier below the Overworld: - lvm_used = set_layers(data, area, c_void , nil, mcl_vars.mg_realm_barrier_overworld_end_max+1, mcl_vars.mg_overworld_min -1, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_void , nil, mcl_vars.mg_realm_barrier_overworld_end_max+1, mcl_mapgen.overworld.min -1, minp, maxp, lvm_used, pr) if mg_name ~= "singlenode" then @@ -1931,8 +1931,8 @@ local function basic(c) -- Big lava seas by replacing air below a certain height if mcl_vars.mg_lava then - lvm_used = set_layers(data, area, c_lava, c_air, mcl_vars.mg_overworld_min, mcl_vars.mg_lava_overworld_max, minp, maxp, lvm_used, pr) - lvm_used = set_layers(data, area, c_nether_lava, c_air, mcl_vars.mg_nether_min, mcl_vars.mg_lava_nether_max, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_lava, c_air, mcl_mapgen.overworld.min, mcl_mapgen.overworld.lava_max, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_nether_lava, c_air, mcl_mapgen.nether.min, mcl_vars.mg_lava_nether_max, minp, maxp, lvm_used, pr) end -- Clay, vines, cocoas @@ -1948,7 +1948,7 @@ local function basic(c) -- Snow and sand fixes. This code implements snow consistency -- and fixes floating sand and cut plants. -- A snowy grass block must be below a top snow or snow block at all times. - if minp.y <= mcl_vars.mg_overworld_max and maxp.y >= mcl_vars.mg_overworld_min then + if minp.y <= mcl_mapgen.overworld.max and maxp.y >= mcl_mapgen.overworld.min then -- v6 mapgen: if mg_name == "v6" then @@ -2014,7 +2014,7 @@ local function basic(c) -- Nether block fixes: -- * Replace water with Nether lava. -- * Replace stone, sand dirt in v6 so the Nether works in v6. - elseif emin.y <= mcl_vars.mg_nether_max and emax.y >= mcl_vars.mg_nether_min then + elseif emin.y <= mcl_mapgen.nether.max and emax.y >= mcl_mapgen.nether.min then if mg_name == "v6" then local nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"}) for n=1, #nodes do @@ -2041,7 +2041,7 @@ local function basic(c) -- * Replace water with end stone or air (depending on height). -- * Remove stone, sand, dirt in v6 so our End map generator works in v6. -- * Generate spawn platform (End portal destination) - elseif minp.y <= mcl_vars.mg_end_max and maxp.y >= mcl_vars.mg_end_min then + elseif minp.y <= mcl_mapgen.end.max and maxp.y >= mcl_mapgen.end.min then local nodes if mg_name == "v6" then nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"}) @@ -2083,11 +2083,11 @@ local function basic(c) -- Final hackery: Set sun light level in the End. -- -26912 is at a mapchunk border. local shadow = true - if minp.y >= -26912 and maxp.y <= mcl_vars.mg_end_max then + if minp.y >= -26912 and maxp.y <= mcl_mapgen.end.max then vm:set_lighting({day=15, night=15}) lvm_used = true end - if minp.y >= mcl_vars.mg_end_min and maxp.y <= -26911 then + if minp.y >= mcl_mapgen.end.min and maxp.y <= -26911 then shadow = false lvm_used = true end diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index e3f6b4829..8304061af 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -110,14 +110,14 @@ mcl_structures.generate_igloo = function(pos, rotation, pr) if r == 1 then -- Select basement depth local dim = mcl_worlds.pos_to_dimension(pos) - --local buffer = pos.y - (mcl_vars.mg_lava_overworld_max + 10) + --local buffer = pos.y - (mcl_mapgen.overworld.lava_max + 10) local buffer if dim == "nether" then buffer = pos.y - (mcl_vars.mg_lava_nether_max + 10) elseif dim == "end" then buffer = pos.y - (mcl_vars.mg_end_min + 1) elseif dim == "overworld" then - buffer = pos.y - (mcl_vars.mg_lava_overworld_max + 10) + buffer = pos.y - (mcl_mapgen.overworld.lava_max + 10) else return success end @@ -277,7 +277,7 @@ local function hut_placement_callback(p1, p2, size, orientation, pr) if not p1 or not p2 then return end local legs = minetest.find_nodes_in_area(p1, p2, "mcl_core:tree") for i = 1, #legs do - while minetest.get_item_group(mcl_vars.get_node({x=legs[i].x, y=legs[i].y-1, z=legs[i].z}, true, 333333).name, "water") ~= 0 do + while minetest.get_item_group(mcl_mapgen.get_far_node({x=legs[i].x, y=legs[i].y-1, z=legs[i].z}, true, 333333).name, "water") ~= 0 do legs[i].y = legs[i].y - 1 minetest.swap_node(legs[i], {name = "mcl_core:tree", param2 = 2}) end diff --git a/mods/MAPGEN/mcl_villages/buildings.lua b/mods/MAPGEN/mcl_villages/buildings.lua index 9d8e7580f..b9c4f8e85 100644 --- a/mods/MAPGEN/mcl_villages/buildings.lua +++ b/mods/MAPGEN/mcl_villages/buildings.lua @@ -88,7 +88,7 @@ function settlements.create_site_plan(maxp, minp, pr) -- find center_surface of chunk local center_surface , surface_material = settlements.find_surface(center, true) local chunks = {} - chunks[mcl_vars.get_chunk_number(center)] = true + chunks[mcl_mapgen.get_chunk_number(center)] = true -- go build settlement around center if not center_surface then return false end @@ -124,7 +124,7 @@ function settlements.create_site_plan(maxp, minp, pr) ptx = settlements.round(ptx, 0) ptz = settlements.round(ptz, 0) local pos1 = { x=ptx, y=center_surface.y+50, z=ptz} - local chunk_number = mcl_vars.get_chunk_number(pos1) + local chunk_number = mcl_mapgen.get_chunk_number(pos1) local pos_surface, surface_material if chunks[chunk_number] then pos_surface, surface_material = settlements.find_surface(pos1) diff --git a/mods/MAPGEN/mcl_villages/utils.lua b/mods/MAPGEN/mcl_villages/utils.lua index 993de11c4..87473cc80 100644 --- a/mods/MAPGEN/mcl_villages/utils.lua +++ b/mods/MAPGEN/mcl_villages/utils.lua @@ -1,4 +1,4 @@ -local get_node = mcl_vars.get_node +local get_node = mcl_mapgen.get_far_node ------------------------------------------------------------------------------- -- function to copy tables diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index f5a8b4908..ad8c6d99f 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -94,7 +94,7 @@ end -- Max. and min. heights between rail corridors are generated local height_min if mcl_vars.mg_lava then - height_min = mcl_vars.mg_lava_overworld_max + 2 + height_min = mcl_mapgen.overworld.lava_max + 2 else height_min = mcl_vars.mg_bedrock_overworld_max + 2 end From 3c5bf8c9b21f36b95e01b659ca9634be2832e5b1 Mon Sep 17 00:00:00 2001 From: kay27 Date: Thu, 29 Apr 2021 00:53:48 +0400 Subject: [PATCH 08/61] [mapgen] Use more readable constants, increase max_block_generate_distance --- minetest.conf | 2 + mods/CORE/mcl_mapgen/init.lua | 87 +++++++++++++---------- mods/CORE/mcl_worlds/init.lua | 18 ++--- mods/CORE/mcl_worlds/mod.conf | 3 +- mods/ENTITIES/mobs_mc_gameconfig/init.lua | 4 +- mods/ITEMS/mcl_portals/portal_end.lua | 8 +-- mods/ITEMS/mcl_portals/portal_nether.lua | 2 +- mods/MAPGEN/mcl_biomes/init.lua | 58 +++++++-------- mods/MAPGEN/mcl_dungeons/init.lua | 8 +-- mods/MAPGEN/mcl_mapgen_core/init.lua | 12 ++-- mods/MAPGEN/mcl_strongholds/init.lua | 9 ++- mods/MAPGEN/tsm_railcorridors/init.lua | 7 +- 12 files changed, 113 insertions(+), 105 deletions(-) diff --git a/minetest.conf b/minetest.conf index 223587f4d..1745bffb3 100644 --- a/minetest.conf +++ b/minetest.conf @@ -27,6 +27,8 @@ movement_gravity = 10.4 # Mapgen stuff +max_block_generate_distance = 13 + # altitude_chill and altitude_dry doesn't go well together with MCL2 biomes # which already include "snowed" variants as you go higher. # humid_rivers would cause the MushroomIsland biome to appear frequently around rivers. diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 74461a5fa..6d3793a46 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -1,10 +1,7 @@ mcl_mapgen = {} -mcl_mapgen.overworld = {} -mcl_mapgen.nether = {} -mcl_mapgen.end = {} local minetest_log, math_floor = minetest.log, math.floor -local minetest_get_node = minetest.get_node +local minetest_get_node, minetest_get_voxel_manip = minetest.get_node, minetest.get_voxel_manip -- Calculate mapgen_edge_min/mapgen_edge_max mcl_mapgen.CS = math.max(1, tonumber(minetest.get_mapgen_setting("chunksize")) or 5) @@ -88,14 +85,14 @@ minetest.register_on_generated(function(minp, maxp, blockseed) vm_context.data = data area = VoxelArea:new({MinEdge=emin, MaxEdge=emax}) vm_context.area = area - for _, v in pairs(lvm_chunk_queue) do - vm_context = v.f(vm_context) - end end + local chunk_is_ready = true + if block > 0 then local x0, y0, z0 = minp.x, minp.y, minp.z local bx0, by0, bz0 = math_floor(x0/BS), math_floor(y0/BS), math_floor(z0/BS) + local bx1, by1, bz1 = bx0 + LAST_BLOCK, by0 + LAST_BLOCK, bz0 + LAST_BLOCK -- only for entire chunk check local x1, y1, z1, x2, y2, z2 = emin.x, emin.y, emin.z, emax.x, emax.y, emax.z local x, y, z = x1, y1, z1 -- iterate 7x7x7 mapchunk, {x,y,z} - first node pos. of mapblock local bx, by, bz -- block coords (in blocs) @@ -133,6 +130,7 @@ minetest.register_on_generated(function(minp, maxp, blockseed) end else blocks[bx][by][bz] = current_mapgen_block_writes + chunk_is_ready = chunk_is_ready and (bx < bx0 or bx > bx1 or by < by0 or by > by1 or bz < bz0 or bz > bz1) end z = z + BS end @@ -147,6 +145,11 @@ minetest.register_on_generated(function(minp, maxp, blockseed) end if lvm > 0 then + if chunk_is_ready then + for _, v in pairs(lvm_chunk_queue) do + vm_context = v.f(vm_context) + end + end if vm_context.write then vm:set_data(data) end @@ -158,8 +161,10 @@ minetest.register_on_generated(function(minp, maxp, blockseed) vm:update_liquids() end - for _, v in pairs(node_chunk_queue) do - v.f(minp, maxp, blockseed) + if chunk_is_ready then + for _, v in pairs(node_chunk_queue) do + v.f(minp, maxp, blockseed) + end end for i, b in pairs(current_blocks) do @@ -218,13 +223,16 @@ end -- Mapgen variables +local overworld, end_, nether = {}, {}, {} +mcl_mapgen.seed = minetest.get_mapgen_setting("seed") mcl_mapgen.name = minetest.get_mapgen_setting("mg_name") +mcl_mapgen.v6 = mcl_mapgen.name == "v6" mcl_mapgen.superflat = mcl_mapgen.name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" mcl_mapgen.singlenode = mcl_mapgen.name == "singlenode" mcl_mapgen.normal = not mcl_mapgen.superflat and not mcl_mapgen.singlenode local superflat, singlenode, normal = mcl_mapgen.superflat, mcl_mapgen.singlenode, mcl_mapgen.normal -minetest_log("action", "[mcl_mapgen] Mapgen mode: " .. normal and "normal" or (superflat and "superflat" or "singlenode")) +minetest_log("action", "[mcl_mapgen] Mapgen mode: " .. (normal and "normal" or (superflat and "superflat" or "singlenode"))) mcl_mapgen.minecraft_height_limit = 256 @@ -241,55 +249,58 @@ mcl_mapgen.bedrock_is_rough = normal ]] -- Overworld -mcl_mapgen.overworld.min = -62 +overworld.min = -62 if superflat then mcl_mapgen.ground = tonumber(minetest.get_mapgen_setting("mgflat_ground_level")) or 8 - mcl_mapgen.overworld.min = ground - 3 + overworld.min = ground - 3 end -- if singlenode then mcl_mapgen.overworld.min = -66 end -- DONT KNOW WHY -mcl_mapgen.overworld.max = mcl_mapgen.EDGE_MAX +overworld.max = mcl_mapgen.EDGE_MAX -mcl_mapgen.overworld.bedrock_min = mcl_mapgen.overworld.min -mcl_mapgen.overworld.bedrock_max = mcl_mapgen.overworld.bedrock_min + (mcl_mapgen.bedrock_is_rough and 4 or 0) +overworld.bedrock_min = overworld.min +overworld.bedrock_max = overworld.bedrock_min + (mcl_mapgen.bedrock_is_rough and 4 or 0) mcl_mapgen.lava = normal -mcl_mapgen.lava_overworld_max = mcl_mapgen.overworld.min + (normal and 10 or 0) +overworld.lava_max = overworld.min + (normal and 10 or 0) -- The Nether (around Y = -29000) -mcl_mapgen.nether.min = -29067 -- Carefully chosen to be at a mapchunk border -mcl_mapgen.nether.max = mcl_mapgen.nether.min + 128 -mcl_mapgen.nether.bedrock_bottom_min = mcl_mapgen.nether.min -mcl_mapgen.nether.bedrock_top_max = mcl_mapgen.nether.max +nether.min = -29067 -- Carefully chosen to be at a mapchunk border +nether.max = nether.min + 128 +nether.bedrock_bottom_min = nether.min +nether.bedrock_top_max = nether.max if not superflat then - mcl_mapgen.nether.bedrock_bottom_max = mcl_vars.mg_bedrock_nether_bottom_min + 4 - mcl_mapgen.nether.bedrock_top_min = mcl_vars.mg_bedrock_nether_top_max - 4 - mcl_mapgen.nether.lava_max = mcl_mapgen.nether.min + 31 + nether.bedrock_bottom_max = nether.bedrock_bottom_min + 4 + nether.bedrock_top_min = nether.bedrock_top_max - 4 + nether.lava_max = nether.min + 31 else -- Thin bedrock in classic superflat mapgen - mcl_mapgen.nether.bedrock_bottom_max = mcl_vars.mg_bedrock_nether_bottom_min - mcl_mapgen.nether.bedrock_top_min = mcl_vars.mg_bedrock_nether_top_max - mcl_mapgen.nether.lava_max = mcl_mapgen.nether.min + 2 + nether.bedrock_bottom_max = nether.bedrock_bottom_min + nether.bedrock_top_min = nether.bedrock_top_max + nether.lava_max = nether.min + 2 end if mcl_mapgen.name == "flat" then if superflat then - mcl_mapgen.nether.flat_nether_floor = mcl_mapgen.nether.bedrock_nether_bottom_max + 4 - mcl_mapgen.nether.flat_nether_ceiling = mcl_mapgen.nether.bedrock_nether_bottom_max + 52 + nether.flat_nether_floor = nether.bedrock_bottom_max + 4 + nether.flat_nether_ceiling = nether.bedrock_bottom_max + 52 else - mcl_mapgen.nether.flat_nether_floor = mcl_mapgen.nether.lava_nether_max + 4 - mcl_mapgen.nether.flat_nether_ceiling = mcl_mapgen.nether.lava_nether_max + 52 + nether.flat_nether_floor = nether.lava_max + 4 + nether.flat_nether_ceiling = nether.lava_max + 52 end end -- The End (surface at ca. Y = -27000) -mcl_mapgen.end.min = -27073 -- Carefully chosen to be at a mapchunk border -mcl_mapgen.end.max_official = mcl_mapgen.end.min + mcl_mapgen.minecraft_height_limit -mcl_mapgen.end.max = mcl_mapgen.overworld.min - 2000 -mcl_vars.mg_end_platform_pos = { x = 100, y = mcl_mapgen.end.min + 74, z = 0 } +end_.min = -27073 -- Carefully chosen to be at a mapchunk border +end_.max = overworld.min - 2000 +end_.platform_pos = { x = 100, y = end_.min + 74, z = 0 } -- Realm barrier used to safely separate the End from the void below the Overworld -mcl_vars.mg_realm_barrier_overworld_end_max = mcl_mapgen.end.max -mcl_vars.mg_realm_barrier_overworld_end_min = mcl_mapgen.end.max - 11 +mcl_mapgen.realm_barrier_overworld_end_max = end_.max +mcl_mapgen.realm_barrier_overworld_end_min = end_.max - 11 --- Use MineClone 2-style dungeons -mcl_vars.mg_dungeons = true +-- Use MineClone 2-style dungeons for normal mapgen +mcl_mapgen.dungeons = normal + +mcl_mapgen.overworld = overworld +mcl_mapgen.end_ = end_ +mcl_mapgen.nether = nether diff --git a/mods/CORE/mcl_worlds/init.lua b/mods/CORE/mcl_worlds/init.lua index a9d9ea050..cc5ba756a 100644 --- a/mods/CORE/mcl_worlds/init.lua +++ b/mods/CORE/mcl_worlds/init.lua @@ -3,8 +3,8 @@ mcl_worlds = {} -- For a given position, returns a 2-tuple: -- 1st return value: true if pos is in void -- 2nd return value: true if it is in the deadly part of the void -local min1, min2, min3 = mcl_mapgen.overworld.min, mcl_mapgen.end.min, mcl_mapgen.nether.min -local max1, max2, max3 = mcl_mapgen.overworld.max, mcl_mapgen.end.max, mcl_mapgen.nether.max+128 +local min1, min2, min3 = mcl_mapgen.overworld.min, mcl_mapgen.end_.min, mcl_mapgen.nether.min +local max1, max2, max3 = mcl_mapgen.overworld.max, mcl_mapgen.end_.max, mcl_mapgen.nether.max+128 function mcl_worlds.is_in_void(pos) local y = pos.y local void = not ((y < max1 and y > min1) or (y < max2 and y > min2) or (y < max3 and y > min3)) @@ -13,7 +13,7 @@ function mcl_worlds.is_in_void(pos) local deadly_tolerance = 64 -- the player must be this many nodes “deep” into the void to be damaged if void then -- Overworld → Void → End → Void → Nether → Void - if y < mcl_vars.min1 and y > max2 then + if y < min1 and y > max2 then void_deadly = y < min1 - deadly_tolerance elseif y < min2 and y > max3 then -- The void between End and Nether. Like usual, but here, the void @@ -56,24 +56,24 @@ end -- mc_dimension is one of "overworld", "nether", "end" (default: "overworld"). function mcl_worlds.layer_to_y(layer, mc_dimension) if mc_dimension == "overworld" or mc_dimension == nil then - return layer + mcl_vars.mg_overworld_min + return layer + min1 elseif mc_dimension == "nether" then - return layer + mcl_vars.mg_nether_min + return layer + min3 elseif mc_dimension == "end" then - return layer + mcl_vars.mg_end_min + return layer + min2 end end -- Takes a position and returns true if this position can have weather function mcl_worlds.has_weather(pos) -- Weather in the Overworld and the high part of the void below - return pos.y <= mcl_vars.mg_overworld_max and pos.y >= mcl_vars.mg_overworld_min - 64 + return pos.y <= max1 and pos.y >= min1 - 64 end -- Takes a position and returns true if this position can have Nether dust function mcl_worlds.has_dust(pos) -- Weather in the Overworld and the high part of the void below - return pos.y <= mcl_vars.mg_nether_max + 138 and pos.y >= mcl_vars.mg_nether_min - 10 + return pos.y <= max3 + 138 and pos.y >= min3 - 10 end -- Takes a position (pos) and returns true if compasses are working here @@ -83,7 +83,7 @@ function mcl_worlds.compass_works(pos) if dim == "nether" or dim == "end" then return false elseif dim == "void" then - return pos.y <= mcl_vars.mg_overworld_max and pos.y >= mcl_vars.mg_overworld_min - 64 + return pos.y <= max1 and pos.y >= min1 - 64 else return true end diff --git a/mods/CORE/mcl_worlds/mod.conf b/mods/CORE/mcl_worlds/mod.conf index 4b979b4fe..8a44f4e01 100644 --- a/mods/CORE/mcl_worlds/mod.conf +++ b/mods/CORE/mcl_worlds/mod.conf @@ -1,5 +1,4 @@ name = mcl_worlds author = Wuzzy description = Utility functions for worlds and the “dimensions”. -depends = mcl_init - +depends = mcl_mapgen diff --git a/mods/ENTITIES/mobs_mc_gameconfig/init.lua b/mods/ENTITIES/mobs_mc_gameconfig/init.lua index dd310c1b3..703b9536c 100644 --- a/mods/ENTITIES/mobs_mc_gameconfig/init.lua +++ b/mods/ENTITIES/mobs_mc_gameconfig/init.lua @@ -241,7 +241,7 @@ mobs_mc.override.spawn_height = { nether_max = mcl_mapgen.nether.max, -- End boundaries (inclusive) - end_min = mcl_mapgen.end.min, - end_max = mcl_mapgen.end.max, + end_min = mcl_mapgen.end_.min, + end_max = mcl_mapgen.end_.max, } diff --git a/mods/ITEMS/mcl_portals/portal_end.lua b/mods/ITEMS/mcl_portals/portal_end.lua index 192f5001c..1b36d093d 100644 --- a/mods/ITEMS/mcl_portals/portal_end.lua +++ b/mods/ITEMS/mcl_portals/portal_end.lua @@ -1,10 +1,10 @@ local S = minetest.get_translator("mcl_portals") -- Parameters -local SPAWN_MIN = mcl_vars.mg_end_min+70 -local SPAWN_MAX = mcl_vars.mg_end_min+98 +local SPAWN_MIN = mcl_mapgen.end_.min+70 +local SPAWN_MAX = mcl_mapgen.end_.min+98 -local mg_name = minetest.get_mapgen_setting("mg_name") +local mg_name = mcl_mapgen.name local destroy_portal = function(pos) local neighbors = { @@ -178,7 +178,7 @@ function mcl_portals.end_teleport(obj, pos) -- Teleport to the End at a fixed position and generate a -- 5×5 obsidian platform below. - local platform_pos = mcl_vars.mg_end_platform_pos + local platform_pos = mcl_mapgen.end_.platform_pos -- force emerge of target1 area minetest.get_voxel_manip():read_from_map(platform_pos, platform_pos) if not minetest.get_node_or_nil(platform_pos) then diff --git a/mods/ITEMS/mcl_portals/portal_nether.lua b/mods/ITEMS/mcl_portals/portal_nether.lua index ee38264da..a06b2f8c7 100644 --- a/mods/ITEMS/mcl_portals/portal_nether.lua +++ b/mods/ITEMS/mcl_portals/portal_nether.lua @@ -28,7 +28,7 @@ local DISTANCE_MAX = 128 local PORTAL = "mcl_portals:portal" local OBSIDIAN = "mcl_core:obsidian" local O_Y_MIN, O_Y_MAX = max(mcl_mapgen.overworld.min, -31), min(mcl_mapgen.overworld.max, 2048) -local N_Y_MIN, N_Y_MAX = mcl_vars.mg_bedrock_nether_bottom_min, mcl_vars.mg_bedrock_nether_top_min - H_MIN +local N_Y_MIN, N_Y_MAX = mcl_mapgen.nether.bedrock_bottom_min, mcl_mapgen.nether.bedrock_top_min - H_MIN -- Alpha and particles local node_particles_allowed = minetest.settings:get("mcl_node_particles") or "none" diff --git a/mods/MAPGEN/mcl_biomes/init.lua b/mods/MAPGEN/mcl_biomes/init.lua index 3cfeea048..a35183c15 100644 --- a/mods/MAPGEN/mcl_biomes/init.lua +++ b/mods/MAPGEN/mcl_biomes/init.lua @@ -1,8 +1,7 @@ -local mg_name = minetest.get_mapgen_setting("mg_name") -local mg_seed = minetest.get_mapgen_setting("seed") +local mg_seed = mcl_mapgen.seed -- Some mapgen settings -local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" +local superflat = mcl_mapgen.superflat local generate_fallen_logs = minetest.settings:get_bool("mcl_generate_fallen_logs", false) @@ -1505,8 +1504,8 @@ local function register_dimension_biomes() node_cave_liquid = "air", -- FIXME: For some reason the End stops generating early if this constant is not added. -- Figure out why. - y_min = mcl_mapgen.end.min, - y_max = mcl_mapgen.end.max + 80, + y_min = mcl_mapgen.end_.min, + y_max = mcl_mapgen.end_.max + 80, heat_point = 50, humidity_point = 50, _mcl_biome_type = "medium", @@ -1539,7 +1538,7 @@ local function register_biome_ores() -- Rarely replace stone with stone monster eggs. -- In v6 this can happen anywhere, in other mapgens only in Extreme Hills. local monster_egg_scarcity - if mg_name == "v6" then + if mcl_mapgen.v6 then monster_egg_scarcity = 28 * 28 * 28 else monster_egg_scarcity = 26 * 26 * 26 @@ -1561,7 +1560,7 @@ local function register_biome_ores() }) -- Bonus gold spawn in Mesa - if mg_name ~= "v6" then + if not mcl_mapgen.v6 then minetest.register_ore({ ore_type = "scatter", ore = "mcl_core:stone_with_gold", @@ -2009,7 +2008,7 @@ local function register_dimension_ores() wherein = {"mcl_nether:netherrack", "mcl_core:stone"}, clust_scarcity = 26 * 26 * 26, clust_size = 5, - y_min = mcl_vars.mg_lava_nether_max + 10, + y_min = mcl_mapgen.nether.lava_max + 10, y_max = mcl_mapgen.nether.max, noise_threshold = 0.0, noise_params = { @@ -2077,7 +2076,7 @@ local function register_dimension_ores() clust_num_ores = 1, clust_size = 1, y_min = mcl_mapgen.nether.min, - y_max = mcl_vars.mg_lava_nether_max + 1, + y_max = mcl_mapgen.nether.lava_max + 1, }) minetest.register_ore({ @@ -2087,8 +2086,8 @@ local function register_dimension_ores() clust_scarcity = 1000, clust_num_ores = 1, clust_size = 1, - y_min = mcl_vars.mg_lava_nether_max + 2, - y_max = mcl_vars.mg_lava_nether_max + 12, + y_min = mcl_mapgen.nether.lava_max + 2, + y_max = mcl_mapgen.nether.lava_max + 12, }) minetest.register_ore({ @@ -2098,8 +2097,8 @@ local function register_dimension_ores() clust_scarcity = 2000, clust_num_ores = 1, clust_size = 1, - y_min = mcl_vars.mg_lava_nether_max + 13, - y_max = mcl_vars.mg_lava_nether_max + 48, + y_min = mcl_mapgen.nether.lava_max + 13, + y_max = mcl_mapgen.nether.lava_max + 48, }) minetest.register_ore({ ore_type = "scatter", @@ -2108,7 +2107,7 @@ local function register_dimension_ores() clust_scarcity = 3500, clust_num_ores = 1, clust_size = 1, - y_min = mcl_vars.mg_lava_nether_max + 49, + y_min = mcl_mapgen.nether.lava_max + 49, y_max = mcl_mapgen.nether.max, }) @@ -2119,7 +2118,7 @@ local function register_dimension_ores() -- FIXME: Broken lighting in v6 mapgen local end_wherein - if mg_name == "v6" then + if mcl_mapgen.v6 then end_wherein = {"air", "mcl_core:stone"} else end_wherein = {"air"} @@ -2129,11 +2128,11 @@ local function register_dimension_ores() ore_type = "stratum", ore = "mcl_end:end_stone", wherein = end_wherein, - y_min = mcl_mapgen.end.min+64, - y_max = mcl_mapgen.end.min+80, + y_min = mcl_mapgen.end_.min+64, + y_max = mcl_mapgen.end_.min+80, noise_params = { - offset = mcl_mapgen.end.min+70, + offset = mcl_mapgen.end_.min+70, scale = -1, spread = {x=126, y=126, z=126}, seed = mg_seed+9999, @@ -2156,11 +2155,11 @@ local function register_dimension_ores() ore_type = "stratum", ore = "mcl_end:end_stone", wherein = end_wherein, - y_min = mcl_mapgen.end.min+64, - y_max = mcl_mapgen.end.min+80, + y_min = mcl_mapgen.end_.min+64, + y_max = mcl_mapgen.end_.min+80, noise_params = { - offset = mcl_mapgen.end.min+72, + offset = mcl_mapgen.end_.min+72, scale = -3, spread = {x=84, y=84, z=84}, seed = mg_seed+999, @@ -2182,11 +2181,11 @@ local function register_dimension_ores() ore_type = "stratum", ore = "mcl_end:end_stone", wherein = end_wherein, - y_min = mcl_mapgen.end.min+64, - y_max = mcl_mapgen.end.min+80, + y_min = mcl_mapgen.end_.min+64, + y_max = mcl_mapgen.end_.min+80, noise_params = { - offset = mcl_mapgen.end.min+70, + offset = mcl_mapgen.end_.min+70, scale = -2, spread = {x=84, y=84, z=84}, seed = mg_seed+99, @@ -3925,8 +3924,8 @@ local function register_dimension_decorations() octaves = 3, persist = 0.6 }, - y_min = mcl_mapgen.end.min, - y_max = mcl_mapgen.end.max, + y_min = mcl_mapgen.end_.min, + y_max = mcl_mapgen.end_.max, decoration = "mcl_end:chorus_flower", height = 1, biomes = { "End" }, @@ -3943,14 +3942,15 @@ end -- -- Detect mapgen to select functions -- -if mg_name ~= "singlenode" then + +if not mcl_mapgen.singlenode then if not superflat then - if mg_name ~= "v6" then + if not mcl_mapgen.v6 then register_biomes() register_biomelike_ores() end register_biome_ores() - if mg_name ~= "v6" then + if not mcl_mapgen.v6 then register_decorations() end else diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index b52a72ee6..d2458939e 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -2,10 +2,8 @@ mcl_dungeons = {} -local mg_name = minetest.get_mapgen_setting("mg_name") - -- Are dungeons disabled? -if mcl_vars.mg_dungeons == false or mg_name == "singlenode" then +if mcl_mapgen.dungeons == false or mcl_mapgen.singlenode == true then return end @@ -35,7 +33,7 @@ local math_ceil = math.ceil local get_node = mcl_mapgen.get_far_node -local min_y = math_max(mcl_mapgen.overworld.min, mcl_vars.mg_bedrock_overworld_max) + 1 +local min_y = math_max(mcl_mapgen.overworld.min, mcl_mapgen.overworld.bedrock_max) + 1 local max_y = mcl_mapgen.overworld.max - 1 -- Calculate the number of dungeon spawn attempts -- In Minecraft, there 8 dungeon spawn attempts Minecraft chunk (16*256*16 = 65536 blocks). @@ -358,7 +356,7 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) } -- Bonus loot for v6 mapgen: Otherwise unobtainable saplings. - if mg_name == "v6" then + if mcl_mapgen.v6 then table_insert(loottable, { stacks_min = 1, stacks_max = 3, diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 563b62050..da92c4e49 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1906,12 +1906,12 @@ local function basic(c) -- The Air on the Nether roof, https://git.minetest.land/MineClone2/MineClone2/issues/1186 lvm_used = set_layers(data, area, c_air , nil, mcl_mapgen.nether.max +1, mcl_mapgen.nether.max + 128 , minp, maxp, lvm_used, pr) -- The Void above the Nether below the End: - lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.nether.max + 128 +1, mcl_mapgen.end.min -1, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.nether.max + 128 +1, mcl_mapgen.end_.min -1, minp, maxp, lvm_used, pr) - -- [[ THE END: mcl_mapgen.end.min mcl_mapgen.end.max ]] + -- [[ THE END: mcl_mapgen.end_.min mcl_mapgen.end_.max ]] -- The Void above the End below the Realm barrier: - lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.end.max +1, mcl_vars.mg_realm_barrier_overworld_end_min-1, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.end_.max +1, mcl_vars.mg_realm_barrier_overworld_end_min-1, minp, maxp, lvm_used, pr) -- Realm barrier between the Overworld void and the End lvm_used = set_layers(data, area, c_realm_barrier, nil, mcl_vars.mg_realm_barrier_overworld_end_min , mcl_vars.mg_realm_barrier_overworld_end_max , minp, maxp, lvm_used, pr) -- The Void above Realm barrier below the Overworld: @@ -2041,7 +2041,7 @@ local function basic(c) -- * Replace water with end stone or air (depending on height). -- * Remove stone, sand, dirt in v6 so our End map generator works in v6. -- * Generate spawn platform (End portal destination) - elseif minp.y <= mcl_mapgen.end.max and maxp.y >= mcl_mapgen.end.min then + elseif minp.y <= mcl_mapgen.end_.max and maxp.y >= mcl_mapgen.end_.min then local nodes if mg_name == "v6" then nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"}) @@ -2083,11 +2083,11 @@ local function basic(c) -- Final hackery: Set sun light level in the End. -- -26912 is at a mapchunk border. local shadow = true - if minp.y >= -26912 and maxp.y <= mcl_mapgen.end.max then + if minp.y >= -26912 and maxp.y <= mcl_mapgen.end_.max then vm:set_lighting({day=15, night=15}) lvm_used = true end - if minp.y >= mcl_mapgen.end.min and maxp.y <= -26911 then + if minp.y >= mcl_mapgen.end_.min and maxp.y <= -26911 then shadow = false lvm_used = true end diff --git a/mods/MAPGEN/mcl_strongholds/init.lua b/mods/MAPGEN/mcl_strongholds/init.lua index 42544e1ed..e4bbdb974 100644 --- a/mods/MAPGEN/mcl_strongholds/init.lua +++ b/mods/MAPGEN/mcl_strongholds/init.lua @@ -18,8 +18,7 @@ local stronghold_rings = { local strongholds = {} local strongholds_inited = false -local mg_name = minetest.get_mapgen_setting("mg_name") -local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" +local superflat = mcl_mapgen.superflat -- Determine the stronghold positions and store them into the strongholds table. -- The stronghold positions are based on the world seed. @@ -30,7 +29,7 @@ local init_strongholds = function() return end -- Don't generate strongholds in singlenode - if mg_name == "singlenode" then + if mcl_mapgen.singlenode then strongholds_inited = true return end @@ -47,9 +46,9 @@ local init_strongholds = function() local dist = pr:next(ring.min, ring.max) local y if superflat then - y = mcl_vars.mg_bedrock_overworld_max + 3 + y = mcl_mapgen.overworld.bedrock_max + 3 else - y = pr:next(mcl_vars.mg_bedrock_overworld_max+1, mcl_vars.mg_overworld_min+48) + y = pr:next(mcl_mapgen.overworld.bedrock_max+1, mcl_mapgen.overworld.bedrock_min+48) end local pos = { x = math.cos(angle) * dist, y = y, z = math.sin(angle) * dist } pos = vector.round(pos) diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index ad8c6d99f..a971f203e 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -16,8 +16,7 @@ end local probability_railcaves_in_mapchunk = P(0.33333) setting = tonumber(minetest.settings:get("tsm_railcorridors_probability_railcaves_in_mapchunk")) -- Extra check to prevent mod griefing in singlenode, mcimported worlds. -local mg_name = minetest.get_mapgen_setting("mg_name") -if mg_name == "singlenode" then +if mcl_mapgen.singlenode then probability_railcaves_in_mapchunk = P(0) elseif setting then probability_railcaves_in_mapchunk = P(setting) @@ -93,10 +92,10 @@ end -- Max. and min. heights between rail corridors are generated local height_min -if mcl_vars.mg_lava then +if mcl_mapgen.lava then height_min = mcl_mapgen.overworld.lava_max + 2 else - height_min = mcl_vars.mg_bedrock_overworld_max + 2 + height_min = mcl_mapgen.overworld.bedrock_max + 2 end local height_max = mcl_worlds.layer_to_y(60) From f38c8daab7c78a1898cc52d4f629058f8861edd8 Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 2 May 2021 02:26:41 +0400 Subject: [PATCH 09/61] [mapgen] Add safe chunk calculation --- mods/CORE/mcl_mapgen/init.lua | 81 ++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 24 deletions(-) diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 6d3793a46..8859c0b0a 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -1,13 +1,17 @@ mcl_mapgen = {} -local minetest_log, math_floor = minetest.log, math.floor -local minetest_get_node, minetest_get_voxel_manip = minetest.get_node, minetest.get_voxel_manip +local math_floor = math.floor +local math_max = math.max +local minetest_get_node = minetest.get_node +local minetest_get_voxel_manip = minetest.get_voxel_manip +local minetest_log = minetest.log +local minetest_pos_to_string = minetest.pos_to_string -- Calculate mapgen_edge_min/mapgen_edge_max -mcl_mapgen.CS = math.max(1, tonumber(minetest.get_mapgen_setting("chunksize")) or 5) -mcl_mapgen.BS = math.max(1, core.MAP_BLOCKSIZE or 16) -mcl_mapgen.LIMIT = math.max(1, tonumber(minetest.get_mapgen_setting("mapgen_limit")) or 31000) -mcl_mapgen.MAX_LIMIT = math.max(1, core.MAX_MAP_GENERATION_LIMIT or 31000) +mcl_mapgen.CS = math_max(1, tonumber(minetest.get_mapgen_setting("chunksize")) or 5) +mcl_mapgen.BS = math_max(1, core.MAP_BLOCKSIZE or 16) +mcl_mapgen.LIMIT = math_max(1, tonumber(minetest.get_mapgen_setting("mapgen_limit")) or 31000) +mcl_mapgen.MAX_LIMIT = math_max(1, core.MAX_MAP_GENERATION_LIMIT or 31000) -- might be set to 31000 or removed, see https://github.com/minetest/minetest/issues/10428 mcl_mapgen.OFFSET = - math_floor(mcl_mapgen.CS / 2) mcl_mapgen.OFFSET_NODES = mcl_mapgen.OFFSET * mcl_mapgen.BS mcl_mapgen.CS_NODES = mcl_mapgen.CS * mcl_mapgen.BS @@ -22,8 +26,8 @@ local mapgen_limit_b = math_floor(math.min(mcl_mapgen.LIMIT, mcl_mapgen.MAX_LIMI local mapgen_limit_min = - mapgen_limit_b * mcl_mapgen.BS local mapgen_limit_max = (mapgen_limit_b + 1) * mcl_mapgen.BS - 1 -local numcmin = math.max(math_floor((ccfmin - mapgen_limit_min) / mcl_mapgen.CS_NODES), 0) -- Number of complete chunks from central chunk -local numcmax = math.max(math_floor((mapgen_limit_max - ccfmax) / mcl_mapgen.CS_NODES), 0) -- fullminp/fullmaxp to effective mapgen limits. +local numcmin = math_max(math_floor((ccfmin - mapgen_limit_min) / mcl_mapgen.CS_NODES), 0) -- Number of complete chunks from central chunk +local numcmax = math_max(math_floor((mapgen_limit_max - ccfmax) / mcl_mapgen.CS_NODES), 0) -- fullminp/fullmaxp to effective mapgen limits. mcl_mapgen.EDGE_MIN = central_chunk_min_pos - numcmin * mcl_mapgen.CS_NODES mcl_mapgen.EDGE_MAX = central_chunk_max_pos + numcmax * mcl_mapgen.CS_NODES @@ -39,6 +43,8 @@ local BS, CS = mcl_mapgen.BS, mcl_mapgen.CS -- Mapblock size (in nodes), Mapchun local LAST_BLOCK, LAST_NODE = CS - 1, BS - 1 -- First mapblock in chunk (node in mapblock) has number 0, last has THIS number. It's for runtime optimization local offset = mcl_mapgen.OFFSET -- Central mapchunk offset (in blocks) +local CS_3D = CS * CS * CS + local DEFAULT_PRIORITY = 5000 function mcl_mapgen.register_chunk_generator(callback_function, priority) @@ -66,18 +72,22 @@ function mcl_mapgen.register_block_generator_lvm(callback_function, priority) end local storage = minetest.get_mod_storage() -local blocks = minetest.deserialize( storage:get_string("mapgen_blocks") or "return {}") or {} -minetest.register_on_shutdown(function() storage:set_string("mapgen_blocks", minetest.serialize(blocks)) end) +local blocks = minetest.deserialize(storage:get_string("mapgen_blocks") or "return {}") or {} +local chunks = minetest.deserialize(storage:get_string("mapgen_chunks") or "return {}") or {} +minetest.register_on_shutdown(function() + storage:set_string("mapgen_chunks", minetest.serialize(chunks)) + storage:set_string("mapgen_blocks", minetest.serialize(blocks)) +end) local vm_context-- here will be many references and flags, like: param2, light_data, heightmap, biomemap, heatmap, humiditymap, gennotify, write_lvm, write_param2, shadow local data, data2, area local current_blocks = {} +local current_chunks = {} minetest.register_on_generated(function(minp, maxp, blockseed) local minp, maxp, blockseed = minp, maxp, blockseed - minetest_log("verbose", "[mcl_mapgen] New chunk: minp=" .. minetest.pos_to_string(minp) .. ", maxp=" .. minetest.pos_to_string(maxp) .. ", blockseed=" .. blockseed) - local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") + minetest_log("warning", "[mcl_mapgen] New_chunk=" .. minetest_pos_to_string(minp) .. "..." .. minetest_pos_to_string(maxp) .. ", shall=" .. minetest_pos_to_string(emin) .. "..." .. minetest_pos_to_string(emax) .. ", blockseed=" .. tostring(blockseed)) if lvm > 0 then vm_context = {lvm_param2_buffer = lvm_param2_buffer, vm = vm, emin = emin, emax = emax, minp = minp, maxp = maxp, blockseed = blockseed} @@ -87,12 +97,21 @@ minetest.register_on_generated(function(minp, maxp, blockseed) vm_context.area = area end - local chunk_is_ready = true - - if block > 0 then + if safe_functions > 0 then local x0, y0, z0 = minp.x, minp.y, minp.z local bx0, by0, bz0 = math_floor(x0/BS), math_floor(y0/BS), math_floor(z0/BS) local bx1, by1, bz1 = bx0 + LAST_BLOCK, by0 + LAST_BLOCK, bz0 + LAST_BLOCK -- only for entire chunk check + + -- Keep `blockseed` in `chunks[cx][cy][cz].seed` for further safe usage: + local cx0, cy0, cz0 = math_floor((bx0-offset)/CS), math_floor((by0-offset)/CS), math_floor((bz0-offset)/CS) + if not chunks[cx0] then chunks[cx0] = {} end + if not chunks[cx0][cy0] then chunks[cx0][cy0] = {} end + if not chunks[cx0][cy0][cz0] then + chunks[cx0][cy0][cz0] = {seed = blockseed, counter = 0} + else + chunks[cx0][cy0][cz0].seed = blockseed + end + local x1, y1, z1, x2, y2, z2 = emin.x, emin.y, emin.z, emax.x, emax.y, emax.z local x, y, z = x1, y1, z1 -- iterate 7x7x7 mapchunk, {x,y,z} - first node pos. of mapblock local bx, by, bz -- block coords (in blocs) @@ -100,24 +119,43 @@ minetest.register_on_generated(function(minp, maxp, blockseed) while x < x2 do bx = math_floor(x/BS) local block_pos_offset_removed = bx - offset + local cx = math_floor(block_pos_offset_removed / CS) box = block_pos_offset_removed % CS if not blocks[bx] then blocks[bx]={} end local total_mapgen_block_writes_through_x = (box > 0 and box < LAST_BLOCK) and 4 or 8 while y < y2 do by = math_floor(y/BS) block_pos_offset_removed = by - offset + local cy = math_floor(block_pos_offset_removed / CS) boy = block_pos_offset_removed % CS if not blocks[bx][by] then blocks[bx][by]={} end local total_mapgen_block_writes_through_y = (boy > 0 and boy < LAST_BLOCK) and math_floor(total_mapgen_block_writes_through_x / 2) or total_mapgen_block_writes_through_x while z < z2 do bz = math_floor(z/BS) block_pos_offset_removed = bz - offset + local cz = math_floor(block_pos_offset_removed / CS) boz = block_pos_offset_removed % CS local total_mapgen_block_writes = (boz > 0 and boz < LAST_BLOCK) and math_floor(total_mapgen_block_writes_through_y / 2) or total_mapgen_block_writes_through_y local current_mapgen_block_writes = blocks[bx][by][bz] and (blocks[bx][by][bz] + 1) or 1 if current_mapgen_block_writes == total_mapgen_block_writes then -- this block shouldn't be overwritten anymore, no need to keep it in memory blocks[bx][by][bz] = nil + if not chunks[cx][cy][cz] then + if not chunks[cx] then chunks[cx] = {} end + if not chunks[cx][cy] then chunks[cx][cy] = {} end + if not chunks[cx][cy][cz] then chunks[cx][cy][cz] = {counter = 1} end + else + chunks[cx][cy][cz].counter = chunks[cx][cy][cz].counter + 1 + if chunks[cx][cy][cz].counter >= CS_3D then + -- this chunk shouldn't be overwritten anymore, no need to keep it in memory + local chunkseed = chunks[cx][cy][cz].seed + process_generated_chunk(cx, cy, cz, chunkseed) + + chunks[cx][cy][cz] = nil + if next(chunks[cx][cy]) == nil then chunks[cx][cy] = nil end + if next(chunks[cx]) == nil then chunks[cx] = nil end + end + end vm_context.seed = blockseed + box * 7 + boy * 243 + boz * 11931 if lvm_block > 0 then vm_context.minp, vm_content.maxp = {x=x, y=y, z=z}, {x=x+LAST_NODE, y=y+LAST_NODE, z=z+LAST_NODE} @@ -130,7 +168,6 @@ minetest.register_on_generated(function(minp, maxp, blockseed) end else blocks[bx][by][bz] = current_mapgen_block_writes - chunk_is_ready = chunk_is_ready and (bx < bx0 or bx > bx1 or by < by0 or by > by1 or bz < bz0 or bz > bz1) end z = z + BS end @@ -145,10 +182,8 @@ minetest.register_on_generated(function(minp, maxp, blockseed) end if lvm > 0 then - if chunk_is_ready then - for _, v in pairs(lvm_chunk_queue) do - vm_context = v.f(vm_context) - end + for _, v in pairs(lvm_chunk_queue) do + vm_context = v.f(vm_context) end if vm_context.write then vm:set_data(data) @@ -161,10 +196,8 @@ minetest.register_on_generated(function(minp, maxp, blockseed) vm:update_liquids() end - if chunk_is_ready then - for _, v in pairs(node_chunk_queue) do - v.f(minp, maxp, blockseed) - end + for _, v in pairs(node_chunk_queue) do + v.f(minp, maxp, blockseed) end for i, b in pairs(current_blocks) do From f4a28cfab0c686c9b750e0c0f53e287a8d7b667f Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 2 May 2021 03:56:55 +0400 Subject: [PATCH 10/61] [mapgen] GETTING RID OF EMERGE AREAS! Currently for dungeons and villages, and it works --- mods/CORE/mcl_mapgen/init.lua | 29 +++++++++++++++-------- mods/MAPGEN/mcl_dungeons/init.lua | 22 ++++++++++------- mods/MAPGEN/mcl_villages/init.lua | 33 +++++++++++++++++--------- mods/MAPGEN/mcl_villages/utils.lua | 38 ------------------------------ 4 files changed, 54 insertions(+), 68 deletions(-) diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 8859c0b0a..5be3ac488 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -37,11 +37,12 @@ minetest_log("action", "[mcl_mapgen] World edges are: mcl_mapgen.EDGE_MIN = " .. local lvm_block_queue, lvm_chunk_queue, node_block_queue, node_chunk_queue = {}, {}, {}, {} -- Generators' queues -local lvm, block, lvm_block, lvm_chunk, param2, nodes_block, nodes_chunk = 0, 0, 0, 0, 0, 0, 0 -- Requirements: 0 means none; greater than 0 means 'required' +local lvm, block, lvm_block, lvm_chunk, param2, nodes_block, nodes_chunk, safe_functions = 0, 0, 0, 0, 0, 0, 0, 0 -- Requirements: 0 means none; greater than 0 means 'required' local lvm_buffer, lvm_param2_buffer = {}, {} -- Static buffer pointers local BS, CS = mcl_mapgen.BS, mcl_mapgen.CS -- Mapblock size (in nodes), Mapchunk size (in blocks) local LAST_BLOCK, LAST_NODE = CS - 1, BS - 1 -- First mapblock in chunk (node in mapblock) has number 0, last has THIS number. It's for runtime optimization local offset = mcl_mapgen.OFFSET -- Central mapchunk offset (in blocks) +local CS_NODES = mcl_mapgen.CS_NODES -- 80 local CS_3D = CS * CS * CS @@ -49,6 +50,7 @@ local DEFAULT_PRIORITY = 5000 function mcl_mapgen.register_chunk_generator(callback_function, priority) nodes_chunk = nodes_chunk + 1 + safe_functions = safe_functions + 1 node_chunk_queue[nodes_chunk] = {i = priority or DEFAULT_PRIORITY, f = callback_function} table.sort(node_chunk_queue, function(a, b) return (a.i <= b.i) end) end @@ -60,6 +62,7 @@ end function mcl_mapgen.register_block_generator(callback_function, priority) block = block + 1 nodes_block = nodes_block + 1 + safe_functions = safe_functions + 1 node_block_queue[nodes_block] = {i = priority or DEFAULT_PRIORITY, f = callback_function} table.sort(node_block_queue, function(a, b) return (a.i <= b.i) end) end @@ -87,7 +90,7 @@ local current_chunks = {} minetest.register_on_generated(function(minp, maxp, blockseed) local minp, maxp, blockseed = minp, maxp, blockseed local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") - minetest_log("warning", "[mcl_mapgen] New_chunk=" .. minetest_pos_to_string(minp) .. "..." .. minetest_pos_to_string(maxp) .. ", shall=" .. minetest_pos_to_string(emin) .. "..." .. minetest_pos_to_string(emax) .. ", blockseed=" .. tostring(blockseed)) + minetest_log("warning", "[mcl_mapgen] New_chunk=" .. minetest_pos_to_string(minp) .. "..." .. minetest_pos_to_string(maxp) .. ", shell=" .. minetest_pos_to_string(emin) .. "..." .. minetest_pos_to_string(emax) .. ", blockseed=" .. tostring(blockseed)) if lvm > 0 then vm_context = {lvm_param2_buffer = lvm_param2_buffer, vm = vm, emin = emin, emax = emax, minp = minp, maxp = maxp, blockseed = blockseed} @@ -140,17 +143,15 @@ minetest.register_on_generated(function(minp, maxp, blockseed) if current_mapgen_block_writes == total_mapgen_block_writes then -- this block shouldn't be overwritten anymore, no need to keep it in memory blocks[bx][by][bz] = nil + if not chunks[cx] then chunks[cx] = {} end + if not chunks[cx][cy] then chunks[cx][cy] = {} end if not chunks[cx][cy][cz] then - if not chunks[cx] then chunks[cx] = {} end - if not chunks[cx][cy] then chunks[cx][cy] = {} end if not chunks[cx][cy][cz] then chunks[cx][cy][cz] = {counter = 1} end else chunks[cx][cy][cz].counter = chunks[cx][cy][cz].counter + 1 if chunks[cx][cy][cz].counter >= CS_3D then + current_chunks[#current_chunks+1] = { x = cx, y = cy, z = cz, s = chunks[cx][cy][cz].seed } -- this chunk shouldn't be overwritten anymore, no need to keep it in memory - local chunkseed = chunks[cx][cy][cz].seed - process_generated_chunk(cx, cy, cz, chunkseed) - chunks[cx][cy][cz] = nil if next(chunks[cx][cy]) == nil then chunks[cx][cy] = nil end if next(chunks[cx]) == nil then chunks[cx] = nil end @@ -196,15 +197,23 @@ minetest.register_on_generated(function(minp, maxp, blockseed) vm:update_liquids() end - for _, v in pairs(node_chunk_queue) do - v.f(minp, maxp, blockseed) + for i, b in pairs(current_chunks) do + local cx, cy, cz, seed = b.x, b.y, b.z, b.s + local bx, by, bz = cx * CS + offset, cy * CS + offset, cz * CS + offset + local x, y, z = bx * BS, by * BS, bz * BS + local minp = {x = x, y = y, z = z} + local maxp = {x = x + CS_NODES - 1, y = y + CS_NODES - 1, z = z + CS_NODES - 1} + for _, v in pairs(node_chunk_queue) do + v.f(minp, maxp, seed) + end + current_chunks[i] = nil end for i, b in pairs(current_blocks) do for _, v in pairs(node_block_queue) do v.f(b.minp, b.maxp, b.seed) end - current_blocks[id] = nil + current_blocks[i] = nil end end) diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index d2458939e..a24e4dc9d 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -14,7 +14,7 @@ local swap_node = minetest.swap_node local set_node = minetest.set_node local dir_to_facedir = minetest.dir_to_facedir local get_meta = minetest.get_meta -local emerge_area = minetest.emerge_area +-- local emerge_area = minetest.emerge_area --vector local vector_add = vector.add @@ -61,12 +61,14 @@ local surround_vectors = { { x=0, y=0, z=1 }, } -local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) - if calls_remaining >= 1 then return end +--local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) +-- if calls_remaining >= 1 then return end +-- local p1, _, dim, pr = param.p1, param.p2, param.dim, param.pr +-- local check = not (param.dontcheck or false) +local function spawn_dungeon(p1, p2, dim, pr, dontcheck) - local p1, _, dim, pr = param.p1, param.p2, param.dim, param.pr local x, y, z = p1.x, p1.y, p1.z - local check = not (param.dontcheck or false) + local check = not (dontcheck or false) -- Check floor and ceiling: Must be *completely* solid local y_floor = y @@ -401,8 +403,9 @@ local function dungeons_nodes(minp, maxp, blockseed) local z = pr:next(minp.z, maxp.z-dim.z-1) local p1 = {x=x,y=y,z=z} local p2 = {x = x+dim.x+1, y = y+dim.y+1, z = z+dim.z+1} - minetest.log("verbose","[mcl_dungeons] size=" ..minetest.pos_to_string(dim) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2)) - emerge_area(p1, p2, ecb_spawn_dungeon, {p1=p1, p2=p2, dim=dim, pr=pr}) + -- minetest.log("verbose","[mcl_dungeons] size=" ..minetest.pos_to_string(dim) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2)) + -- emerge_area(p1, p2, ecb_spawn_dungeon, {p1=p1, p2=p2, dim=dim, pr=pr}) + spawn_dungeon(p1, p2, dim, pr) end end @@ -410,8 +413,9 @@ function mcl_dungeons.spawn_dungeon(p1, _, pr) if not p1 or not pr or not p1.x or not p1.y or not p1.z then return end local dim = dungeonsizes[pr:next(1, #dungeonsizes)] local p2 = {x = p1.x+dim.x+1, y = p1.y+dim.y+1, z = p1.z+dim.z+1} - minetest.log("verbose","[mcl_dungeons] size=" ..minetest.pos_to_string(dim) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2)) - emerge_area(p1, p2, ecb_spawn_dungeon, {p1=p1, p2=p2, dim=dim, pr=pr, dontcheck=true}) +-- minetest.log("verbose","[mcl_dungeons] size=" ..minetest.pos_to_string(dim) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2)) +-- emerge_area(p1, p2, ecb_spawn_dungeon, {p1=p1, p2=p2, dim=dim, pr=pr, dontcheck=true}) + spawn_dungeon(p1, p2, dim, pr, true) end mcl_mapgen.register_chunk_generator(dungeons_nodes, 999999) diff --git a/mods/MAPGEN/mcl_villages/init.lua b/mods/MAPGEN/mcl_villages/init.lua index f1b1de906..2b7109451 100644 --- a/mods/MAPGEN/mcl_villages/init.lua +++ b/mods/MAPGEN/mcl_villages/init.lua @@ -1,6 +1,8 @@ settlements = {} settlements.modpath = minetest.get_modpath("mcl_villages") +local minetest_get_spawn_level = minetest.get_spawn_level + dofile(settlements.modpath.."/const.lua") dofile(settlements.modpath.."/utils.lua") dofile(settlements.modpath.."/foundation.lua") @@ -53,6 +55,7 @@ end -- on map generation, try to build a settlement -- local function build_a_settlement(minp, maxp, blockseed) + minetest.log("action","[mcl_villages] Building village at mapchunk " .. minetest.pos_to_string(minp) .. "..." .. minetest.pos_to_string(maxp) .. ", blockseed = " .. tostring(blockseed)) local pr = PseudoRandom(blockseed) -- fill settlement_info with buildings and their data @@ -69,28 +72,36 @@ local function build_a_settlement(minp, maxp, blockseed) settlements.place_schematics(settlement_info, pr) end -local function ecb_village(blockpos, action, calls_remaining, param) - if calls_remaining >= 1 then return end - local minp, maxp, blockseed = param.minp, param.maxp, param.blockseed - build_a_settlement(minp, maxp, blockseed) -end - -- Disable natural generation in singlenode. local mg_name = minetest.get_mapgen_setting("mg_name") if mg_name ~= "singlenode" then mcl_mapgen.register_chunk_generator(function(minp, maxp, blockseed) + -- local str1 = (maxp.y >= 0 and blockseed % 77 == 17) and "YES" or "no" + -- minetest.log("action","[mcl_villages] " .. str1 .. ": minp=" .. minetest.pos_to_string(minp) .. ", maxp=" .. minetest.pos_to_string(maxp) .. ", blockseed=" .. tostring(blockseed)) -- don't build settlement underground if maxp.y < 0 then return end -- randomly try to build settlements if blockseed % 77 ~= 17 then return end - -- needed for manual and automated settlement building + -- don't build settlements on (too) uneven terrain - --local heightmap = minetest.get_mapgen_object("heightmap") - local height_difference = settlements.evaluate_heightmap() + + -- lame and quick replacement of `heightmap` by kay27 - we maybe need to restore `heightmap` analysis if there will be a way for the engine to avoid cavegen conflicts: + -------------------------------------------------------------------------- + local height_difference, min, max + local pr1=PseudoRandom(blockseed) + for i=1,pr1:next(5,10) do + local x = pr1:next(0, 40) + minp.x + 19 + local z = pr1:next(0, 40) + minp.z + 19 + local y = minetest_get_spawn_level(x, z) + if y < (min or y+1) then min = y end + if y > (max or y-1) then max = y end + end + height_difference = max - min + 1 + -------------------------------------------------------------------------- + if height_difference > max_height_difference then return end - local param={minp=vector.new(minp), maxp=vector.new(maxp), blockseed=blockseed} - minetest.emerge_area(minp, maxp, ecb_village, param) + build_a_settlement(minp, maxp, blockseed) end) end -- manually place villages diff --git a/mods/MAPGEN/mcl_villages/utils.lua b/mods/MAPGEN/mcl_villages/utils.lua index 87473cc80..1d94ead0c 100644 --- a/mods/MAPGEN/mcl_villages/utils.lua +++ b/mods/MAPGEN/mcl_villages/utils.lua @@ -207,44 +207,6 @@ function shuffle(tbl, pr) return table end ------------------------------------------------------------------------------- --- evaluate heightmap -------------------------------------------------------------------------------- -function settlements.evaluate_heightmap() - local heightmap = minetest.get_mapgen_object("heightmap") - -- max height and min height, initialize with impossible values for easier first time setting - local max_y = -50000 - local min_y = 50000 - -- only evaluate the center square of heightmap 40 x 40 - local square_start = 1621 - local square_end = 1661 - for j = 1 , 40, 1 do - for i = square_start, square_end, 1 do - -- skip buggy heightmaps, return high value - if heightmap[i] == -31000 or heightmap[i] == 31000 then - return max_height_difference + 1 - end - if heightmap[i] < min_y then - min_y = heightmap[i] - end - if heightmap[i] > max_y then - max_y = heightmap[i] - end - end - -- set next line - square_start = square_start + 80 - square_end = square_end + 80 - end - -- return the difference between highest and lowest pos in chunk - local height_diff = max_y - min_y - -- filter buggy heightmaps - if height_diff <= 1 then - return max_height_difference + 1 - end - -- debug info - settlements.debug("heightdiff ".. height_diff) - return height_diff -end -------------------------------------------------------------------------------- -- Set array to list -- https://stackoverflow.com/questions/656199/search-for-an-item-in-a-lua-list ------------------------------------------------------------------------------- From fd56bb746cd2cf0d146eee813ff41451bcfce2d0 Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 2 May 2021 04:25:23 +0400 Subject: [PATCH 11/61] [mapgen] Spawn strongholds without emerge areas --- mods/MAPGEN/mcl_dungeons/init.lua | 5 ----- mods/MAPGEN/mcl_structures/init.lua | 4 +++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index a24e4dc9d..03a5c4e07 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -14,7 +14,6 @@ local swap_node = minetest.swap_node local set_node = minetest.set_node local dir_to_facedir = minetest.dir_to_facedir local get_meta = minetest.get_meta --- local emerge_area = minetest.emerge_area --vector local vector_add = vector.add @@ -403,8 +402,6 @@ local function dungeons_nodes(minp, maxp, blockseed) local z = pr:next(minp.z, maxp.z-dim.z-1) local p1 = {x=x,y=y,z=z} local p2 = {x = x+dim.x+1, y = y+dim.y+1, z = z+dim.z+1} - -- minetest.log("verbose","[mcl_dungeons] size=" ..minetest.pos_to_string(dim) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2)) - -- emerge_area(p1, p2, ecb_spawn_dungeon, {p1=p1, p2=p2, dim=dim, pr=pr}) spawn_dungeon(p1, p2, dim, pr) end end @@ -413,8 +410,6 @@ function mcl_dungeons.spawn_dungeon(p1, _, pr) if not p1 or not pr or not p1.x or not p1.y or not p1.z then return end local dim = dungeonsizes[pr:next(1, #dungeonsizes)] local p2 = {x = p1.x+dim.x+1, y = p1.y+dim.y+1, z = p1.z+dim.z+1} --- minetest.log("verbose","[mcl_dungeons] size=" ..minetest.pos_to_string(dim) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2)) --- emerge_area(p1, p2, ecb_spawn_dungeon, {p1=p1, p2=p2, dim=dim, pr=pr, dontcheck=true}) spawn_dungeon(p1, p2, dim, pr, true) end diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 8304061af..617c19d46 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -33,7 +33,9 @@ mcl_structures.place_schematic = function(pos, schematic, rotation, replacements local p2 = {x=pos.x+x-1, y=pos.y+s.size.y-1, z=pos.z+z-1} minetest.log("verbose","[mcl_structures] size=" ..minetest.pos_to_string(s.size) .. ", rotation=" .. tostring(rotation) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2)) local param = {pos=vector.new(pos), schematic=s, rotation=rotation, replacements=replacements, force_placement=force_placement, flags=flags, p1=p1, p2=p2, after_placement_callback = after_placement_callback, size=vector.new(s.size), pr=pr, callback_param=callback_param} - minetest.emerge_area(p1, p2, ecb_place, param) + -- minetest.emerge_area(p1, p2, ecb_place, param) + -- TODO: Make it better + ecb_place(0, 0, 0, param) end end From 238eb6cb6823ffe1bb35ca1f4cf54a3fb0d7903f Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 2 May 2021 13:29:29 +0400 Subject: [PATCH 12/61] [mapgen] Comment complex part of the code --- mods/CORE/mcl_mapgen/init.lua | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 5be3ac488..f89eeabf9 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -46,7 +46,7 @@ local CS_NODES = mcl_mapgen.CS_NODES -- 80 local CS_3D = CS * CS * CS -local DEFAULT_PRIORITY = 5000 +local DEFAULT_PRIORITY = 5000 function mcl_mapgen.register_chunk_generator(callback_function, priority) nodes_chunk = nodes_chunk + 1 @@ -125,6 +125,12 @@ minetest.register_on_generated(function(minp, maxp, blockseed) local cx = math_floor(block_pos_offset_removed / CS) box = block_pos_offset_removed % CS if not blocks[bx] then blocks[bx]={} end + + -- We don't know how many calls, including this one, will overwrite this block's content! + -- Start calculating it with `total_mapgen_block_writes_through_x` variable. + -- It can be `8 or less`, if we (speaking of `x` axis) are on chunk edge now, + -- or it can be `4 or less` - if we are in the middle of the chunk by `x` axis: + local total_mapgen_block_writes_through_x = (box > 0 and box < LAST_BLOCK) and 4 or 8 while y < y2 do by = math_floor(y/BS) @@ -132,14 +138,34 @@ minetest.register_on_generated(function(minp, maxp, blockseed) local cy = math_floor(block_pos_offset_removed / CS) boy = block_pos_offset_removed % CS if not blocks[bx][by] then blocks[bx][by]={} end + + -- Here we just divide `total_mapgen_block_writes_through_x` by 2, + -- if we are (speaking of `y` axis now) in the middle of the chunk now. + -- Or we don't divide it, if not. + -- So, basing on `total_mapgen_block_writes_through_x`, + --- we calculate `total_mapgen_block_writes_through_y` this way: + local total_mapgen_block_writes_through_y = (boy > 0 and boy < LAST_BLOCK) and math_floor(total_mapgen_block_writes_through_x / 2) or total_mapgen_block_writes_through_x while z < z2 do bz = math_floor(z/BS) block_pos_offset_removed = bz - offset local cz = math_floor(block_pos_offset_removed / CS) boz = block_pos_offset_removed % CS + + -- Now we do absolutely the same for `z` axis, basing on our previous result + -- from `total_mapgen_block_writes_through_y` variable. + -- And our final result is in `total_mapgen_block_writes`. + -- It can be still 8, derived from `x` calculation, but it can be less! + -- It can be even 1, if we are in safe 3x3x3 area of mapchunk: + local total_mapgen_block_writes = (boz > 0 and boz < LAST_BLOCK) and math_floor(total_mapgen_block_writes_through_y / 2) or total_mapgen_block_writes_through_y + + -- Get current number of writes from the table, or just set it to 1, if accessed first time: + local current_mapgen_block_writes = blocks[bx][by][bz] and (blocks[bx][by][bz] + 1) or 1 + + -- And compare: + if current_mapgen_block_writes == total_mapgen_block_writes then -- this block shouldn't be overwritten anymore, no need to keep it in memory blocks[bx][by][bz] = nil From 16700632afc074410db87e5f47f99dc663f906f9 Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 2 May 2021 23:18:03 +0400 Subject: [PATCH 13/61] [mapgen] [debug] Add blockseed calculation functions --- mods/CORE/mcl_mapgen/init.lua | 54 ++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index f89eeabf9..9c6fb8a11 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -35,6 +35,18 @@ mcl_mapgen.EDGE_MAX = central_chunk_max_pos + numcmax * mcl_mapgen.CS_NODES minetest_log("action", "[mcl_mapgen] World edges are: mcl_mapgen.EDGE_MIN = " .. tostring(mcl_mapgen.EDGE_MIN) .. ", mcl_mapgen.EDGE_MAX = " .. tostring(mcl_mapgen.EDGE_MAX)) ------------------------------------------ +-- Mapgen variables +local overworld, end_, nether = {}, {}, {} +mcl_mapgen.seed = minetest.get_mapgen_setting("seed") +mcl_mapgen.name = minetest.get_mapgen_setting("mg_name") +mcl_mapgen.v6 = mcl_mapgen.name == "v6" +mcl_mapgen.superflat = mcl_mapgen.name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" +mcl_mapgen.singlenode = mcl_mapgen.name == "singlenode" +mcl_mapgen.normal = not mcl_mapgen.superflat and not mcl_mapgen.singlenode +local superflat, singlenode, normal = mcl_mapgen.superflat, mcl_mapgen.singlenode, mcl_mapgen.normal + +minetest_log("action", "[mcl_mapgen] Mapgen mode: " .. (normal and "normal" or (superflat and "superflat" or "singlenode"))) +------------------------------------------ local lvm_block_queue, lvm_chunk_queue, node_block_queue, node_chunk_queue = {}, {}, {}, {} -- Generators' queues local lvm, block, lvm_block, lvm_chunk, param2, nodes_block, nodes_chunk, safe_functions = 0, 0, 0, 0, 0, 0, 0, 0 -- Requirements: 0 means none; greater than 0 means 'required' @@ -74,6 +86,33 @@ function mcl_mapgen.register_block_generator_lvm(callback_function, priority) table.sort(lvm_block_queue, function(a, b) return (a.i <= b.i) end) end +function mcl_mapgen.get_block_seed(pos, seed) + local p = pos + local x, y, z = p.x, p.y, p.z + if x<0 then x = 4294967296+x end + if y<0 then y = 4294967296+y end + if z<0 then z = 4294967296+z end + local seed = (seed or mcl_mapgen.seed or 0) % 4294967296 + return (seed + (z*38134234)%4294967296 + (y*42123)%4294967296 + (x*23)%4294967296) % 4294967296 +end + +function mcl_mapgen.get_block_seed_2(pos, seed) + local p = pos + local seed = seed or mcl_mapgen.seed or 0 + local x, y, z = p.x, p.y, p.z + if x<0 then x = 4294967296+x end + if y<0 then y = 4294967296+y end + if z<0 then z = 4294967296+z end + local n = ((1619*x)%4294967296 + (31337*y)%4294967296 + (52591*z)%4294967296 + (1013*seed)%4294967296) % 4294967296 +-- n = (math_floor(n / 8192) ^ n) % 4294967296 + + local m = (n*n) % 4294967296 + m = (m*60493) % 4294967296 + m = (m+19990303) % 4294967296 + + return (n * m + 1376312589) % 4294967296 +end + local storage = minetest.get_mod_storage() local blocks = minetest.deserialize(storage:get_string("mapgen_blocks") or "return {}") or {} local chunks = minetest.deserialize(storage:get_string("mapgen_chunks") or "return {}") or {} @@ -90,7 +129,7 @@ local current_chunks = {} minetest.register_on_generated(function(minp, maxp, blockseed) local minp, maxp, blockseed = minp, maxp, blockseed local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") - minetest_log("warning", "[mcl_mapgen] New_chunk=" .. minetest_pos_to_string(minp) .. "..." .. minetest_pos_to_string(maxp) .. ", shell=" .. minetest_pos_to_string(emin) .. "..." .. minetest_pos_to_string(emax) .. ", blockseed=" .. tostring(blockseed)) + minetest_log("warning", "[mcl_mapgen] New_chunk=" .. minetest_pos_to_string(minp) .. "..." .. minetest_pos_to_string(maxp) .. ", shell=" .. minetest_pos_to_string(emin) .. "..." .. minetest_pos_to_string(emax) .. ", blockseed=" .. tostring(blockseed) .. ", seed1=" .. mcl_mapgen.get_block_seed(minp) .. ", seed2=" .. mcl_mapgen.get_block_seed_2(minp)) if lvm > 0 then vm_context = {lvm_param2_buffer = lvm_param2_buffer, vm = vm, emin = emin, emax = emax, minp = minp, maxp = maxp, blockseed = blockseed} @@ -289,19 +328,6 @@ function mcl_mapgen.get_chunk_number(pos) -- unsigned int c.x + k_positive end - --- Mapgen variables -local overworld, end_, nether = {}, {}, {} -mcl_mapgen.seed = minetest.get_mapgen_setting("seed") -mcl_mapgen.name = minetest.get_mapgen_setting("mg_name") -mcl_mapgen.v6 = mcl_mapgen.name == "v6" -mcl_mapgen.superflat = mcl_mapgen.name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" -mcl_mapgen.singlenode = mcl_mapgen.name == "singlenode" -mcl_mapgen.normal = not mcl_mapgen.superflat and not mcl_mapgen.singlenode -local superflat, singlenode, normal = mcl_mapgen.superflat, mcl_mapgen.singlenode, mcl_mapgen.normal - -minetest_log("action", "[mcl_mapgen] Mapgen mode: " .. (normal and "normal" or (superflat and "superflat" or "singlenode"))) - mcl_mapgen.minecraft_height_limit = 256 mcl_mapgen.bedrock_is_rough = normal From 66d117285254ee387822a73c4343177aea179e22 Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 3 May 2021 05:24:53 +0400 Subject: [PATCH 14/61] [mapgen] Add ocean monument --- mods/CORE/mcl_mapgen/init.lua | 6 +++ mods/MAPGEN/mcl_ocean_monument/init.lua | 36 ++++++++++++++++++ mods/MAPGEN/mcl_ocean_monument/mod.conf | 4 ++ .../schematics/ocean_monument.mts | Bin 0 -> 8342 bytes mods/MAPGEN/mcl_villages/init.lua | 1 + 5 files changed, 47 insertions(+) create mode 100644 mods/MAPGEN/mcl_ocean_monument/init.lua create mode 100644 mods/MAPGEN/mcl_ocean_monument/mod.conf create mode 100644 mods/MAPGEN/mcl_ocean_monument/schematics/ocean_monument.mts diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 9c6fb8a11..a5982ae4e 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -1,5 +1,9 @@ mcl_mapgen = {} +local priority = { + OCEAN_MONUMENT = 1000000 +} + local math_floor = math.floor local math_max = math.max local minetest_get_node = minetest.get_node @@ -398,3 +402,5 @@ mcl_mapgen.dungeons = normal mcl_mapgen.overworld = overworld mcl_mapgen.end_ = end_ mcl_mapgen.nether = nether + +mcl_mapgen.priorities = priority diff --git a/mods/MAPGEN/mcl_ocean_monument/init.lua b/mods/MAPGEN/mcl_ocean_monument/init.lua new file mode 100644 index 000000000..135e315bd --- /dev/null +++ b/mods/MAPGEN/mcl_ocean_monument/init.lua @@ -0,0 +1,36 @@ +local mcl_mapgen_get_far_node = mcl_mapgen.get_far_node +local minetest_log = minetest.log +local minetest_place_schematic = minetest.place_schematic +local minetest_pos_to_string = minetest.pos_to_string + +local path = minetest.get_modpath("mcl_ocean_monument") .. "/schematics/ocean_monument.mts" +local water, air = "mcl_core:water_source", "air" + +mcl_mapgen.register_chunk_generator(function(minp, maxp, seed) + local minp = minp + local y = minp.y + if y ~= -32 then return end + + local x, z = minp.x, minp.z + local pr = PseudoRandom(seed) + for i = 1, pr:next(10,100) do + if mcl_mapgen_get_far_node({x=pr:next(0,79)+x, y=1, z=pr:next(0,79)+z}).name ~= water then return end + end + for i = 1, pr:next(10,100) do + if mcl_mapgen_get_far_node({x=pr:next(0,79)+x, y=2, z=pr:next(0,79)+z}).name ~= air then return end + end + for i = 1, pr:next(10,100) do + if mcl_mapgen_get_far_node({x=pr:next(15,64)+x, y=pr:next(0,25)-25, z=pr:next(15,64)+z}).name ~= water then +-- minetest_log("warning", "[mcl_ocean_monument] Not water at " .. minetest_pos_to_string(minp)) + return + end + end + +-- minetest_place_schematic(minp, path, tostring(pr:next(0,3)*90), nil, true) + minetest_place_schematic(minp, path, 0, nil, true) + + minetest_log("action", "[mcl_ocean_monument] Placed at " .. minetest_pos_to_string(minp)) + + ---- TODO: SET UP SPECIAL NODES... + +end, mcl_mapgen.priorities.OCEAN_MONUMENT) diff --git a/mods/MAPGEN/mcl_ocean_monument/mod.conf b/mods/MAPGEN/mcl_ocean_monument/mod.conf new file mode 100644 index 000000000..62648e987 --- /dev/null +++ b/mods/MAPGEN/mcl_ocean_monument/mod.conf @@ -0,0 +1,4 @@ +name = mcl_ocean_monument +author = Sister of epCode +description = Adds Ocean Monument, https://git.minetest.land/MineClone2/MineClone2/issues/958#issuecomment-14102 +depends = mcl_mapgen, mcl_structures diff --git a/mods/MAPGEN/mcl_ocean_monument/schematics/ocean_monument.mts b/mods/MAPGEN/mcl_ocean_monument/schematics/ocean_monument.mts new file mode 100644 index 0000000000000000000000000000000000000000..f94b808b521a431c82d0ed5a708156daf748171b GIT binary patch literal 8342 zcmaKRcU)7+yLa3*t8TEMNU#73i--h+K$I3(lqwyhgg`)gZ&4vsH)}y!%!(ip0wTR? z=#YT10Ma28DFV_WHMAsz2)qaP_rCY@dGGz)`6HQgX6BjaJpDUke9O`pv>&7j5(lY9 z|L+ZS5cKP9uVBz=KNnxe02jC0{;Gk&URb}|!CwAuj?TeeEVJCc=z2TY z2PC~WguMgM#j0X`Z#z5w|0Eq<1MWKex`9sq7Y(f2ZAahR{&(Dh{Xxfnt`7|G_izIU z{QUp-ol8Klo2o~EudB0ffQwIP+ERKPeiBx$sAIH6AJHWlmP;D6S_Ef&#WizC9|~{c{0}U{c&b` z4+9$(wTPb;&CXqxBeQ4=;RDe(q&RpVQO=;{U>|kj!^^d{W6N&|P=T^5N%N^U$fmf5 zy55hNd3Q7nLwI#AFS+;zZkzas1yX!W!xA0O)BXkYjvMp{s(r#(sjLK-4Bcq6yc9&v z$Y-&f+3bR)k_86o74%NqRM=ypA3L5lAxSdviWh;#w?Vy=BT|d={Orv}-e;8i3?x8? znGDk4I{wu{dYyWT5;h|-=!@YOo0FPH05vm%9~@00KqaY8UiN_xpcRRbx*0w#^RE5M zGDiL^G=7c+E}6nBIF~_P?T_u5MdzduyoNhwfDX9I1g~?2yty&My4OZE2n8OCVAfrN z=a}LgMn*&PE;pts+R-dA`FUbVC0UZ@6ndocA3Ob}ysoi5)0xmuFzh~R=IqiP)hT*3J=Hddx71tl zGC|CnTSZYM#1WxA=E)n_P|jn{;VS5`Cnf+cGU)h{H3udXdd!LSkV(TD>y7Tu2JSF$ zDLLbkc6M1AU4eDK`5+s+Aj@SQD1_LcxTUEhJ3nk7{})h2kgII4Zrj5PB+n`@v8jDI zq<+cI$J@pwL;-spCFH5}Lh5R(!kREEg2pLIg9!gcc(jI;H6dwW@mrfO6Wf0lm}eiV z(Tt;SNY`$>RFU~A6KeCFtnE|V+ITprH$s~sGk%iXh{UX%C#Totki)4?qZ(g25tw5j zJC(e$+IG>`wU=H45$I}%8jfC*;#uZb1Wh98;poX>%WQm9G*<-veUP!Mwz`Vt*JQqI z+pUU!sKG9N-6Wn}wRB^yu3sa-(Yl{A7p0c(h>W!ANH6W$ZUzHUq}FuI9CZkkII&JU zNAk=<<>8?4nzAZCOkl?3T3r`pm~ed&+{TT$*%7!Ti0RJIbOuatR+Q>AB9dp8Ty6|3Md2ke~A#P0Kvjj!CYFUhIE^I3ivg6;#mVDC1s$oG|rFN`6Lg@{p zIRDzOfO7Afx)k#b*|sSSMhyYx%a$WSAtD0_vOkOf3SS*fi{eaJj9eLhz2*q%N73t@ zfDRT{KSv{o7g2@Nsy^U1uMU3^wQ&ZTgm{AdhZ;g*)=a!_gFI>!Ra_J6nL+Wh(<2F< zjV=p5jbdFN*Du0j`1?U1WkNZ1B949YPRk94^13Xyy5-9SNQ^v{+d13D!D;19CR!hs z!*pv_HHT_BFihg00$m<7cN%mwT7w%szh$|I{c z>7Y2l21^&(z$lNl%^>>~&rfc$$`rQW@ zGfuemdkyRF;06ATZ?>^lPY#ynLHqJLSM_-cWu&h6MSV$3MKUE+N3-ebPC>YMG%D5{ zBQLHw%g6KNnnxu`E=kb#00f}KBpK=s552jL4_BJn`Lxbb#R?qMG|jm!!wQrr>i3EiEdIpyDnJ_sXE@-A9Lr?#Dr)OBPa_k7%jq5c8V zQ031nAtC{pyq*S+-0~CqOc*Mf_t{~MOLFi>uZVKZybT4z=(Y^exb7RsTrrHiMwR9y z>F?aR&XAYTJ`r=%mrx^I3OVW%2jif`2SQx$;sSAcHGX@d?vo%UkcR$RB90?`zv0JC zJPoZVIh7L&eGtAPNnW5svH&I;E?~ONw}BpLy#?>u(U2L zHPia|HAE9+_Ld_?{)a}krl!BWnF)6-qi&waRP5{IQB2qIwfD{dSrDz<47t3>K5}mh zM?d{(rgE{Zb?jABq&GhX(T3?3m!6ve&s=1fW4a^Dca`B^s>#;TD=#L^bKJb!xnKlg zdRA{#a(LV$oIQ)sH(aI7}{%y=oN)Etaj8l5p(03bze=Fv6VmBQ*~)IJ}7c zBU|foA6Xx78CUYiQ}|_m{m$B3%*yw$%i$H3xwM{6|K-TTppcms(~9w^2+C|>`~^}- zUmuMgqqoU3;$DMA&JPba>@c^igjr^JHPnHy!q5hjp4>wIL1+M1Og5Ar#2#gV`3aD% z43Fv`f*stmP$QaYbC?zy*|mb-Q~-H`;mX&sR=OuT)V#?|uuoe)E_)OsHr6)@HUtXq zj&0FbchfiUQZURL`!2nTKlB;`hGxNr#UAtotp}tihxg1H>#Fr3zF5!kIL%LGu5Jk3~plN%ThV`ux#~b{)HvvyQIdEos@zvkO5AWjj^8(8o7#JD%9IjD3bk< z0{F>0huRG29rPmtJLNZixK>C-Z)D>bMt<~}i6h*T5m5*PiSKZqB9HXk=#0sLI~qPG z{V?6*rpg)jl;$XDQ{YO|9w7ER{s!>Yol#D6;*A;9Lyfq<1HxdyA|2oKLy{K?Sklzp zE7l2l5$sW97QsM#%10bJYS~52tMt3315u?MBgO!^|&1KzS$#0yR9AEE`A4p^QwpR$Gk|&%89x6lectBhW(|3$|N8i9tuv zT_Vx;@-tb%1i>l%>vUfB6 z&)Fi}VYo=Lyv^k1?QKzWgU_9HSKf0_aC28Ip+jw#+f?`h~)2s^Y_ zNJknEeGsSpu>^J`Y_N=4Ppc{s9PJGHoK<$0V2lKNrS52vG`5QcR@mFAY z!tNt2Y1Ob>`$WfrkJtj35WTl30=fPps(@UhJAJ397o$c=KoUV955}0cF3$r!X{}?J z{KWOopviSf4vQYWK=*~4-02anm!ZdScU)a`?Ifh52_uUY-m;rS zdY%2WdS$Y;+yPJoBBb71Z@Q-C>ZJXJ(;s^AQ7-AWkRPk=7Qwj zvB}d+Lt*u`kW)4rGdB)ZeU)wQ8SbL_o> z8v9X;p?yxr8}NsPM*-pe*uDS0{hjH);N$ z70&_gJ%)AvPb$U;L3>Oe?0V47*l|`DL~xkpT!x4(kbrMu$tVlf~}%+^tt@&Ute8G zQa=Jx^U}Xxo?({NlmvTGYI=F?2kand<*w2n?}ns=xRcDPN@E)mN)uwO?XOa3&2ZCd zTv^?Bto)>n_TR1+K{|Z|0m_7PTUPHS;&!>y%q$3WEvN8v-^iyW1V?VTt=?_?Y&sGU zMD(*{eFUTl0Gq}&O-5eTE|-o57-uhoPY^#Zx~h1{R5^dz_ps%k2C3tqiNIE4_qRIF z%M4}H1GZ)hu2`s6X71;;C_~&O_H-vKBS40G#0l7tB%Yl_kb7^r220=Uh<{~84C^rl z%+@dIrI8_a-j|GkRB2yEy*UqTU!`AtF|S~@sAknv*ZZWLj{A}2?B~*VhZQRHOq?05 zElAWGx%{r zouvl1+|K+oEw5HQ)>7Esan@ib?iU5(p?lhe(uE3Y7d@0ya8qU|L7(h{>CCzo2UK9< z4jpQ?F1-5s^axs_>~w9MpDEo3bM+Y*^4AQ^b_I`ld!w=UDR_G@DR{ialH&BLBFM9* z{rD+YI!T{;uCJFP>=lg_#LcuMzHmjOi&5}(>r_8UIWvfZB;&DU<%M`7VcegthQfWE z?50w<^GHn}ZhpStBn^WtgZd`yzdvH>uYfJ_%4*h3DUH$n+$y9}MjvW%#lBdR#?+tL zf$PLVD_hhgKQYdux|dwPGWa<1qK)>pg|+t9;CDj3#A&?|$-LP=K{fklE+`JZXw~&5 zPf@cBXUiwjF87^Ii*3KAeS?z8M4v_|61|0C1LYBuu@6vYCB~{1atbYY1hKx{DXdh8 zly)V*D(NJs&SH<9f|O^|thDLiR5JKOi$RzEO<{q`m%M*k|8ejfD3++V>` zyaH7(;q8M+K$#t_bfs(mHKmU(!eMsQRUvih#o-ipEzJr!%6Uj#cU72wkMmJ+GT4JP zGfxD4khzvxaCDgJrZxEdXsL6KWomsZQ~jgeSwrEZq4UN1b%nRHEBlQc(l-V?C{F0? z_VYn=-jqy)g?|#PM5aP6*dpS~ZIqcduqkR`H1)biPJqo3zb^c>50RmDtXkf8K^~5% zv(aL&Yj@2c#-xOZ4u5;H=qjXD->2x5-j>wZDX-29>y8@C`tZ=jiq(;CWqkr%^Vf5a zw>o!Tz?92Sfg>r1;NQFKbTU(}e#RRVszEO+M2Ft1AT8-gti=+SQ1T7ILbD3tK_$dF zn5_oLPFUc`eHDufYd=^uA`*(I?vZCGMb&79`dgv&&uWDT;HXijp{+Lkd2CDOK&A2M zV)T>BtB`p`#4A_&J|U70C4w1lChdI>{sAA5zYICf3nHqOXNLYB zj8Z5H)k5rT=r3FW^UTjXJ(m*d;d%kGrPoq;YH*=MlPRh5ThV_$#h-}&Y)qU#GbGIG ztdz)9g>(kzUb;2s_vLz#EDrs9Eey&#{P+Ne0jQ_i>#p#qol0sOg@sv8T;&v}Ty=!k zLw#dMDNd2oB=8xD5I4G42Yy7bTJQG-^jG^h!cmm`L;eaV{oEi#n;^F_c|W6pgPeKZPKMJ zQSk5g-gMYqA5jVqrT5v_wm&)bx3?i`U#9Gyza=LRhdT8B17`o3gG9`j2E^6Ok5G}2 zFo*kvFkA6jcP(u8xAx~TluSdfWV7(jBR58rxE}O@mI9SyCb>%yl^I?VWoL)LyxdC; zyWa6aHYGnoPZcaVb>QbHc>{R^`$;EH&Bg17V}_1o37ssPYcU(Q8`k#BnQefzI9hMr z95&h5Qc+b3=Is|$xkO1{i8UGJK#M9E&QM?dr6KGm3Sn9 z>WHbeaaD_*RpFm+m{Kb1rB1(vu0Ue5wfp}92V79Rp?pla9Sm6zX zPw>#D{)beMVrgB|1>@iS{-hclx^U<<;rMPmaqN!fZN&bS;z; zh@ainE{da$ft>b&CL?*4l3BIR?Y%B+FX?uE{I7?w8vj2Qn8`DgOyRi_b49dCxs*Z% z`0p0i+&5{pLd!z^y2%@IKrVa?#BN2uIZ|>iyYeY`&^M`3qE5HqNT_j)uHf0@X=ttHj31LVM9a=JYnEo|wBr3o z9zBvv6qx^h6>;mLs%q1(Ii6M8v*npIprCfjE`590ZcJIyPtq^ihh1gYg@4qdEiAxY z9_*4+1g0xA{Vn9}UK(S)cmM>_wHz|y8{d1|Z+!;GUKTOTCIg?>1j`?ID@D1b0@S(( z{XCmxN@j+1c!xDo6^0~Ej34%MY|9`dntf|$oEtUGctDOHdy_FE14ep}F ze;#e$z591X-%2?$67j+Sbia$qHMHY9N|o(WSvz}|OaP?2+R(fQsP5~{#$Lpo08Pm9 z&iv`}4gic3gmHMS%LdbM9=MuB{D}J8PiM8@BTnoc5&)xdJhx5g&+gujMtUPUeff^e zhTe}oWCYMFn=%m={@FE|MI7Utwg@v4klP1(XS>XntAGfx?}Zel9efOs{8%p`t4sp`LoYw#U=q{^0STpR;&&JEl#mypB?4?4&0NjhIjmD2sp@DEl4>WEph?a z7W~hLyw!u4eV_?fO5>$%+5ddvJMLei`$6|5Ra`e>8p{C_Ij|mA{;y~@Rafx;QVKi} xSO(}<{iy%9y}OLZ2XG=k2PQ(TrJHKb0A#)tExW&J82nTGe*g|}P=Npd literal 0 HcmV?d00001 diff --git a/mods/MAPGEN/mcl_villages/init.lua b/mods/MAPGEN/mcl_villages/init.lua index 2b7109451..6e30f7b1c 100644 --- a/mods/MAPGEN/mcl_villages/init.lua +++ b/mods/MAPGEN/mcl_villages/init.lua @@ -93,6 +93,7 @@ if mg_name ~= "singlenode" then local x = pr1:next(0, 40) + minp.x + 19 local z = pr1:next(0, 40) + minp.z + 19 local y = minetest_get_spawn_level(x, z) + if not y then return end if y < (min or y+1) then min = y end if y > (max or y-1) then max = y end end From 9e3c2fe21e1cef5f4d5d35420a5ac91e8c39c112 Mon Sep 17 00:00:00 2001 From: kay27 Date: Tue, 4 May 2021 03:27:35 +0400 Subject: [PATCH 15/61] [mapgen] [mcl_ocean_monument] Support ice --- mods/MAPGEN/mcl_ocean_monument/init.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mods/MAPGEN/mcl_ocean_monument/init.lua b/mods/MAPGEN/mcl_ocean_monument/init.lua index 135e315bd..385e342df 100644 --- a/mods/MAPGEN/mcl_ocean_monument/init.lua +++ b/mods/MAPGEN/mcl_ocean_monument/init.lua @@ -4,7 +4,7 @@ local minetest_place_schematic = minetest.place_schematic local minetest_pos_to_string = minetest.pos_to_string local path = minetest.get_modpath("mcl_ocean_monument") .. "/schematics/ocean_monument.mts" -local water, air = "mcl_core:water_source", "air" +local water, air, ice = "mcl_core:water_source", "air", "mcl_core:ice" mcl_mapgen.register_chunk_generator(function(minp, maxp, seed) local minp = minp @@ -14,16 +14,19 @@ mcl_mapgen.register_chunk_generator(function(minp, maxp, seed) local x, z = minp.x, minp.z local pr = PseudoRandom(seed) for i = 1, pr:next(10,100) do - if mcl_mapgen_get_far_node({x=pr:next(0,79)+x, y=1, z=pr:next(0,79)+z}).name ~= water then return end + local pos = {x=pr:next(0,79)+x, y=1, z=pr:next(0,79)+z} + local node_name = mcl_mapgen_get_far_node(pos).name + if node_name ~= water and node_name ~= ice then return end end for i = 1, pr:next(10,100) do - if mcl_mapgen_get_far_node({x=pr:next(0,79)+x, y=2, z=pr:next(0,79)+z}).name ~= air then return end + local pos = {x=pr:next(0,79)+x, y=2, z=pr:next(0,79)+z} + local node_name = mcl_mapgen_get_far_node(pos).name + if node_name ~= air then return end end for i = 1, pr:next(10,100) do - if mcl_mapgen_get_far_node({x=pr:next(15,64)+x, y=pr:next(0,25)-25, z=pr:next(15,64)+z}).name ~= water then --- minetest_log("warning", "[mcl_ocean_monument] Not water at " .. minetest_pos_to_string(minp)) - return - end + local pos = {x=pr:next(15,64)+x, y=pr:next(0,25)-25, z=pr:next(15,64)+z} + local node_name = mcl_mapgen_get_far_node(pos).name + if node_name ~= water then return end end -- minetest_place_schematic(minp, path, tostring(pr:next(0,3)*90), nil, true) From 2fda0f2644ee342fea234a17a54664dc329c5a50 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 5 May 2021 14:22:50 +0000 Subject: [PATCH 16/61] [mapgen] Add true builder name of Ocean Monument into mod.conf --- mods/MAPGEN/mcl_ocean_monument/mod.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/MAPGEN/mcl_ocean_monument/mod.conf b/mods/MAPGEN/mcl_ocean_monument/mod.conf index 62648e987..945a81166 100644 --- a/mods/MAPGEN/mcl_ocean_monument/mod.conf +++ b/mods/MAPGEN/mcl_ocean_monument/mod.conf @@ -1,4 +1,4 @@ name = mcl_ocean_monument -author = Sister of epCode +author = TrashPanda description = Adds Ocean Monument, https://git.minetest.land/MineClone2/MineClone2/issues/958#issuecomment-14102 depends = mcl_mapgen, mcl_structures From 2272753652998a45f12dead96f1d4f92b35c0acf Mon Sep 17 00:00:00 2001 From: kay27 Date: Thu, 6 May 2021 00:41:20 +0400 Subject: [PATCH 17/61] [mapgen] [mcl_ocean_monument] Reorder check loops to make it work faster, add random rotation --- mods/MAPGEN/mcl_ocean_monument/init.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mods/MAPGEN/mcl_ocean_monument/init.lua b/mods/MAPGEN/mcl_ocean_monument/init.lua index 385e342df..8b34f2c6c 100644 --- a/mods/MAPGEN/mcl_ocean_monument/init.lua +++ b/mods/MAPGEN/mcl_ocean_monument/init.lua @@ -1,3 +1,6 @@ + +-- Check it: `/tp 14958,8,11370` @ world seed `1` + local mcl_mapgen_get_far_node = mcl_mapgen.get_far_node local minetest_log = minetest.log local minetest_place_schematic = minetest.place_schematic @@ -14,9 +17,9 @@ mcl_mapgen.register_chunk_generator(function(minp, maxp, seed) local x, z = minp.x, minp.z local pr = PseudoRandom(seed) for i = 1, pr:next(10,100) do - local pos = {x=pr:next(0,79)+x, y=1, z=pr:next(0,79)+z} + local pos = {x=pr:next(15,64)+x, y=pr:next(0,25)-25, z=pr:next(15,64)+z} local node_name = mcl_mapgen_get_far_node(pos).name - if node_name ~= water and node_name ~= ice then return end + if node_name ~= water then return end end for i = 1, pr:next(10,100) do local pos = {x=pr:next(0,79)+x, y=2, z=pr:next(0,79)+z} @@ -24,16 +27,15 @@ mcl_mapgen.register_chunk_generator(function(minp, maxp, seed) if node_name ~= air then return end end for i = 1, pr:next(10,100) do - local pos = {x=pr:next(15,64)+x, y=pr:next(0,25)-25, z=pr:next(15,64)+z} + local pos = {x=pr:next(0,79)+x, y=1, z=pr:next(0,79)+z} local node_name = mcl_mapgen_get_far_node(pos).name - if node_name ~= water then return end + if node_name ~= water and node_name ~= ice then return end end --- minetest_place_schematic(minp, path, tostring(pr:next(0,3)*90), nil, true) - minetest_place_schematic(minp, path, 0, nil, true) + minetest_place_schematic(minp, path, tostring(pr:next(0,3)*90), nil, true) minetest_log("action", "[mcl_ocean_monument] Placed at " .. minetest_pos_to_string(minp)) - ---- TODO: SET UP SPECIAL NODES... + ---- TODO: SET UP SOME NODES? end, mcl_mapgen.priorities.OCEAN_MONUMENT) From 135c8ece4109ccff8a5340809d22e567ea4b514e Mon Sep 17 00:00:00 2001 From: NO11 Date: Wed, 5 May 2021 21:42:11 +0000 Subject: [PATCH 18/61] Remove some helper recipes, because the ocean monument generates now --- mods/MISC/mcl_temp_helper_recipes/init.lua | 27 ---------------------- 1 file changed, 27 deletions(-) diff --git a/mods/MISC/mcl_temp_helper_recipes/init.lua b/mods/MISC/mcl_temp_helper_recipes/init.lua index ff9f541f3..3c448a465 100644 --- a/mods/MISC/mcl_temp_helper_recipes/init.lua +++ b/mods/MISC/mcl_temp_helper_recipes/init.lua @@ -8,33 +8,6 @@ minetest.register_craft({ recipe = {"mcl_core:iron_ingot", "mcl_core:stick", "group:wood", "mcl_chests:chest"}, }) -minetest.register_craft({ - output = "mcl_sponges:sponge", - recipe = { - { "mcl_farming:hay_block", "mcl_farming:hay_block", "mcl_farming:hay_block" }, - { "mcl_farming:hay_block", "mcl_core:goldblock", "mcl_farming:hay_block" }, - { "mcl_farming:hay_block", "mcl_farming:hay_block", "mcl_farming:hay_block" }, - } -}) - -minetest.register_craft({ - output = "mcl_ocean:prismarine_shard", - recipe = { - { "mcl_core:glass_cyan", }, - } -}) - -minetest.register_craft({ - type = "shapeless", - output = "mcl_ocean:prismarine_crystals", - recipe = { - "mcl_ocean:prismarine_shard", - "mcl_ocean:prismarine_shard", - "mcl_ocean:prismarine_shard", - "mcl_core:gold_ingot", - }, -}) - minetest.register_craft({ output = "mcl_armor:helmet_chain", recipe = { From ce6f5b0ee191d51a13ea7e6f8442a73e5ad527de Mon Sep 17 00:00:00 2001 From: kay27 Date: Thu, 6 May 2021 02:42:06 +0400 Subject: [PATCH 19/61] [mapgen] [mcl_ocean_monument] Generate prismarine legs up to the bottom --- mods/MAPGEN/mcl_ocean_monument/init.lua | 78 +++++++++++++++++++++---- 1 file changed, 67 insertions(+), 11 deletions(-) diff --git a/mods/MAPGEN/mcl_ocean_monument/init.lua b/mods/MAPGEN/mcl_ocean_monument/init.lua index 8b34f2c6c..97ca1fa6e 100644 --- a/mods/MAPGEN/mcl_ocean_monument/init.lua +++ b/mods/MAPGEN/mcl_ocean_monument/init.lua @@ -1,41 +1,97 @@ --- Check it: `/tp 14958,8,11370` @ world seed `1` +-- Check it: +-- seed 1, v7 mapgen +-- /teleport 14958,8,11370 local mcl_mapgen_get_far_node = mcl_mapgen.get_far_node local minetest_log = minetest.log local minetest_place_schematic = minetest.place_schematic local minetest_pos_to_string = minetest.pos_to_string +local minetest_swap_node = minetest.swap_node local path = minetest.get_modpath("mcl_ocean_monument") .. "/schematics/ocean_monument.mts" -local water, air, ice = "mcl_core:water_source", "air", "mcl_core:ice" + +local water = "mcl_core:water_source" +local air = "air" +local ice = "mcl_core:ice" + +local leg_materials = { + "mcl_ocean:prismarine_brick", + "mcl_ocean:prismarine", +} +local what_we_can_replace_by_legs = { + water, + air, + "mcl_core:water_flow", + "mcl_core:stone", +} + +local leg_search_quick_index = {} +for _, v in pairs(leg_materials) do + leg_search_quick_index[v] = true +end + +local leg_replace_quick_index = {} +for _, v in pairs(what_we_can_replace_by_legs) do + leg_replace_quick_index[v] = true +end + +local y_wanted = mcl_mapgen.OFFSET_NODES -- supposed to be -32 +local y_bottom = mcl_mapgen.overworld.min -- -62 mcl_mapgen.register_chunk_generator(function(minp, maxp, seed) local minp = minp local y = minp.y - if y ~= -32 then return end + if y ~= y_wanted then return end local x, z = minp.x, minp.z local pr = PseudoRandom(seed) - for i = 1, pr:next(10,100) do - local pos = {x=pr:next(15,64)+x, y=pr:next(0,25)-25, z=pr:next(15,64)+z} + + -- scan the ocean - it should be the ocean: + for i = 1, pr:next(10, 100) do + local pos = {x = pr:next(15, 64) + x, y = pr:next(0, 25) - 25, z = pr:next(15, 64) + z} local node_name = mcl_mapgen_get_far_node(pos).name if node_name ~= water then return end end - for i = 1, pr:next(10,100) do - local pos = {x=pr:next(0,79)+x, y=2, z=pr:next(0,79)+z} + + -- scan nodes above water level - there should be the air: + for i = 1, pr:next(10, 100) do + local pos = {x = pr:next(0, 79) + x, y = 2, z = pr:next(0,79) + z} local node_name = mcl_mapgen_get_far_node(pos).name if node_name ~= air then return end end + + -- scan ocean surface - allow only water and ice: for i = 1, pr:next(10,100) do - local pos = {x=pr:next(0,79)+x, y=1, z=pr:next(0,79)+z} + local pos = {x=pr:next(0, 79)+x, y=1, z=pr:next(0,79)+z} local node_name = mcl_mapgen_get_far_node(pos).name if node_name ~= water and node_name ~= ice then return end end - minetest_place_schematic(minp, path, tostring(pr:next(0,3)*90), nil, true) + -- random rotation: + local rotation = pr:next(0, 3) + local rotation_str = tostring(rotation * 90) + minetest_place_schematic(minp, path, rotation_str, nil, true) - minetest_log("action", "[mcl_ocean_monument] Placed at " .. minetest_pos_to_string(minp)) + -- search prismarine legs at base level and continue them up to the bottom: + for x = x, maxp.x do + for z = z, maxp.z do + local pos = {x = x, y = y, z = z} + local node_name = mcl_mapgen_get_far_node(pos).name + if leg_search_quick_index[node_name] then + local node_leg = {name = node_name} + for y = y - 1, y_bottom, -1 do + pos.y = y + local next_name = mcl_mapgen_get_far_node(pos).name + if not leg_replace_quick_index[next_name] then + break + end + minetest_swap_node(pos, node_leg) + end + end + end + end - ---- TODO: SET UP SOME NODES? + minetest_log("action", "[mcl_ocean_monument] Placed at " .. minetest_pos_to_string(minp) .. ", " .. rotation_str .. " deg.") end, mcl_mapgen.priorities.OCEAN_MONUMENT) From 3bd1a6f89ea750909086e6fb972190e466febdf4 Mon Sep 17 00:00:00 2001 From: kay27 Date: Thu, 6 May 2021 02:58:49 +0400 Subject: [PATCH 20/61] [mapgen] [mcl_ocean_monument] Fix a typo in water_flowing node name --- mods/MAPGEN/mcl_ocean_monument/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/MAPGEN/mcl_ocean_monument/init.lua b/mods/MAPGEN/mcl_ocean_monument/init.lua index 97ca1fa6e..04117d143 100644 --- a/mods/MAPGEN/mcl_ocean_monument/init.lua +++ b/mods/MAPGEN/mcl_ocean_monument/init.lua @@ -22,7 +22,7 @@ local leg_materials = { local what_we_can_replace_by_legs = { water, air, - "mcl_core:water_flow", + "mcl_core:water_flowing", "mcl_core:stone", } From 279b1b09cdbbb2f51147ed1d10f862ca0c090dfd Mon Sep 17 00:00:00 2001 From: kay27 Date: Sat, 8 May 2021 02:51:17 +0400 Subject: [PATCH 21/61] [mapgen] Add `mcl_mapgen.priorities` table --- mods/CORE/mcl_mapgen/API.md | 84 +++++++++++++++++----------- mods/CORE/mcl_mapgen/init.lua | 17 ++++-- mods/MAPGEN/mcl_biomes/init.lua | 2 +- mods/MAPGEN/mcl_dungeons/init.lua | 2 +- mods/MAPGEN/mcl_strongholds/init.lua | 2 +- mods/MAPGEN/mcl_villages/init.lua | 2 +- 6 files changed, 68 insertions(+), 41 deletions(-) diff --git a/mods/CORE/mcl_mapgen/API.md b/mods/CORE/mcl_mapgen/API.md index 364bc3205..b5afbeb4d 100644 --- a/mods/CORE/mcl_mapgen/API.md +++ b/mods/CORE/mcl_mapgen/API.md @@ -1,54 +1,74 @@ # mcl_mapgen ============ -This mod helps to avoid problems caused by Minetest's 'chunk-in-shell' feature of mapgen.cpp. -It also queues your generators to run them in proper order. +Helps to avoid problems caused by 'chunk-in-shell' feature of mapgen.cpp. +It also queues your generators to run them in proper order: - -========================================================================= ## mcl_mapgen.register_chunk_generator(chunk_callback_function, priority) ========================================================================= -UNSAFE! See below. Registers callback function to be called when current chunk generation is finished. - `callback_function`: chunk callback function definition, see below; - `priority`: order number - the less, the earlier. -### Chunk callback function definition: - `function(minp, maxp, seed)`: - `minp` & `maxp`: minimum and maximum chunk position; - `seed`: seed of this mapchunk. - - -======================================================================= -## mcl_mapgen.register_chunk_generator_lvm(callback_function, priority) -======================================================================= -UNSAFE! See below. Registers callback function to be called when current chunk generation is finished. -`vm_context` passes into callback function and should be returned back. - `callback_function`: chunk callback LVM function definition, see below; - `priority`: order number - the less, the earlier. -### Chunk callback LVM function definition: - Function MUST RETURN `vm_context`. It passes into next callback function from the queue. - `function(vm_context)`: - `vm_context` is a table which already contains some LVM data and some of them can be added in callback function: +Registers callback function to be called when current chunk generation is finished. + `callback_function`: chunk callback function definition: + `function(minp, maxp, seed)`: `minp` & `maxp`: minimum and maximum chunk position; - `seed`: seed of this mapchunk. + `seed`: seed of this mapchunk; + `priority` (optional): order number - the less, the earlier, + e.g. `mcl_mapgen.priorities.BUILDINGS` or `mcl_mapgen.priorities.LARGE_BUILDINGS` - -=================================================================== ## mcl_mapgen.register_block_generator(callback_function, priority) =================================================================== Registers callback function to be called when block (usually 16x16x16 nodes) generation is finished. `callback_function`: block callback function definition, see below; - `priority`: order number - the less, the earlier. + `priority` (optional): order number - the less, the earlier, + e.g. `mcl_mapgen.priorities.BUILDINGS` or `mcl_mapgen.priorities.LARGE_BUILDINGS` - -======================================================================= ## mcl_mapgen.register_block_generator_lvm(callback_function, priority) ======================================================================= Registers callback function to be called when block (usually 16x16x16 nodes) generation is finished. `vm_context` passes into callback function and should be returned back. `callback_function`: block callback LVM function definition, see below; - `priority`: order number - the less, the earlier. + `priority` (optional): order number - the less, the earlier, + e.g. `mcl_mapgen.priorities.BUILDINGS` or `mcl_mapgen.priorities.LARGE_BUILDINGS` +## mcl_mapgen.register_chunk_generator_lvm(callback_function, priority) +======================================================================= +UNSAFE! See https://git.minetest.land/MineClone2/MineClone2/issues/1395 +Registers callback function to be called when current chunk generation is finished. +IT IS UNSAFE! GROUND CONTENT YOU PLACE (INCLUDING WATER AND AIR) CAN BE OVERWRITTEN BY cavegen. +ALL OTHER API FUNCTIONS ARE SAFE! USE THEM PLEASE! BUT WE NEED THIS FUNCTION STILL SOMETIMES, +WHEN WE NEED TO ACCESS MAPGEN OBJECTS like `heightmap`, `biomemap`, ETC. + `callback_function`: chunk callback LVM function definition, see below; + `function(vm_context)`: + Function MUST RETURN `vm_context` back anyway! It will passed into next callback function from the queue. + `vm_context`: a table which already contains some LVM data if the fields, and some of them can be added right in callback function: + `vm`: curent voxel manipulator object itself; + `blockseed`: seed of this mapchunk; + `minp` & `maxp`: minimum and maximum chunk position; + `emin` & `emax`: minimum and maximum chunk position WITH SHELL AROUND IT; + `area`: voxel area, can be helpful to access data; + `data`: LVM buffer data array, data loads into it before the callbacks; + `write`: set it to true in yout callback functionm, if you changed `data` and want to write it; + `data2`: LVM buffer data array of `param2`, !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: + `vm_context.data2 = vm_context.data2 or vm_context.vm.get_param2_data(vm_context.lvm_param2_buffer)` + `write_param2`: set it to true in yout callback functionm, if you used `data2` and want to write it; + `lvm_param2_buffer`: static `param2` buffer pointer, used to load `data2` array; + `shadow`: set it to false to disable shadow propagation; + `heightmap`: mapgen object contanting y coordinates of ground level, + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: + `vm_context.heightmap = vm_context.heightmap or minetest.get_mapgen_object('heightmap')` + `biomemap`: mapgen object contanting biome IDs of nodes, + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: + `vm_context.biomemap = vm_context.biomemap or minetest.get_mapgen_object('biomemap')` + `heatmap`: mapgen object contanting temperature values of nodes, + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: + `vm_context.heatmap = vm_context.heatmap or minetest.get_mapgen_object('heatmap')` + `humiditymap`: mapgen object contanting humidity values of nodes, + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: + `vm_context.humiditymap = vm_context.humiditymap or minetest.get_mapgen_object('humiditymap')` + `gennotify`: mapgen object contanting mapping table of structures, see Minetest Lua API for explanation, + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: + `vm_context.gennotify = vm_context.gennotify or minetest.get_mapgen_object('gennotify')` + `priority` (optional): order number - the less, the earlier, + e.g. `mcl_mapgen.priorities.BUILDINGS` or `mcl_mapgen.priorities.LARGE_BUILDINGS` -=============================== ## mcl_mapgen.get_far_node(pos) =============================== Returns node if it is generated. Otherwise returns `{name = "ignore"}`. diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index a5982ae4e..992c93b0d 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -1,7 +1,14 @@ mcl_mapgen = {} -local priority = { - OCEAN_MONUMENT = 1000000 +local priorities = { -- mcl_mapgen.priorities... + DEFAULT = 5000, + CHORUS = 100000, + BUILDINGS = 200000, + VILLAGES = 900000, + DUNGEONS = 950000, + STRONGHOLDS = 999999, + OCEAN_MONUMENT = 1000000, + LARGE_BUILDINGS = 2000000, } local math_floor = math.floor @@ -62,7 +69,7 @@ local CS_NODES = mcl_mapgen.CS_NODES -- 80 local CS_3D = CS * CS * CS -local DEFAULT_PRIORITY = 5000 +local DEFAULT_PRIORITY = priorities.DEFAULT function mcl_mapgen.register_chunk_generator(callback_function, priority) nodes_chunk = nodes_chunk + 1 @@ -261,7 +268,7 @@ minetest.register_on_generated(function(minp, maxp, blockseed) if vm_context.write_param2 then vm:set_param2_data(data2) end - vm:calc_lighting(minp, maxp, vm_context.shadow) -- TODO: check boundaries + vm:calc_lighting(minp, maxp, vm_context.shadow or true) -- TODO: check boundaries vm:write_to_map() vm:update_liquids() end @@ -403,4 +410,4 @@ mcl_mapgen.overworld = overworld mcl_mapgen.end_ = end_ mcl_mapgen.nether = nether -mcl_mapgen.priorities = priority +mcl_mapgen.priorities = priorities diff --git a/mods/MAPGEN/mcl_biomes/init.lua b/mods/MAPGEN/mcl_biomes/init.lua index a35183c15..80975d6e4 100644 --- a/mods/MAPGEN/mcl_biomes/init.lua +++ b/mods/MAPGEN/mcl_biomes/init.lua @@ -3979,7 +3979,7 @@ if not mcl_mapgen.singlenode then minetest.after(1, mcl_end.grow_chorus_plant, realpos) end return c - end) + end, mcl_mapgen.priorities.CHORUS) end end diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index 03a5c4e07..b333f4d8a 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -413,4 +413,4 @@ function mcl_dungeons.spawn_dungeon(p1, _, pr) spawn_dungeon(p1, p2, dim, pr, true) end -mcl_mapgen.register_chunk_generator(dungeons_nodes, 999999) +mcl_mapgen.register_chunk_generator(dungeons_nodes, mcl_mapgen.priorities.DUNGEONS) diff --git a/mods/MAPGEN/mcl_strongholds/init.lua b/mods/MAPGEN/mcl_strongholds/init.lua index e4bbdb974..d4dd8a99c 100644 --- a/mods/MAPGEN/mcl_strongholds/init.lua +++ b/mods/MAPGEN/mcl_strongholds/init.lua @@ -100,4 +100,4 @@ mcl_mapgen.register_chunk_generator(function(minp, maxp, blockseed) end end end -end, 999999) +end, mcl_mapgen.priorities.STRONGHOLDS) diff --git a/mods/MAPGEN/mcl_villages/init.lua b/mods/MAPGEN/mcl_villages/init.lua index 6e30f7b1c..3c3cf3291 100644 --- a/mods/MAPGEN/mcl_villages/init.lua +++ b/mods/MAPGEN/mcl_villages/init.lua @@ -103,7 +103,7 @@ if mg_name ~= "singlenode" then if height_difference > max_height_difference then return end build_a_settlement(minp, maxp, blockseed) - end) + end, mcl_mapgen.priorities.VILLAGES) end -- manually place villages if minetest.is_creative_enabled("") then From 9d383560be76191530da4f3a03fac411c4b37d84 Mon Sep 17 00:00:00 2001 From: kay27 Date: Fri, 23 Jul 2021 01:39:10 +0400 Subject: [PATCH 22/61] Increase max_block_generate_distance --- minetest.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/minetest.conf b/minetest.conf index 223587f4d..97d1f5cd6 100644 --- a/minetest.conf +++ b/minetest.conf @@ -32,6 +32,10 @@ movement_gravity = 10.4 # humid_rivers would cause the MushroomIsland biome to appear frequently around rivers. mgvalleys_spflags = noaltitude_chill,noaltitude_dry,nohumid_rivers,vary_river_depth +# From how far blocks are generated for clients, stated in mapblocks (16 nodes). +# Probably values >10 won't work because of numerous overridings. Type: int. +max_block_generate_distance = 13 + # MCL2-specific stuff keepInventory = false From 67248afe5850ef7c6c0bacc9a365067ed9522cb2 Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 25 Jul 2021 04:34:55 +0400 Subject: [PATCH 23/61] Use new vars in mcl_debrisgen --- mods/MAPGEN/mcl_debrisgen/init.lua | 7 ++++--- mods/MAPGEN/mcl_debrisgen/mod.conf | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mods/MAPGEN/mcl_debrisgen/init.lua b/mods/MAPGEN/mcl_debrisgen/init.lua index 4e80c2504..28af327cd 100644 --- a/mods/MAPGEN/mcl_debrisgen/init.lua +++ b/mods/MAPGEN/mcl_debrisgen/init.lua @@ -11,8 +11,10 @@ local facedir = { vector.new(-1, 0, 0), } +local min, max = mcl_mapgen.nether.min, mcl_mapgen.nether.max + minetest.register_on_generated(function(minp, maxp) - if maxp.y < mcl_vars.mg_nether_min or minp.y > mcl_vars.mg_nether_max then + if maxp.y < min or minp.y > max then return end @@ -20,7 +22,7 @@ minetest.register_on_generated(function(minp, maxp) local data = vm:get_data() local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax}) - for idx in area:iter(minp.x, math.max(minp.y, mcl_vars.mg_nether_min), minp.z, maxp.x, math.min(maxp.y, mcl_vars.mg_nether_max), maxp.z) do + for idx in area:iter(minp.x, math.max(minp.y, min), minp.z, maxp.x, math.min(maxp.y, max), maxp.z) do if data[idx] == c_debris then local pos = area:position(idx) local exposed = false @@ -41,4 +43,3 @@ minetest.register_on_generated(function(minp, maxp) vm:update_liquids() vm:write_to_map() end) - diff --git a/mods/MAPGEN/mcl_debrisgen/mod.conf b/mods/MAPGEN/mcl_debrisgen/mod.conf index cc5455208..270f40f71 100644 --- a/mods/MAPGEN/mcl_debrisgen/mod.conf +++ b/mods/MAPGEN/mcl_debrisgen/mod.conf @@ -1,4 +1,4 @@ name = mcl_debrisgen author = Fleckenstein description = Make sure ancient debris is not generated exposed to air -depends = mcl_mapgen_core, mcl_nether +depends = mcl_mapgen, mcl_mapgen_core, mcl_nether From 72e88f1980f80bd52d608c5f875042fd64ac2610 Mon Sep 17 00:00:00 2001 From: kay27 Date: Thu, 5 Aug 2021 04:01:07 +0400 Subject: [PATCH 24/61] Rename mapgen API methods, fix errors --- mods/CORE/mcl_mapgen/API.md | 157 +++++++++++++----------- mods/CORE/mcl_mapgen/init.lua | 138 ++++++++++----------- mods/MAPGEN/mcl_biomes/init.lua | 10 +- mods/MAPGEN/mcl_debrisgen/init.lua | 70 +++++------ mods/MAPGEN/mcl_debrisgen/mod.conf | 2 +- mods/MAPGEN/mcl_dungeons/init.lua | 42 ++++++- mods/MAPGEN/mcl_end_island/init.lua | 2 +- mods/MAPGEN/mcl_mapgen_core/init.lua | 88 ++++++------- mods/MAPGEN/mcl_ocean_monument/init.lua | 4 +- mods/MAPGEN/mcl_strongholds/init.lua | 4 +- mods/MAPGEN/mcl_villages/init.lua | 4 +- mods/MAPGEN/tsm_railcorridors/init.lua | 2 +- 12 files changed, 270 insertions(+), 253 deletions(-) diff --git a/mods/CORE/mcl_mapgen/API.md b/mods/CORE/mcl_mapgen/API.md index b5afbeb4d..20829e183 100644 --- a/mods/CORE/mcl_mapgen/API.md +++ b/mods/CORE/mcl_mapgen/API.md @@ -1,74 +1,83 @@ -# mcl_mapgen -============ -Helps to avoid problems caused by 'chunk-in-shell' feature of mapgen.cpp. -It also queues your generators to run them in proper order: - -## mcl_mapgen.register_chunk_generator(chunk_callback_function, priority) -========================================================================= -Registers callback function to be called when current chunk generation is finished. - `callback_function`: chunk callback function definition: - `function(minp, maxp, seed)`: - `minp` & `maxp`: minimum and maximum chunk position; - `seed`: seed of this mapchunk; - `priority` (optional): order number - the less, the earlier, - e.g. `mcl_mapgen.priorities.BUILDINGS` or `mcl_mapgen.priorities.LARGE_BUILDINGS` - -## mcl_mapgen.register_block_generator(callback_function, priority) -=================================================================== -Registers callback function to be called when block (usually 16x16x16 nodes) generation is finished. - `callback_function`: block callback function definition, see below; - `priority` (optional): order number - the less, the earlier, - e.g. `mcl_mapgen.priorities.BUILDINGS` or `mcl_mapgen.priorities.LARGE_BUILDINGS` - -## mcl_mapgen.register_block_generator_lvm(callback_function, priority) -======================================================================= -Registers callback function to be called when block (usually 16x16x16 nodes) generation is finished. -`vm_context` passes into callback function and should be returned back. - `callback_function`: block callback LVM function definition, see below; - `priority` (optional): order number - the less, the earlier, - e.g. `mcl_mapgen.priorities.BUILDINGS` or `mcl_mapgen.priorities.LARGE_BUILDINGS` - -## mcl_mapgen.register_chunk_generator_lvm(callback_function, priority) -======================================================================= -UNSAFE! See https://git.minetest.land/MineClone2/MineClone2/issues/1395 -Registers callback function to be called when current chunk generation is finished. -IT IS UNSAFE! GROUND CONTENT YOU PLACE (INCLUDING WATER AND AIR) CAN BE OVERWRITTEN BY cavegen. -ALL OTHER API FUNCTIONS ARE SAFE! USE THEM PLEASE! BUT WE NEED THIS FUNCTION STILL SOMETIMES, -WHEN WE NEED TO ACCESS MAPGEN OBJECTS like `heightmap`, `biomemap`, ETC. - `callback_function`: chunk callback LVM function definition, see below; - `function(vm_context)`: - Function MUST RETURN `vm_context` back anyway! It will passed into next callback function from the queue. - `vm_context`: a table which already contains some LVM data if the fields, and some of them can be added right in callback function: - `vm`: curent voxel manipulator object itself; - `blockseed`: seed of this mapchunk; - `minp` & `maxp`: minimum and maximum chunk position; - `emin` & `emax`: minimum and maximum chunk position WITH SHELL AROUND IT; - `area`: voxel area, can be helpful to access data; - `data`: LVM buffer data array, data loads into it before the callbacks; - `write`: set it to true in yout callback functionm, if you changed `data` and want to write it; - `data2`: LVM buffer data array of `param2`, !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: - `vm_context.data2 = vm_context.data2 or vm_context.vm.get_param2_data(vm_context.lvm_param2_buffer)` - `write_param2`: set it to true in yout callback functionm, if you used `data2` and want to write it; - `lvm_param2_buffer`: static `param2` buffer pointer, used to load `data2` array; - `shadow`: set it to false to disable shadow propagation; - `heightmap`: mapgen object contanting y coordinates of ground level, - !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: - `vm_context.heightmap = vm_context.heightmap or minetest.get_mapgen_object('heightmap')` - `biomemap`: mapgen object contanting biome IDs of nodes, - !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: - `vm_context.biomemap = vm_context.biomemap or minetest.get_mapgen_object('biomemap')` - `heatmap`: mapgen object contanting temperature values of nodes, - !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: - `vm_context.heatmap = vm_context.heatmap or minetest.get_mapgen_object('heatmap')` - `humiditymap`: mapgen object contanting humidity values of nodes, - !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: - `vm_context.humiditymap = vm_context.humiditymap or minetest.get_mapgen_object('humiditymap')` - `gennotify`: mapgen object contanting mapping table of structures, see Minetest Lua API for explanation, - !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: - `vm_context.gennotify = vm_context.gennotify or minetest.get_mapgen_object('gennotify')` - `priority` (optional): order number - the less, the earlier, - e.g. `mcl_mapgen.priorities.BUILDINGS` or `mcl_mapgen.priorities.LARGE_BUILDINGS` - -## mcl_mapgen.get_far_node(pos) -=============================== -Returns node if it is generated. Otherwise returns `{name = "ignore"}`. +# mcl_mapgen +============ +Helps to avoid problems caused by 'chunk-in-shell' feature of mapgen.cpp. +It also queues your generators to run them in proper order: + +### mcl_mapgen.register_on_generated(callback_function, order_number) +For Minetest 5.4 it doesn't recommended to place blocks within callback function. +See https://git.minetest.land/MineClone2/MineClone2/issues/1395 + `callback_function`: chunk callback LVM function definition: + `function(vm_context)`: + Function MUST RETURN `vm_context` back anyway! It will passed into next callback function from the queue. + `vm_context`: a table which already contains some LVM data if the fields, and some of them can be added by you right in the callback function: + `vm`: curent voxel manipulator object itself; + `blockseed`: seed of this mapchunk; + `minp` & `maxp`: minimum and maximum chunk position; + `emin` & `emax`: minimum and maximum chunk position WITH SHELL AROUND IT; + `area`: voxel area, can be helpful to access data; + `data`: LVM buffer data array, data loads into it before the callbacks; + `write`: set it to true in yout callback functionm, if you changed `data` and want to write it; + `data2`: LVM buffer data array of `param2`, !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: + `vm_context.data2 = vm_context.data2 or vm_context.vm.get_param2_data(vm_context.lvm_param2_buffer)` + `write_param2`: set it to true in yout callback functionm, if you used `data2` and want to write it; + `lvm_param2_buffer`: static `param2` buffer pointer, used to load `data2` array; + `shadow`: set it to false to disable shadow propagation; + `heightmap`: mapgen object contanting y coordinates of ground level, + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourfels: + `vm_context.heightmap = vm_context.heightmap or minetest.get_mapgen_object('heightmap')` + `biomemap`: mapgen object contanting biome IDs of nodes, + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourfels: + `vm_context.biomemap = vm_context.biomemap or minetest.get_mapgen_object('biomemap')` + `heatmap`: mapgen object contanting temperature values of nodes, + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourfels: + `vm_context.heatmap = vm_context.heatmap or minetest.get_mapgen_object('heatmap')` + `humiditymap`: mapgen object contanting humidity values of nodes, + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourfels: + `vm_context.humiditymap = vm_context.humiditymap or minetest.get_mapgen_object('humiditymap')` + `gennotify`: mapgen object contanting mapping table of structures, see Minetest Lua API for explanation, + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourfels: + `vm_context.gennotify = vm_context.gennotify or minetest.get_mapgen_object('gennotify')` + `order_number` (optional): the less, the earlier, + e.g. `mcl_mapgen.order.BUILDINGS` or `mcl_mapgen.order.LARGE_BUILDINGS` + +### mcl_mapgen.register_mapgen(callback_function, order_number) +============================================================================== +Registers callback function to be called when current chunk generation is finished. + `callback_function`: callback function definition: + `function(minp, maxp, seed)`: + `minp` & `maxp`: minimum and maximum chunk position; + `seed`: seed of this mapchunk; + `order_number` (optional): the less, the earlier, + e.g. `mcl_mapgen.order.BUILDINGS` or `mcl_mapgen.order.LARGE_BUILDINGS` + +### mcl_mapgen.register_mapgen_block(callback_function, order_number) +======================================================================= +Registers callback function to be called when block (usually 16x16x16 nodes) generation is finished. + `callback_function`: callback function definition: + `function(minp, maxp, seed)`: + `minp` & `maxp`: minimum and maximum block position; + `seed`: seed of this mapblock; + `order_number` (optional): the less, the earlier, + e.g. `mcl_mapgen.order.BUILDINGS` or `mcl_mapgen.order.LARGE_BUILDINGS` + +### mcl_mapgen.register_mapgen_block_lvm(callback_function, order_number) +============================================================================ +Registers callback function to be called when block (usually 16x16x16 nodes) generation is finished. +`vm_context` passes into callback function and should be returned back. + `callback_function`: block callback LVM function definition, see below; + `order_number` (optional): the less, the earlier, + e.g. `mcl_mapgen.order.BUILDINGS` or `mcl_mapgen.order.LARGE_BUILDINGS` + +### mcl_mapgen.register_mapgen_lvm(callback_function, order_number) +============================================================================ + +### mcl_mapgen.get_far_node(pos) +=============================== +Returns node if it is generated. Otherwise returns `{name = "ignore"}`. + +## Constants: + +* `mcl_mapgen.EDGE_MIN`, `mcl_mapgen.EDGE_MAX` - world edges, min & max. +* `mcl_mapgen.seed`, `mcl_mapgen.name` - mapgen seed & name. +* `mcl_mapgen.v6`, `mcl_mapgen.superflat`, `mcl_mapgen.singlenode` - is mapgen v6, superflat, singlenode. +* `mcl_mapgen.normal` is mapgen normal (not superflat or singlenode). diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 992c93b0d..7e49f5d11 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -1,6 +1,6 @@ mcl_mapgen = {} -local priorities = { -- mcl_mapgen.priorities... +local order = { -- mcl_mapgen.order... DEFAULT = 5000, CHORUS = 100000, BUILDINGS = 200000, @@ -43,12 +43,13 @@ local numcmax = math_max(math_floor((mapgen_limit_max - ccfmax) / mcl_mapgen.CS_ mcl_mapgen.EDGE_MIN = central_chunk_min_pos - numcmin * mcl_mapgen.CS_NODES mcl_mapgen.EDGE_MAX = central_chunk_max_pos + numcmax * mcl_mapgen.CS_NODES -minetest_log("action", "[mcl_mapgen] World edges are: mcl_mapgen.EDGE_MIN = " .. tostring(mcl_mapgen.EDGE_MIN) .. ", mcl_mapgen.EDGE_MAX = " .. tostring(mcl_mapgen.EDGE_MAX)) +minetest_log("action", "[mcl_mapgen] World edges: mcl_mapgen.EDGE_MIN = " .. tostring(mcl_mapgen.EDGE_MIN) .. ", mcl_mapgen.EDGE_MAX = " .. tostring(mcl_mapgen.EDGE_MAX)) ------------------------------------------ -- Mapgen variables local overworld, end_, nether = {}, {}, {} -mcl_mapgen.seed = minetest.get_mapgen_setting("seed") +local seed = minetest.get_mapgen_setting("seed") +mcl_mapgen.seed = seed mcl_mapgen.name = minetest.get_mapgen_setting("mg_name") mcl_mapgen.v6 = mcl_mapgen.name == "v6" mcl_mapgen.superflat = mcl_mapgen.name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" @@ -59,9 +60,8 @@ local superflat, singlenode, normal = mcl_mapgen.superflat, mcl_mapgen.singlenod minetest_log("action", "[mcl_mapgen] Mapgen mode: " .. (normal and "normal" or (superflat and "superflat" or "singlenode"))) ------------------------------------------ -local lvm_block_queue, lvm_chunk_queue, node_block_queue, node_chunk_queue = {}, {}, {}, {} -- Generators' queues -local lvm, block, lvm_block, lvm_chunk, param2, nodes_block, nodes_chunk, safe_functions = 0, 0, 0, 0, 0, 0, 0, 0 -- Requirements: 0 means none; greater than 0 means 'required' -local lvm_buffer, lvm_param2_buffer = {}, {} -- Static buffer pointers +local queue_unsafe, queue_blocks_lvm, queue_lvm, queue_blocks, queue = {}, {}, {}, {}, {} -- Generators' queues +local lvm, block, queue_blocks_lvm_counter, lvm_chunk, param2, nodes_block, nodes_chunk, safe_functions = 0, 0, 0, 0, 0, 0, 0, 0 -- Requirements: 0 means none; greater than 0 means 'required' local BS, CS = mcl_mapgen.BS, mcl_mapgen.CS -- Mapblock size (in nodes), Mapchunk size (in blocks) local LAST_BLOCK, LAST_NODE = CS - 1, BS - 1 -- First mapblock in chunk (node in mapblock) has number 0, last has THIS number. It's for runtime optimization local offset = mcl_mapgen.OFFSET -- Central mapchunk offset (in blocks) @@ -69,59 +69,39 @@ local CS_NODES = mcl_mapgen.CS_NODES -- 80 local CS_3D = CS * CS * CS -local DEFAULT_PRIORITY = priorities.DEFAULT +local DEFAULT_ORDER = order.DEFAULT -function mcl_mapgen.register_chunk_generator(callback_function, priority) +function mcl_mapgen.register_on_generated(callback_function, order) + queue_unsafe[#queue_unsafe+1] = {i = priority or DEFAULT_ORDER, f = callback_function} + table.sort(queue_lvm, function(a, b) return (a.i <= b.i) end) +end +function mcl_mapgen.register_mapgen(callback_function, order) nodes_chunk = nodes_chunk + 1 safe_functions = safe_functions + 1 - node_chunk_queue[nodes_chunk] = {i = priority or DEFAULT_PRIORITY, f = callback_function} - table.sort(node_chunk_queue, function(a, b) return (a.i <= b.i) end) + queue[nodes_chunk] = {i = order or DEFAULT_ORDER, f = callback_function} + table.sort(queue, function(a, b) return (a.i <= b.i) end) end -function mcl_mapgen.register_chunk_generator_lvm(callback_function, priority) +function mcl_mapgen.register_mapgen_lvm(callback_function, order) lvm = lvm + 1 - lvm_chunk_queue[lvm_chunk] = {i = priority or DEFAULT_PRIORITY, f = callback_function} - table.sort(lvm_chunk_queue, function(a, b) return (a.i <= b.i) end) + lvm_chunk = lvm_chunk + 1 + safe_functions = safe_functions + 1 + queue_lvm[lvm_chunk] = {i = priority or DEFAULT_ORDER, f = callback_function} + table.sort(queue_lvm, function(a, b) return (a.i <= b.i) end) end -function mcl_mapgen.register_block_generator(callback_function, priority) +function mcl_mapgen.register_mapgen_block(callback_function, priority) block = block + 1 nodes_block = nodes_block + 1 safe_functions = safe_functions + 1 - node_block_queue[nodes_block] = {i = priority or DEFAULT_PRIORITY, f = callback_function} - table.sort(node_block_queue, function(a, b) return (a.i <= b.i) end) + queue_blocks[nodes_block] = {i = priority or DEFAULT_ORDER, f = callback_function} + table.sort(queue_blocks, function(a, b) return (a.i <= b.i) end) end -function mcl_mapgen.register_block_generator_lvm(callback_function, priority) +function mcl_mapgen.register_mapgen_block_lvm(callback_function, order) block = block + 1 lvm = lvm + 1 - lvm_block = lvm_block + 1 - lvm_block_queue[lvm_block] = {i = priority or DEFAULT_PRIORITY, f = callback_function} - table.sort(lvm_block_queue, function(a, b) return (a.i <= b.i) end) -end - -function mcl_mapgen.get_block_seed(pos, seed) - local p = pos - local x, y, z = p.x, p.y, p.z - if x<0 then x = 4294967296+x end - if y<0 then y = 4294967296+y end - if z<0 then z = 4294967296+z end - local seed = (seed or mcl_mapgen.seed or 0) % 4294967296 - return (seed + (z*38134234)%4294967296 + (y*42123)%4294967296 + (x*23)%4294967296) % 4294967296 -end - -function mcl_mapgen.get_block_seed_2(pos, seed) - local p = pos - local seed = seed or mcl_mapgen.seed or 0 - local x, y, z = p.x, p.y, p.z - if x<0 then x = 4294967296+x end - if y<0 then y = 4294967296+y end - if z<0 then z = 4294967296+z end - local n = ((1619*x)%4294967296 + (31337*y)%4294967296 + (52591*z)%4294967296 + (1013*seed)%4294967296) % 4294967296 --- n = (math_floor(n / 8192) ^ n) % 4294967296 - - local m = (n*n) % 4294967296 - m = (m*60493) % 4294967296 - m = (m+19990303) % 4294967296 - - return (n * m + 1376312589) % 4294967296 + queue_blocks_lvm_counter =queue_blocks_lvm_counter + 1 + safe_functions = safe_functions + 1 + queue_blocks_lvm[queue_blocks_lvm_counter] = {order = order or DEFAULT_ORDER, callback_function = callback_function} + table.sort(queue_blocks_lvm, function(a, b) return (a.order <= b.order) end) end local storage = minetest.get_mod_storage() @@ -132,37 +112,44 @@ minetest.register_on_shutdown(function() storage:set_string("mapgen_blocks", minetest.serialize(blocks)) end) -local vm_context-- here will be many references and flags, like: param2, light_data, heightmap, biomemap, heatmap, humiditymap, gennotify, write_lvm, write_param2, shadow +local vm_context -- here will be many references and flags, like: param2, light_data, heightmap, biomemap, heatmap, humiditymap, gennotify, write_lvm, write_param2, shadow local data, data2, area local current_blocks = {} local current_chunks = {} +local lvm_buffer, lvm_param2_buffer = {}, {} -- Static buffer pointers -minetest.register_on_generated(function(minp, maxp, blockseed) - local minp, maxp, blockseed = minp, maxp, blockseed +minetest.register_on_generated(function(minp, maxp, chunkseed) + local minp, maxp, chunkseed = minp, maxp, chunkseed local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") - minetest_log("warning", "[mcl_mapgen] New_chunk=" .. minetest_pos_to_string(minp) .. "..." .. minetest_pos_to_string(maxp) .. ", shell=" .. minetest_pos_to_string(emin) .. "..." .. minetest_pos_to_string(emax) .. ", blockseed=" .. tostring(blockseed) .. ", seed1=" .. mcl_mapgen.get_block_seed(minp) .. ", seed2=" .. mcl_mapgen.get_block_seed_2(minp)) + minetest_log("warning", "[mcl_mapgen] New_chunk=" .. minetest_pos_to_string(minp) .. "..." .. minetest_pos_to_string(maxp) .. ", shell=" .. minetest_pos_to_string(emin) .. "..." .. minetest_pos_to_string(emax) .. ", chunkseed=" .. tostring(chunkseed)) - if lvm > 0 then - vm_context = {lvm_param2_buffer = lvm_param2_buffer, vm = vm, emin = emin, emax = emax, minp = minp, maxp = maxp, blockseed = blockseed} - data = vm:get_data(lvm_buffer) - vm_context.data = data - area = VoxelArea:new({MinEdge=emin, MaxEdge=emax}) - vm_context.area = area - end + data = vm:get_data(lvm_buffer) + area = VoxelArea:new({MinEdge=emin, MaxEdge=emax}) + vm_context = { + data = data, + area = area, + lvm_param2_buffer = lvm_param2_buffer, + vm = vm, + emin = emin, + emax = emax, + minp = minp, + maxp = maxp, + chunkseed = chunkseed + } if safe_functions > 0 then local x0, y0, z0 = minp.x, minp.y, minp.z local bx0, by0, bz0 = math_floor(x0/BS), math_floor(y0/BS), math_floor(z0/BS) local bx1, by1, bz1 = bx0 + LAST_BLOCK, by0 + LAST_BLOCK, bz0 + LAST_BLOCK -- only for entire chunk check - -- Keep `blockseed` in `chunks[cx][cy][cz].seed` for further safe usage: + -- Keep `chunkseed` in `chunks[cx][cy][cz].seed` for further safe usage: local cx0, cy0, cz0 = math_floor((bx0-offset)/CS), math_floor((by0-offset)/CS), math_floor((bz0-offset)/CS) if not chunks[cx0] then chunks[cx0] = {} end if not chunks[cx0][cy0] then chunks[cx0][cy0] = {} end if not chunks[cx0][cy0][cz0] then - chunks[cx0][cy0][cz0] = {seed = blockseed, counter = 0} + chunks[cx0][cy0][cz0] = {seed = chunkseed, counter = 0} else - chunks[cx0][cy0][cz0].seed = blockseed + chunks[cx0][cy0][cz0].seed = chunkseed end local x1, y1, z1, x2, y2, z2 = emin.x, emin.y, emin.z, emax.x, emax.y, emax.z @@ -233,15 +220,16 @@ minetest.register_on_generated(function(minp, maxp, blockseed) if next(chunks[cx]) == nil then chunks[cx] = nil end end end - vm_context.seed = blockseed + box * 7 + boy * 243 + boz * 11931 - if lvm_block > 0 then - vm_context.minp, vm_content.maxp = {x=x, y=y, z=z}, {x=x+LAST_NODE, y=y+LAST_NODE, z=z+LAST_NODE} - for _, v in pairs(lvm_block_queue) do - vm_context = v.f(vm_context) + local blockseed = seed + bx * 7 + by * 243 + bz * 11931 + if queue_blocks_lvm_counter > 0 then + vm_context.blockseed = blockseed + vm_context.minp, vm_context.maxp = {x=x, y=y, z=z}, {x=x+LAST_NODE, y=y+LAST_NODE, z=z+LAST_NODE} + for _, v in pairs(queue_blocks_lvm) do + vm_context = v.callback_function(vm_context) end end if nodes_block > 0 then - current_blocks[#current_blocks+1] = { minp = {x=x, y=y, z=z}, maxp = {x=pos.x+LAST_NODE, y=pos.y+LAST_NODE, z=pos.z+LAST_NODE}, seed = seed } + current_blocks[#current_blocks+1] = { minp = {x=x, y=y, z=z}, maxp = {x=x+LAST_NODE, y=y+LAST_NODE, z=z+LAST_NODE}, seed = blockseed } end else blocks[bx][by][bz] = current_mapgen_block_writes @@ -259,7 +247,7 @@ minetest.register_on_generated(function(minp, maxp, blockseed) end if lvm > 0 then - for _, v in pairs(lvm_chunk_queue) do + for _, v in pairs(queue_lvm) do vm_context = v.f(vm_context) end if vm_context.write then @@ -279,14 +267,14 @@ minetest.register_on_generated(function(minp, maxp, blockseed) local x, y, z = bx * BS, by * BS, bz * BS local minp = {x = x, y = y, z = z} local maxp = {x = x + CS_NODES - 1, y = y + CS_NODES - 1, z = z + CS_NODES - 1} - for _, v in pairs(node_chunk_queue) do + for _, v in pairs(queue) do v.f(minp, maxp, seed) end current_chunks[i] = nil end for i, b in pairs(current_blocks) do - for _, v in pairs(node_block_queue) do + for _, v in pairs(queue_blocks) do v.f(b.minp, b.maxp, b.seed) end current_blocks[i] = nil @@ -386,11 +374,11 @@ else end if mcl_mapgen.name == "flat" then if superflat then - nether.flat_nether_floor = nether.bedrock_bottom_max + 4 - nether.flat_nether_ceiling = nether.bedrock_bottom_max + 52 + nether.flat_floor = nether.bedrock_bottom_max + 4 + nether.flat_ceiling = nether.bedrock_bottom_max + 52 else - nether.flat_nether_floor = nether.lava_max + 4 - nether.flat_nether_ceiling = nether.lava_max + 52 + nether.flat_floor = nether.lava_max + 4 + nether.flat_ceiling = nether.lava_max + 52 end end @@ -410,4 +398,4 @@ mcl_mapgen.overworld = overworld mcl_mapgen.end_ = end_ mcl_mapgen.nether = nether -mcl_mapgen.priorities = priorities +mcl_mapgen.order = order diff --git a/mods/MAPGEN/mcl_biomes/init.lua b/mods/MAPGEN/mcl_biomes/init.lua index 95b673aa2..10a5f2414 100644 --- a/mods/MAPGEN/mcl_biomes/init.lua +++ b/mods/MAPGEN/mcl_biomes/init.lua @@ -3990,15 +3990,15 @@ if not mcl_mapgen.singlenode then -- Overworld decorations for v6 are handled in mcl_mapgen_core if deco_id_chorus_plant then - mcl_mapgen.register_chunk_generator_lvm(function(c) - c.gennotify = c.gennotify or minetest.get_mapgen_object("gennotify") - local gennotify = c.gennotify + mcl_mapgen.register_mapgen_block_lvm(function(vm_context) + vm_context.gennotify = vm_context.gennotify or minetest.get_mapgen_object("gennotify") + local gennotify = vm_context.gennotify for _, pos in pairs(gennotify["decoration#"..deco_id_chorus_plant] or {}) do local realpos = { x = pos.x, y = pos.y + 1, z = pos.z } minetest.after(1, mcl_end.grow_chorus_plant, realpos) end - return c - end, mcl_mapgen.priorities.CHORUS) + return vm_context + end, mcl_mapgen.order.CHORUS) end end diff --git a/mods/MAPGEN/mcl_debrisgen/init.lua b/mods/MAPGEN/mcl_debrisgen/init.lua index 28af327cd..b2b630626 100644 --- a/mods/MAPGEN/mcl_debrisgen/init.lua +++ b/mods/MAPGEN/mcl_debrisgen/init.lua @@ -1,45 +1,33 @@ -local c_debris = minetest.get_content_id("mcl_nether:ancient_debris") -local c_netherrack = minetest.get_content_id("mcl_nether:netherrack") -local c_air = minetest.get_content_id("air") - -local facedir = { - vector.new(0, 0, 1), - vector.new(0, 1, 0), - vector.new(1, 0, 0), - vector.new(0, 0, -1), - vector.new(0, -1, 0), - vector.new(-1, 0, 0), -} +local minetest_find_nodes_in_area = minetest.find_nodes_in_area +local minetest_get_node = minetest.get_node +local minetest_set_node = minetest.set_node +local debris_name = "mcl_nether:ancient_debris" +local netherrack_name = "mcl_nether:netherrack" +local air_name = "air" local min, max = mcl_mapgen.nether.min, mcl_mapgen.nether.max -minetest.register_on_generated(function(minp, maxp) - if maxp.y < min or minp.y > max then - return - end - - local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") - local data = vm:get_data() - local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax}) - - for idx in area:iter(minp.x, math.max(minp.y, min), minp.z, maxp.x, math.min(maxp.y, max), maxp.z) do - if data[idx] == c_debris then - local pos = area:position(idx) - local exposed = false - for _, dir in pairs(facedir) do - if data[area:indexp(vector.add(pos, dir))] == c_air then - exposed = true - break - end - end - if exposed then - data[idx] = c_netherrack - end - end - end - - vm:set_data(data) - vm:calc_lighting() - vm:update_liquids() - vm:write_to_map() +mcl_mapgen.register_mapgen_block(function(minp, maxp) + local minp = minp + local minp_y = minp.y + if minp_y > max then return end + local maxp = maxp + local maxp_y = maxp.y + if maxp_y < min then return end + local nodes = minetest_find_nodes_in_area(minp, maxp, debris_name) + if nodes then + for _, pos in pairs(nodes) do + minetest.log("warning","debris found at "..minetest.pos_to_string(pos)) + local x, y, z = pos.x, pos.y, pos.z + if minetest_get_node({x = x-1, y = y, z = z}) == air_name + or minetest_get_node({x = x+1, y = y, z = z}) == air_name + or minetest_get_node({x = x, y = y-1, z = z}) == air_name + or minetest_get_node({x = x, y = y+1, z = z}) == air_name + or minetest_get_node({x = x, y = y, z = z-1}) == air_name + or minetest_get_node({x = x, y = y, z = z+1}) == air_name then + minetest_set_node(pos, netherrack_name) + minetest.log("warning","debris at "..minetest.pos_to_string(pos) .. " replaced to netherrack") + end + end + end end) diff --git a/mods/MAPGEN/mcl_debrisgen/mod.conf b/mods/MAPGEN/mcl_debrisgen/mod.conf index 270f40f71..9407fedc9 100644 --- a/mods/MAPGEN/mcl_debrisgen/mod.conf +++ b/mods/MAPGEN/mcl_debrisgen/mod.conf @@ -1,4 +1,4 @@ name = mcl_debrisgen author = Fleckenstein description = Make sure ancient debris is not generated exposed to air -depends = mcl_mapgen, mcl_mapgen_core, mcl_nether +depends = mcl_mapgen, mcl_nether diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index b333f4d8a..c4228d2cf 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -9,6 +9,7 @@ end --lua locals --minetest +local minetest_find_nodes_in_area = minetest.find_nodes_in_area local registered_nodes = minetest.registered_nodes local swap_node = minetest.swap_node local set_node = minetest.set_node @@ -64,6 +65,7 @@ local surround_vectors = { -- if calls_remaining >= 1 then return end -- local p1, _, dim, pr = param.p1, param.p2, param.dim, param.pr -- local check = not (param.dontcheck or false) +local m1, m2 = 0, 0 local function spawn_dungeon(p1, p2, dim, pr, dontcheck) local x, y, z = p1.x, p1.y, p1.z @@ -72,10 +74,40 @@ local function spawn_dungeon(p1, p2, dim, pr, dontcheck) -- Check floor and ceiling: Must be *completely* solid local y_floor = y local y_ceiling = y + dim.y + 1 - if check then for tx = x+1, x+dim.x do for tz = z+1, z+dim.z do - if not registered_nodes[get_node({x = tx, y = y_floor , z = tz}).name].walkable - or not registered_nodes[get_node({x = tx, y = y_ceiling, z = tz}).name].walkable then return false end - end end end + + if check then + local result1, result2 = true, true + local dim_x, dim_z = dim.x, dim.z + local size = dim_z*dim_x + local time1 = minetest.get_us_time() + for i=1,100 do + for tx = x+1, x+dim_x do + for tz = z+1, z+dim_z do + if not registered_nodes[get_node({x = tx, y = y_floor , z = tz}).name].walkable + or not registered_nodes[get_node({x = tx, y = y_ceiling, z = tz}).name].walkable then + result1 = false + end + end + end + end + local time2 = minetest.get_us_time() + for i=1,100 do + if #minetest_find_nodes_in_area({x=x+1,y=y_floor,z=z+1}, {x=x+dim_z,y=y_floor,z=z+dim_z}, "group:walkabke") < size + or #minetest_find_nodes_in_area({x=x+1,y=y_floor,z=z+1}, {x=x+dim_z,y=y_floor,z=z+dim_z}, "group:walkabke") < size then + result2 = false + end + end + local time3 = minetest.get_us_time() + if result1 == result2 then + local d1, d2 = time2-time1, time3-time2 + local m1 = m1 + d1 + local m2 = m2 + d2 + minetest.chat_send_all("m1 = " .. tostring(m1)) + minetest.chat_send_all("m2 = " .. tostring(m2)) + else + minetest.log("warning", "results mismatch") + end + end -- Check for air openings (2 stacked air at ground level) in wall positions local openings_counter = 0 @@ -413,4 +445,4 @@ function mcl_dungeons.spawn_dungeon(p1, _, pr) spawn_dungeon(p1, p2, dim, pr, true) end -mcl_mapgen.register_chunk_generator(dungeons_nodes, mcl_mapgen.priorities.DUNGEONS) +mcl_mapgen.register_mapgen(dungeons_nodes, mcl_mapgen.order.DUNGEONS) diff --git a/mods/MAPGEN/mcl_end_island/init.lua b/mods/MAPGEN/mcl_end_island/init.lua index 730176257..b0e5e68eb 100644 --- a/mods/MAPGEN/mcl_end_island/init.lua +++ b/mods/MAPGEN/mcl_end_island/init.lua @@ -10,7 +10,7 @@ local noisemap = PerlinNoiseMap({ local c_end_stone = minetest.get_content_id("mcl_end:end_stone") local y_offset = -2 -minetest.register_on_generated(function(minp, maxp) +mcl_mapgen.register_mapgen(function(minp, maxp) if maxp.y < (-27025 + y_offset) or minp.y > (-27000 + y_offset + 4) or maxp.x < -75 or minp.x > 75 or maxp.z < -75 or minp.z > 75 then return end diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 10ab43ae5..f306c608e 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -784,7 +784,7 @@ local function register_mgv6_decorations() persist = 0.62, }, y_min = 1, - y_max = mcl_vars.overworld_max, + y_max = mcl_mapgen.overworld.max, flags = "", }) end @@ -837,7 +837,7 @@ local function register_mgv6_decorations() persist = 0.666 }, y_min = 1, - y_max = mcl_vars.overworld_max, + y_max = mcl_mapgen.overworld.max, }) -- Melon @@ -875,7 +875,7 @@ local function register_mgv6_decorations() persist = 0.6 }, y_min = 1, - y_max = mcl_vars.overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_flowers:tallgrass", }) minetest.register_decoration({ @@ -891,7 +891,7 @@ local function register_mgv6_decorations() persist = 0.6 }, y_min = 1, - y_max = mcl_vars.overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_flowers:tallgrass", }) @@ -916,7 +916,7 @@ local function register_mgv6_decorations() }, flags = "force_placement", place_offset_y = -1, - y_min = mcl_vars.overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = 0, decoration = "mcl_ocean:seagrass_"..mat, }) @@ -936,7 +936,7 @@ local function register_mgv6_decorations() }, flags = "force_placement", place_offset_y = -1, - y_min = mcl_vars.overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = -5, decoration = "mcl_ocean:seagrass_"..mat, }) @@ -957,7 +957,7 @@ local function register_mgv6_decorations() }, flags = "force_placement", place_offset_y = -1, - y_min = mcl_vars.overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = -6, decoration = "mcl_ocean:kelp_"..mat, param2 = 16, @@ -979,7 +979,7 @@ local function register_mgv6_decorations() }, flags = "force_placement", place_offset_y = -1, - y_min = mcl_vars.overworld_min, + y_min = mcl_mapgen.overworld.min, y_max = -15, decoration = "mcl_ocean:kelp_"..mat, param2 = 32, @@ -1017,7 +1017,7 @@ local function register_mgv6_decorations() sidelen = 8, fill_ratio = 0.004, y_min = 1, - y_max = mcl_vars.overworld_max, + y_max = mcl_mapgen.overworld.max, decoration = "mcl_flowers:tallgrass", }) @@ -1120,7 +1120,7 @@ end local mg_flags = minetest.settings:get_flags("mg_flags") -- Inform other mods of dungeon setting for MCL2-style dungeons -mcl_vars.mg_dungeons = mg_flags.dungeons and not superflat +mcl_vars.mg_dungeons = mcl_mapgen.dungeons -- Disable builtin dungeons, we provide our own dungeons mg_flags.dungeons = false @@ -1191,8 +1191,8 @@ local perlin_vines, perlin_vines_fine, perlin_vines_upwards, perlin_vines_length local perlin_clay -- Generate Clay -mcl_mapgen.register_chunk_generator_lvm(function(c) - local minp, maxp, blockseed, voxelmanip_data, voxelmanip_area, lvm_used = c.minp, c.maxp, c.blockseed, c.data, c.area, c.write or false +mcl_mapgen.register_mapgen_lvm(function(c) + local minp, maxp, blockseed, voxelmanip_data, voxelmanip_area, lvm_used = c.minp, c.maxp, c.chunkseed, c.data, c.area, c.write or false -- TODO: Make clay generation reproducible for same seed. if maxp.y < -5 or minp.y > 0 then return c @@ -1799,7 +1799,7 @@ local function generate_nether_decorations(minp, maxp, seed) -- Note: Spawned *after* the fire because of light level checks special_deco(rack, function(bpos) local l = minetest.get_node_light(bpos, 0.5) - if bpos.y > mcl_vars.mg_lava_nether_max + 6 and l and l <= 12 and pr_nether:next(1,1000) <= 4 then + if bpos.y > mcl_mapgen.nether.lava_max + 6 and l and l <= 12 and pr_nether:next(1,1000) <= 4 then -- TODO: Make mushrooms appear in groups, use Perlin noise if pr_nether:next(1,2) == 1 then minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_brown"}) @@ -1823,15 +1823,15 @@ end -- Also perform some basic node replacements. local bedrock_check -if mcl_vars.mg_bedrock_is_rough then +if mcl_mapgen.bedrock_is_rough then function bedrock_check(pos, _, pr) local y = pos.y -- Bedrock layers with increasing levels of roughness, until a perfecly flat bedrock later at the bottom layer -- This code assumes a bedrock height of 5 layers. - local diff = mcl_vars.mg_bedrock_overworld_max - y -- Overworld bedrock - local ndiff1 = mcl_vars.mg_bedrock_nether_bottom_max - y -- Nether bedrock, bottom - local ndiff2 = mcl_vars.mg_bedrock_nether_top_max - y -- Nether bedrock, ceiling + local diff = mcl_mapgen.overworld.bedrock_max - y -- Overworld bedrock + local ndiff1 = mcl_mapgen.nether.bedrock_bottom_max - y -- Nether bedrock, bottom + local ndiff2 = mcl_mapgen.nether.bedrock_top_max - y -- Nether bedrock, ceiling local top if diff == 0 or ndiff1 == 0 or ndiff2 == 4 then @@ -1895,10 +1895,10 @@ local function set_layers(data, area, content_id, check, min, max, minp, maxp, l end -- Below the bedrock, generate air/void -local function basic(c) - local vm, data, emin, emax, area, minp, maxp, blockseed = c.vm, c.data, c.emin, c.emax, c.area, c.minp, c.maxp, c.blockseed - c.data2 = c.data2 or vm:get_data_param2(lvm_buffer_param2) - local data2 = c.data2 +local function basic_safe(vm_context) + local vm, data, emin, emax, area, minp, maxp, chunkseed, blockseed = vm_context.vm, vm_context.data, vm_context.emin, vm_context.emax, vm_context.area, vm_context.minp, vm_context.maxp, vm_context.chunkseed, vm_context.blockseed + vm_context.data2 = vm_context.data2 or vm:get_param2_data(lvm_param2_buffer) + local data2 = vm_context.data2 local lvm_used = false local pr = PseudoRandom(blockseed) @@ -1916,34 +1916,35 @@ local function basic(c) -- [[ THE END: mcl_mapgen.end_.min mcl_mapgen.end_.max ]] -- The Void above the End below the Realm barrier: - lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.end_.max +1, mcl_vars.mg_realm_barrier_overworld_end_min-1, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.end_.max +1, mcl_mapgen.realm_barrier_overworld_end_min-1, minp, maxp, lvm_used, pr) -- Realm barrier between the Overworld void and the End - lvm_used = set_layers(data, area, c_realm_barrier, nil, mcl_vars.mg_realm_barrier_overworld_end_min , mcl_vars.mg_realm_barrier_overworld_end_max , minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_realm_barrier, nil, mcl_mapgen.realm_barrier_overworld_end_min , mcl_mapgen.realm_barrier_overworld_end_max , minp, maxp, lvm_used, pr) -- The Void above Realm barrier below the Overworld: - lvm_used = set_layers(data, area, c_void , nil, mcl_vars.mg_realm_barrier_overworld_end_max+1, mcl_mapgen.overworld.min -1, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.realm_barrier_overworld_end_max+1, mcl_mapgen.overworld.min -1, minp, maxp, lvm_used, pr) if mg_name ~= "singlenode" then -- Bedrock - lvm_used = set_layers(data, area, c_bedrock, bedrock_check, mcl_vars.mg_bedrock_overworld_min, mcl_vars.mg_bedrock_overworld_max, minp, maxp, lvm_used, pr) - lvm_used = set_layers(data, area, c_bedrock, bedrock_check, mcl_vars.mg_bedrock_nether_bottom_min, mcl_vars.mg_bedrock_nether_bottom_max, minp, maxp, lvm_used, pr) - lvm_used = set_layers(data, area, c_bedrock, bedrock_check, mcl_vars.mg_bedrock_nether_top_min, mcl_vars.mg_bedrock_nether_top_max, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_bedrock, bedrock_check, mcl_mapgen.overworld.bedrock_min, mcl_mapgen.overworld.bedrock_max, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_bedrock, bedrock_check, mcl_mapgen.nether.bedrock_bottom_min, mcl_mapgen.nether.bedrock_bottom_max, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_bedrock, bedrock_check, mcl_mapgen.nether.bedrock_top_min, mcl_mapgen.nether.bedrock_top_max, minp, maxp, lvm_used, pr) -- Flat Nether if mg_name == "flat" then - lvm_used = set_layers(data, area, c_air, nil, mcl_vars.mg_flat_nether_floor, mcl_vars.mg_flat_nether_ceiling, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_air, nil, mcl_mapgen.nether.flat_floor, mcl_mapgen.nether.flat_ceiling, minp, maxp, lvm_used, pr) end -- Big lava seas by replacing air below a certain height - if mcl_vars.mg_lava then + if mcl_mapgen.lava then lvm_used = set_layers(data, area, c_lava, c_air, mcl_mapgen.overworld.min, mcl_mapgen.overworld.lava_max, minp, maxp, lvm_used, pr) - lvm_used = set_layers(data, area, c_nether_lava, c_air, mcl_mapgen.nether.min, mcl_vars.mg_lava_nether_max, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_nether_lava, c_air, mcl_mapgen.nether.min, mcl_mapgen.nether.lava_max, minp, maxp, lvm_used, pr) end -- Clay, vines, cocoas - lvm_used = generate_clay(minp, maxp, blockseed, data, area, lvm_used) + -- lvm_used = generate_clay(minp, maxp, chunkseed, data, area, lvm_used) - c.biomemap = c.biomemap or minetest.get_mapgen_object("biomemap") + vm_context.biomemap = vm_context.biomemap or minetest.get_mapgen_object("biomemap") + local biomemap = vm_context.biomemap lvm_used = generate_tree_decorations(minp, maxp, blockseed, data, data2, area, biomemap, lvm_used, pr) @@ -2061,18 +2062,18 @@ local function basic(c) end -- Obsidian spawn platform - if minp.y <= mcl_vars.mg_end_platform_pos.y and maxp.y >= mcl_vars.mg_end_platform_pos.y and - minp.x <= mcl_vars.mg_end_platform_pos.x and maxp.x >= mcl_vars.mg_end_platform_pos.z and - minp.z <= mcl_vars.mg_end_platform_pos.z and maxp.z >= mcl_vars.mg_end_platform_pos.z then + if minp.y <= mcl_mapgen.end_.platform_pos.y and maxp.y >= mcl_mapgen.end_.platform_pos.y and + minp.x <= mcl_mapgen.end_.platform_pos.x and maxp.x >= mcl_mapgen.end_.platform_pos.z and + minp.z <= mcl_mapgen.end_.platform_pos.z and maxp.z >= mcl_mapgen.end_.platform_pos.z then - --local pos1 = {x = math.max(minp.x, mcl_vars.mg_end_platform_pos.x-2), y = math.max(minp.y, mcl_vars.mg_end_platform_pos.y), z = math.max(minp.z, mcl_vars.mg_end_platform_pos.z-2)} - --local pos2 = {x = math.min(maxp.x, mcl_vars.mg_end_platform_pos.x+2), y = math.min(maxp.y, mcl_vars.mg_end_platform_pos.y+2), z = math.min(maxp.z, mcl_vars.mg_end_platform_pos.z+2)} + --local pos1 = {x = math.max(minp.x, mcl_mapgen.end_.platform_pos.x-2), y = math.max(minp.y, mcl_mapgen.end_.platform_pos.y), z = math.max(minp.z, mcl_mapgen.end_.platform_pos.z-2)} + --local pos2 = {x = math.min(maxp.x, mcl_mapgen.end_.platform_pos.x+2), y = math.min(maxp.y, mcl_mapgen.end_.platform_pos.y+2), z = math.min(maxp.z, mcl_mapgen.end_.platform_pos.z+2)} - for x=math.max(minp.x, mcl_vars.mg_end_platform_pos.x-2), math.min(maxp.x, mcl_vars.mg_end_platform_pos.x+2) do - for z=math.max(minp.z, mcl_vars.mg_end_platform_pos.z-2), math.min(maxp.z, mcl_vars.mg_end_platform_pos.z+2) do - for y=math.max(minp.y, mcl_vars.mg_end_platform_pos.y), math.min(maxp.y, mcl_vars.mg_end_platform_pos.y+2) do + for x=math.max(minp.x, mcl_mapgen.end_.platform_pos.x-2), math.min(maxp.x, mcl_mapgen.end_.platform_pos.x+2) do + for z=math.max(minp.z, mcl_mapgen.end_.platform_pos.z-2), math.min(maxp.z, mcl_mapgen.end_.platform_pos.z+2) do + for y=math.max(minp.y, mcl_mapgen.end_.platform_pos.y), math.min(maxp.y, mcl_mapgen.end_.platform_pos.y+2) do local p_pos = area:index(x, y, z) - if y == mcl_vars.mg_end_platform_pos.y then + if y == mcl_mapgen.end_.platform_pos.y then data[p_pos] = c_obsidian else data[p_pos] = c_air @@ -2104,8 +2105,7 @@ local function basic(c) generate_structures(minp, maxp, blockseed, biomemap) end - return lvm_used, shadow + return vm_context --, lvm_used, shadow end -mcl_mapgen.register_chunk_generator_lvm(basic, 1) - +mcl_mapgen.register_mapgen_block_lvm(basic_safe, 1) diff --git a/mods/MAPGEN/mcl_ocean_monument/init.lua b/mods/MAPGEN/mcl_ocean_monument/init.lua index 04117d143..fffa6f6b0 100644 --- a/mods/MAPGEN/mcl_ocean_monument/init.lua +++ b/mods/MAPGEN/mcl_ocean_monument/init.lua @@ -39,7 +39,7 @@ end local y_wanted = mcl_mapgen.OFFSET_NODES -- supposed to be -32 local y_bottom = mcl_mapgen.overworld.min -- -62 -mcl_mapgen.register_chunk_generator(function(minp, maxp, seed) +mcl_mapgen.register_mapgen(function(minp, maxp, seed) local minp = minp local y = minp.y if y ~= y_wanted then return end @@ -94,4 +94,4 @@ mcl_mapgen.register_chunk_generator(function(minp, maxp, seed) minetest_log("action", "[mcl_ocean_monument] Placed at " .. minetest_pos_to_string(minp) .. ", " .. rotation_str .. " deg.") -end, mcl_mapgen.priorities.OCEAN_MONUMENT) +end, mcl_mapgen.order.OCEAN_MONUMENT) diff --git a/mods/MAPGEN/mcl_strongholds/init.lua b/mods/MAPGEN/mcl_strongholds/init.lua index 26ab031af..db48a93ae 100644 --- a/mods/MAPGEN/mcl_strongholds/init.lua +++ b/mods/MAPGEN/mcl_strongholds/init.lua @@ -68,7 +68,7 @@ end init_strongholds() -- Stronghold generation for register_on_generated. -mcl_mapgen.register_chunk_generator(function(minp, maxp, blockseed) +mcl_mapgen.register_mapgen(function(minp, maxp, blockseed) local pr = PseudoRandom(blockseed) for s=1, #strongholds do if not strongholds[s].generated then @@ -100,4 +100,4 @@ mcl_mapgen.register_chunk_generator(function(minp, maxp, blockseed) end end end -end, mcl_mapgen.priorities.STRONGHOLDS) +end, mcl_mapgen.order.STRONGHOLDS) diff --git a/mods/MAPGEN/mcl_villages/init.lua b/mods/MAPGEN/mcl_villages/init.lua index 233e5a5ac..47ca91f2e 100644 --- a/mods/MAPGEN/mcl_villages/init.lua +++ b/mods/MAPGEN/mcl_villages/init.lua @@ -75,7 +75,7 @@ end -- Disable natural generation in singlenode. local mg_name = minetest.get_mapgen_setting("mg_name") if mg_name ~= "singlenode" then - mcl_mapgen.register_chunk_generator(function(minp, maxp, blockseed) + mcl_mapgen.register_mapgen(function(minp, maxp, blockseed) -- local str1 = (maxp.y >= 0 and blockseed % 77 == 17) and "YES" or "no" -- minetest.log("action","[mcl_villages] " .. str1 .. ": minp=" .. minetest.pos_to_string(minp) .. ", maxp=" .. minetest.pos_to_string(maxp) .. ", blockseed=" .. tostring(blockseed)) -- don't build settlement underground @@ -103,7 +103,7 @@ if mg_name ~= "singlenode" then if height_difference > max_height_difference then return end build_a_settlement(minp, maxp, blockseed) - end, mcl_mapgen.priorities.VILLAGES) + end, mcl_mapgen.order.VILLAGES) end -- manually place villages if minetest.is_creative_enabled("") then diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index 34bd455e3..654a05672 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -1092,7 +1092,7 @@ local function create_corridor_system(main_cave_coords) end -- The rail corridor algorithm starts here -mcl_mapgen.register_chunk_generator(function(minp, maxp, blockseed, _pr) +mcl_mapgen.register_mapgen(function(minp, maxp, blockseed) -- We re-init the randomizer for every mapchunk as we start generating in the middle of each mapchunk. -- We can't use the mapgen seed as this would make the algorithm depending on the order the mapchunk generate. InitRandomizer(blockseed) From 6c1d30a13075152d1e0b5afd35b71fef8fd43bb0 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 5 Jan 2022 06:43:16 +0400 Subject: [PATCH 25/61] Polish new mapgen stuff --- mods/CORE/mcl_mapgen/API.md | 88 +++++++----- mods/CORE/mcl_mapgen/init.lua | 133 +++++++++++++----- mods/CORE/mcl_mapgen/mod.conf | 2 +- .../api/mob_functions/environment.lua | 16 +-- mods/MAPGEN/mcl_biomes/init.lua | 3 +- mods/MAPGEN/mcl_mapgen_core/init.lua | 24 +--- 6 files changed, 164 insertions(+), 102 deletions(-) diff --git a/mods/CORE/mcl_mapgen/API.md b/mods/CORE/mcl_mapgen/API.md index 20829e183..75307f321 100644 --- a/mods/CORE/mcl_mapgen/API.md +++ b/mods/CORE/mcl_mapgen/API.md @@ -3,77 +3,95 @@ Helps to avoid problems caused by 'chunk-in-shell' feature of mapgen.cpp. It also queues your generators to run them in proper order: -### mcl_mapgen.register_on_generated(callback_function, order_number) -For Minetest 5.4 it doesn't recommended to place blocks within callback function. +### mcl_mapgen.register_on_generated(lvm_callback_function, order_number) +========================================================================= +Replacement of engine API function `minetest.register_on_generated(function(minp, maxp, blockseed))` +It is still unsafe. Cavegen part can and will overwrite outer 1-block layer of the chunk which is expected to be generated. +Nodes marked as `is_ground_content` could be overwritten. Air and water are usually 'ground content' too. +For Minetest 5.4 it doesn't recommended to place blocks within lvm callback function. See https://git.minetest.land/MineClone2/MineClone2/issues/1395 - `callback_function`: chunk callback LVM function definition: + `lvm_callback_function`: chunk callback LVM function definition: `function(vm_context)`: - Function MUST RETURN `vm_context` back anyway! It will passed into next callback function from the queue. - `vm_context`: a table which already contains some LVM data if the fields, and some of them can be added by you right in the callback function: + Function MUST RETURN `vm_context` back anyway! It will passed into next lvm callback function from the queue. + `vm_context`: a table which already contains some LVM data as the fields, and some of them can be added in your lvm callback function: `vm`: curent voxel manipulator object itself; `blockseed`: seed of this mapchunk; `minp` & `maxp`: minimum and maximum chunk position; `emin` & `emax`: minimum and maximum chunk position WITH SHELL AROUND IT; `area`: voxel area, can be helpful to access data; `data`: LVM buffer data array, data loads into it before the callbacks; - `write`: set it to true in yout callback functionm, if you changed `data` and want to write it; - `data2`: LVM buffer data array of `param2`, !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourfels: + `write`: set it to true in your lvm callback functionm, if you changed `data` and want to write it; + `data2`: LVM buffer data array of `param2`, !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourself: `vm_context.data2 = vm_context.data2 or vm_context.vm.get_param2_data(vm_context.lvm_param2_buffer)` - `write_param2`: set it to true in yout callback functionm, if you used `data2` and want to write it; + `write_param2`: set it to true in your lvm callback function, if you used `data2` and want to write it; + `light`: LVM buffer data array of light, !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourself: + `vm_context.light = vm_context.light or vm_context.vm.get_light2_data(vm_context.lvm_light_buffer)` + `write_light`: set it to true in your lvm callback function, if you used `light` and want to write it; `lvm_param2_buffer`: static `param2` buffer pointer, used to load `data2` array; `shadow`: set it to false to disable shadow propagation; `heightmap`: mapgen object contanting y coordinates of ground level, - !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourfels: + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourself: `vm_context.heightmap = vm_context.heightmap or minetest.get_mapgen_object('heightmap')` `biomemap`: mapgen object contanting biome IDs of nodes, - !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourfels: + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourself: `vm_context.biomemap = vm_context.biomemap or minetest.get_mapgen_object('biomemap')` `heatmap`: mapgen object contanting temperature values of nodes, - !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourfels: + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourself: `vm_context.heatmap = vm_context.heatmap or minetest.get_mapgen_object('heatmap')` `humiditymap`: mapgen object contanting humidity values of nodes, - !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourfels: + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourself: `vm_context.humiditymap = vm_context.humiditymap or minetest.get_mapgen_object('humiditymap')` `gennotify`: mapgen object contanting mapping table of structures, see Minetest Lua API for explanation, - !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourfels: + !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourself: `vm_context.gennotify = vm_context.gennotify or minetest.get_mapgen_object('gennotify')` `order_number` (optional): the less, the earlier, e.g. `mcl_mapgen.order.BUILDINGS` or `mcl_mapgen.order.LARGE_BUILDINGS` -### mcl_mapgen.register_mapgen(callback_function, order_number) -============================================================================== -Registers callback function to be called when current chunk generation is finished. - `callback_function`: callback function definition: - `function(minp, maxp, seed)`: - `minp` & `maxp`: minimum and maximum chunk position; - `seed`: seed of this mapchunk; +### mcl_mapgen.register_mapgen_block_lvm(lvm_callback_function, order_number) +============================================================================= +Registers lvm callback function to be called when current block (usually 16x16x16 nodes) generation is REALLY 100% finished. +`vm_context` passes into lvm callback function and should always be returned back. + `lvm_callback_function`: the block callback LVM function definition - same as for chunks - see definition example above; `order_number` (optional): the less, the earlier, e.g. `mcl_mapgen.order.BUILDINGS` or `mcl_mapgen.order.LARGE_BUILDINGS` -### mcl_mapgen.register_mapgen_block(callback_function, order_number) -======================================================================= -Registers callback function to be called when block (usually 16x16x16 nodes) generation is finished. - `callback_function`: callback function definition: +### mcl_mapgen.register_mapgen_block(node_callback_function, order_number) +========================================================================== +Registers node_callback function to be called when current block (usually 16x16x16 nodes) generation is REALLY 100% finished. + `node_callback_function`: node callback function definition: `function(minp, maxp, seed)`: `minp` & `maxp`: minimum and maximum block position; `seed`: seed of this mapblock; `order_number` (optional): the less, the earlier, e.g. `mcl_mapgen.order.BUILDINGS` or `mcl_mapgen.order.LARGE_BUILDINGS` -### mcl_mapgen.register_mapgen_block_lvm(callback_function, order_number) -============================================================================ -Registers callback function to be called when block (usually 16x16x16 nodes) generation is finished. -`vm_context` passes into callback function and should be returned back. - `callback_function`: block callback LVM function definition, see below; - `order_number` (optional): the less, the earlier, - e.g. `mcl_mapgen.order.BUILDINGS` or `mcl_mapgen.order.LARGE_BUILDINGS` +### mcl_mapgen.register_mapgen(callback_function, order_number) +==================================================================== +Registers callback function to be called when current chunk generation is REALLY 100% finished. +For LVM it's the most frustrating function from this mod. +It can't provide you access to mapgen objects. They are probably gone long ago. +Don't use it for accessing mapgen objects please. +To use VM you have to run `vm_context.vm = minetest.get_voxel_manip(vm_context.emin, vm_context.emax)`. +Set + `callback_function`: callback function definition: + `function(minp, maxp, seed, vm_context)`: + `minp` & `maxp`: minimum and maximum block position; + `seed`: seed of this mapblock; + `vm_context`: a table - see description above. + `order_number` (optional): the less, the earlier. -### mcl_mapgen.register_mapgen_lvm(callback_function, order_number) -============================================================================ +### mcl_mapgen.register_mapgen_lvm(lvm_callback_function, order_number) +======================================================================= +Registers lvm callback function to be called when current chunk generation is REALLY 100% finished. +It's the most frustrating function from this mod. It can't provide you access to mapgen objects. They are probably gone long ago. +Don't use it for accessing mapgen objects please. +`vm_context` passes into lvm callback function and should always be returned back. + `lvm_callback_function`: the block callback LVM function definition - same as above; + `order_number` (optional): the less, the earlier. ### mcl_mapgen.get_far_node(pos) -=============================== -Returns node if it is generated. Otherwise returns `{name = "ignore"}`. +================================ +Returns node if it is generated, otherwise returns `{name = "ignore"}`. ## Constants: diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 7e49f5d11..d2224075b 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -44,7 +44,7 @@ mcl_mapgen.EDGE_MIN = central_chunk_min_pos - numcmin * mcl_mapgen.CS_NODES mcl_mapgen.EDGE_MAX = central_chunk_max_pos + numcmax * mcl_mapgen.CS_NODES minetest_log("action", "[mcl_mapgen] World edges: mcl_mapgen.EDGE_MIN = " .. tostring(mcl_mapgen.EDGE_MIN) .. ", mcl_mapgen.EDGE_MAX = " .. tostring(mcl_mapgen.EDGE_MAX)) ------------------------------------------- +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Mapgen variables local overworld, end_, nether = {}, {}, {} @@ -58,10 +58,24 @@ mcl_mapgen.normal = not mcl_mapgen.superflat and not mcl_mapgen.singlenode local superflat, singlenode, normal = mcl_mapgen.superflat, mcl_mapgen.singlenode, mcl_mapgen.normal minetest_log("action", "[mcl_mapgen] Mapgen mode: " .. (normal and "normal" or (superflat and "superflat" or "singlenode"))) ------------------------------------------- +---------------------------------------------------------------------------------------------------------------------------- + +-- Generator queues +local queue_unsafe_engine = {} +local queue_chunks_nodes = {} +local queue_chunks_lvm = {} +local queue_blocks_nodes = {} +local queue_blocks_lvm = {} + +-- Requirements. 0 means 'none', greater than 0 means 'required' +local block = 0 +local queue_blocks_lvm_counter = 0 +local lvm_chunk = 0 +local param2 = 0 +local nodes_block = 0 +local nodes_chunk = 0 +local safe_functions = 0 -local queue_unsafe, queue_blocks_lvm, queue_lvm, queue_blocks, queue = {}, {}, {}, {}, {} -- Generators' queues -local lvm, block, queue_blocks_lvm_counter, lvm_chunk, param2, nodes_block, nodes_chunk, safe_functions = 0, 0, 0, 0, 0, 0, 0, 0 -- Requirements: 0 means none; greater than 0 means 'required' local BS, CS = mcl_mapgen.BS, mcl_mapgen.CS -- Mapblock size (in nodes), Mapchunk size (in blocks) local LAST_BLOCK, LAST_NODE = CS - 1, BS - 1 -- First mapblock in chunk (node in mapblock) has number 0, last has THIS number. It's for runtime optimization local offset = mcl_mapgen.OFFSET -- Central mapchunk offset (in blocks) @@ -72,33 +86,31 @@ local CS_3D = CS * CS * CS local DEFAULT_ORDER = order.DEFAULT function mcl_mapgen.register_on_generated(callback_function, order) - queue_unsafe[#queue_unsafe+1] = {i = priority or DEFAULT_ORDER, f = callback_function} - table.sort(queue_lvm, function(a, b) return (a.i <= b.i) end) + queue_unsafe_engine[#queue_unsafe_engine+1] = {i = priority or DEFAULT_ORDER, f = callback_function} + table.sort(queue_unsafe_engine, function(a, b) return (a.i <= b.i) end) end function mcl_mapgen.register_mapgen(callback_function, order) nodes_chunk = nodes_chunk + 1 safe_functions = safe_functions + 1 - queue[nodes_chunk] = {i = order or DEFAULT_ORDER, f = callback_function} - table.sort(queue, function(a, b) return (a.i <= b.i) end) + queue_chunks_nodes[nodes_chunk] = {i = order or DEFAULT_ORDER, f = callback_function} + table.sort(queue_chunks_nodes, function(a, b) return (a.i <= b.i) end) end function mcl_mapgen.register_mapgen_lvm(callback_function, order) - lvm = lvm + 1 lvm_chunk = lvm_chunk + 1 safe_functions = safe_functions + 1 - queue_lvm[lvm_chunk] = {i = priority or DEFAULT_ORDER, f = callback_function} - table.sort(queue_lvm, function(a, b) return (a.i <= b.i) end) + queue_chunks_lvm[lvm_chunk] = {i = priority or DEFAULT_ORDER, f = callback_function} + table.sort(queue_chunks_lvm, function(a, b) return (a.i <= b.i) end) end function mcl_mapgen.register_mapgen_block(callback_function, priority) block = block + 1 nodes_block = nodes_block + 1 safe_functions = safe_functions + 1 - queue_blocks[nodes_block] = {i = priority or DEFAULT_ORDER, f = callback_function} - table.sort(queue_blocks, function(a, b) return (a.i <= b.i) end) + queue_blocks_nodes[nodes_block] = {i = priority or DEFAULT_ORDER, f = callback_function} + table.sort(queue_blocks_nodes, function(a, b) return (a.i <= b.i) end) end function mcl_mapgen.register_mapgen_block_lvm(callback_function, order) block = block + 1 - lvm = lvm + 1 - queue_blocks_lvm_counter =queue_blocks_lvm_counter + 1 + queue_blocks_lvm_counter = queue_blocks_lvm_counter + 1 safe_functions = safe_functions + 1 queue_blocks_lvm[queue_blocks_lvm_counter] = {order = order or DEFAULT_ORDER, callback_function = callback_function} table.sort(queue_blocks_lvm, function(a, b) return (a.order <= b.order) end) @@ -113,10 +125,10 @@ minetest.register_on_shutdown(function() end) local vm_context -- here will be many references and flags, like: param2, light_data, heightmap, biomemap, heatmap, humiditymap, gennotify, write_lvm, write_param2, shadow -local data, data2, area +local data, data2, light, area local current_blocks = {} local current_chunks = {} -local lvm_buffer, lvm_param2_buffer = {}, {} -- Static buffer pointers +local lvm_buffer, lvm_param2_buffer, lvm_light_buffer = {}, {}, {} -- Static buffer pointers minetest.register_on_generated(function(minp, maxp, chunkseed) local minp, maxp, chunkseed = minp, maxp, chunkseed @@ -126,15 +138,19 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) data = vm:get_data(lvm_buffer) area = VoxelArea:new({MinEdge=emin, MaxEdge=emax}) vm_context = { - data = data, - area = area, + data = data, + data2 = data2, + light = light, + area = area, + lvm_buffer = lvm_buffer, lvm_param2_buffer = lvm_param2_buffer, - vm = vm, - emin = emin, - emax = emax, - minp = minp, - maxp = maxp, - chunkseed = chunkseed + lvm_light_buffer = lvm_light_buffer, + vm = vm, + emin = emin, + emax = emax, + minp = minp, + maxp = maxp, + chunkseed = chunkseed, } if safe_functions > 0 then @@ -163,7 +179,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) box = block_pos_offset_removed % CS if not blocks[bx] then blocks[bx]={} end - -- We don't know how many calls, including this one, will overwrite this block's content! + -- We don't know how many calls, including this one, will overwrite this block content! -- Start calculating it with `total_mapgen_block_writes_through_x` variable. -- It can be `8 or less`, if we (speaking of `x` axis) are on chunk edge now, -- or it can be `4 or less` - if we are in the middle of the chunk by `x` axis: @@ -197,7 +213,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) local total_mapgen_block_writes = (boz > 0 and boz < LAST_BLOCK) and math_floor(total_mapgen_block_writes_through_y / 2) or total_mapgen_block_writes_through_y - -- Get current number of writes from the table, or just set it to 1, if accessed first time: + -- Get current number of writes from the table, or just set it to 1, if accessing first time: local current_mapgen_block_writes = blocks[bx][by][bz] and (blocks[bx][by][bz] + 1) or 1 @@ -246,8 +262,8 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) end end - if lvm > 0 then - for _, v in pairs(queue_lvm) do + if #queue_unsafe_engine > 0 then + for _, v in pairs(queue_unsafe_engine) do vm_context = v.f(vm_context) end if vm_context.write then @@ -256,9 +272,14 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) if vm_context.write_param2 then vm:set_param2_data(data2) end - vm:calc_lighting(minp, maxp, vm_context.shadow or true) -- TODO: check boundaries - vm:write_to_map() - vm:update_liquids() + if vm_context.write_light then + vm:set_light_data(light) + end + if vm_context.write or vm_context.write_param2 or vm_context.write_light then + vm:calc_lighting(minp, maxp, vm_context.shadow or true) -- TODO: check boundaries + vm:write_to_map() + vm:update_liquids() + end end for i, b in pairs(current_chunks) do @@ -267,14 +288,46 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) local x, y, z = bx * BS, by * BS, bz * BS local minp = {x = x, y = y, z = z} local maxp = {x = x + CS_NODES - 1, y = y + CS_NODES - 1, z = z + CS_NODES - 1} - for _, v in pairs(queue) do - v.f(minp, maxp, seed) + area = VoxelArea:new({MinEdge=minp, MaxEdge=maxp}) + vm_context = { + data = data, + data2 = data2, + light = light, + area = area, + lvm_buffer = lvm_buffer, + lvm_param2_buffer = lvm_param2_buffer, + lvm_light_buffer = lvm_light_buffer, + emin = minp, + emax = maxp, + minp = minp, + maxp = maxp, + chunkseed = seed, + } + for _, v in pairs(queue_chunks_lvm) do + v.f(vm_context) + end + for _, v in pairs(queue_chunks_nodes) do + v.f(minp, maxp, seed, vm_context) + end + if vm_context.write or vm_context.write_param2 or vm_context.write_light then + if vm_context.write then + vm:set_data(data) + end + if vm_context.write_param2 then + vm:set_param2_data(data2) + end + if vm_context.write_light then + vm:set_light_data(light) + end + vm:calc_lighting(minp, maxp, vm_context.shadow or true) + vm:write_to_map() + vm:update_liquids() end current_chunks[i] = nil end for i, b in pairs(current_blocks) do - for _, v in pairs(queue_blocks) do + for _, v in pairs(queue_blocks_nodes) do v.f(b.minp, b.maxp, b.seed) end current_blocks[i] = nil @@ -399,3 +452,13 @@ mcl_mapgen.end_ = end_ mcl_mapgen.nether = nether mcl_mapgen.order = order + +function mcl_mapgen.get_voxel_manip(vm_context) + if vm_context.vm then + return vm + end + vm_context.vm = minetest.get_voxel_manip(vm_context.emin, vm_context.emax) + vm_context.emin, vm_context.emax = vm_context.vm:read_from_map(vm_context.emin, vm_context.emax) + vm_context.area = VoxelArea:new({MinEdge=vm_context.emin, MaxEdge=vm_context.emax}) + return vm_context.vm +end diff --git a/mods/CORE/mcl_mapgen/mod.conf b/mods/CORE/mcl_mapgen/mod.conf index 4f896b3cf..76b4a5c93 100644 --- a/mods/CORE/mcl_mapgen/mod.conf +++ b/mods/CORE/mcl_mapgen/mod.conf @@ -1,4 +1,4 @@ name = mcl_mapgen author = kay27 -description = MineClone 2 MapGen Basic Stuff +description = MineClone 2/5 MapGen Basic Stuff depends = mcl_init diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua index 5c431135e..847a4e0c7 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua @@ -175,16 +175,16 @@ end -- check if within physical map limits (-30911 to 30927) -- within_limits, wmin, wmax = nil, -30913, 30928 mobs.within_limits = function(pos, radius) - local wmin, wmax - if mcl_vars then - if mcl_vars.mapgen_edge_min and mcl_vars.mapgen_edge_max then - wmin, wmax = mcl_vars.mapgen_edge_min, mcl_vars.mapgen_edge_max + local wmin, wmax + if mcl_mapgen then + if mcl_mapgen.EDGE_MIN and mcl_mapgen.EDGE_MAX then + wmin, wmax = mcl_mapgen.EDGE_MIN, mcl_mapgen.EDGE_MAX + return pos + and (pos.x - radius) > wmin and (pos.x + radius) < wmax + and (pos.y - radius) > wmin and (pos.y + radius) < wmax + and (pos.z - radius) > wmin and (pos.z + radius) < wmax end end - return pos - and (pos.x - radius) > wmin and (pos.x + radius) < wmax - and (pos.y - radius) > wmin and (pos.y + radius) < wmax - and (pos.z - radius) > wmin and (pos.z + radius) < wmax end -- get node but use fallback for nil or unknown diff --git a/mods/MAPGEN/mcl_biomes/init.lua b/mods/MAPGEN/mcl_biomes/init.lua index d9bb1fff1..56a3cfe11 100644 --- a/mods/MAPGEN/mcl_biomes/init.lua +++ b/mods/MAPGEN/mcl_biomes/init.lua @@ -3995,7 +3995,8 @@ if not mcl_mapgen.singlenode then local gennotify = vm_context.gennotify for _, pos in pairs(gennotify["decoration#"..deco_id_chorus_plant] or {}) do local realpos = { x = pos.x, y = pos.y + 1, z = pos.z } - minetest.after(1, mcl_end.grow_chorus_plant, realpos) + local pr = PseudoRandom(vm_context.blockseed) + minetest.after(1, mcl_end.grow_chorus_plant, realpos, false, pr) end return vm_context end, mcl_mapgen.order.CHORUS) diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 129642470..b1e9d8e09 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -988,28 +988,6 @@ local function register_mgv6_decorations() end - -- Wet Sponge - -- TODO: Remove this when we got ocean monuments - minetest.register_decoration({ - deco_type = "simple", - decoration = "mcl_sponges:sponge_wet", - spawn_by = {"group:water"}, - num_spawn_by = 1, - place_on = {"mcl_core:dirt","mcl_core:sand"}, - sidelen = 16, - noise_params = { - offset = 0.00295, - scale = 0.006, - spread = {x = 250, y = 250, z = 250}, - seed = 999, - octaves = 3, - persist = 0.666 - }, - flags = "force_placement", - y_min = mcl_mapgen.overworld.lava_max + 5, - y_max = -20, - }) - -- Add a small amount of tall grass everywhere to avoid areas completely empty devoid of tall grass minetest.register_decoration({ deco_type = "simple", @@ -1197,6 +1175,8 @@ mcl_mapgen.register_mapgen_lvm(function(c) if maxp.y < -5 or minp.y > 0 then return c end + c.vm = c.vm or mcl_mapgen.get_voxel_manip(c) + minetest.log("warning", "CLAY!") local pr = PseudoRandom(blockseed) From 726159e796811fa303ab9e40218ef8dd260dc493 Mon Sep 17 00:00:00 2001 From: kay27 Date: Fri, 7 Jan 2022 06:24:11 +0400 Subject: [PATCH 26/61] Dedicate clay and structures from mapgen core --- mods/CORE/mcl_mapgen/API.md | 8 +- mods/CORE/mcl_mapgen/init.lua | 6 +- mods/MAPGEN/mcl_dungeons/init.lua | 33 +- mods/MAPGEN/mcl_mapgen_core/clay.lua | 58 ++++ mods/MAPGEN/mcl_mapgen_core/init.lua | 365 +-------------------- mods/MAPGEN/mcl_mapgen_core/structures.lua | 314 ++++++++++++++++++ 6 files changed, 400 insertions(+), 384 deletions(-) create mode 100644 mods/MAPGEN/mcl_mapgen_core/clay.lua create mode 100644 mods/MAPGEN/mcl_mapgen_core/structures.lua diff --git a/mods/CORE/mcl_mapgen/API.md b/mods/CORE/mcl_mapgen/API.md index 75307f321..1587e19f4 100644 --- a/mods/CORE/mcl_mapgen/API.md +++ b/mods/CORE/mcl_mapgen/API.md @@ -5,14 +5,14 @@ It also queues your generators to run them in proper order: ### mcl_mapgen.register_on_generated(lvm_callback_function, order_number) ========================================================================= -Replacement of engine API function `minetest.register_on_generated(function(minp, maxp, blockseed))` +Replacement of engine API function `minetest.register_on_generated(function(vm_context))` It is still unsafe. Cavegen part can and will overwrite outer 1-block layer of the chunk which is expected to be generated. Nodes marked as `is_ground_content` could be overwritten. Air and water are usually 'ground content' too. For Minetest 5.4 it doesn't recommended to place blocks within lvm callback function. See https://git.minetest.land/MineClone2/MineClone2/issues/1395 `lvm_callback_function`: chunk callback LVM function definition: `function(vm_context)`: - Function MUST RETURN `vm_context` back anyway! It will passed into next lvm callback function from the queue. + `vm_context` will pass into next lvm callback function from the queue! `vm_context`: a table which already contains some LVM data as the fields, and some of them can be added in your lvm callback function: `vm`: curent voxel manipulator object itself; `blockseed`: seed of this mapchunk; @@ -50,7 +50,7 @@ See https://git.minetest.land/MineClone2/MineClone2/issues/1395 ### mcl_mapgen.register_mapgen_block_lvm(lvm_callback_function, order_number) ============================================================================= Registers lvm callback function to be called when current block (usually 16x16x16 nodes) generation is REALLY 100% finished. -`vm_context` passes into lvm callback function and should always be returned back. +`vm_context` passes into lvm callback function. `lvm_callback_function`: the block callback LVM function definition - same as for chunks - see definition example above; `order_number` (optional): the less, the earlier, e.g. `mcl_mapgen.order.BUILDINGS` or `mcl_mapgen.order.LARGE_BUILDINGS` @@ -85,7 +85,7 @@ Set Registers lvm callback function to be called when current chunk generation is REALLY 100% finished. It's the most frustrating function from this mod. It can't provide you access to mapgen objects. They are probably gone long ago. Don't use it for accessing mapgen objects please. -`vm_context` passes into lvm callback function and should always be returned back. +`vm_context` passes into lvm callback function. `lvm_callback_function`: the block callback LVM function definition - same as above; `order_number` (optional): the less, the earlier. diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index d2224075b..16271b4d2 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -241,7 +241,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) vm_context.blockseed = blockseed vm_context.minp, vm_context.maxp = {x=x, y=y, z=z}, {x=x+LAST_NODE, y=y+LAST_NODE, z=z+LAST_NODE} for _, v in pairs(queue_blocks_lvm) do - vm_context = v.callback_function(vm_context) + v.callback_function(vm_context) end end if nodes_block > 0 then @@ -264,7 +264,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) if #queue_unsafe_engine > 0 then for _, v in pairs(queue_unsafe_engine) do - vm_context = v.f(vm_context) + v.f(vm_context) end if vm_context.write then vm:set_data(data) @@ -304,7 +304,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) chunkseed = seed, } for _, v in pairs(queue_chunks_lvm) do - v.f(vm_context) + vm_context = v.f(vm_context) end for _, v in pairs(queue_chunks_nodes) do v.f(minp, maxp, seed, vm_context) diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index eb802d850..c3e406ca1 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -110,7 +110,7 @@ local loottable = } -- Bonus loot for v6 mapgen: Otherwise unobtainable saplings. -if mg_name == "v6" then +if mcl_mapgen.v6 then table.insert(loottable, { stacks_min = 1, stacks_max = 3, @@ -137,36 +137,11 @@ local function spawn_dungeon(p1, p2, dim, pr, dontcheck) local y_ceiling = y + dim.y + 1 if check then - local result1, result2 = true, true local dim_x, dim_z = dim.x, dim.z local size = dim_z*dim_x - local time1 = minetest.get_us_time() - for i=1,100 do - for tx = x+1, x+dim_x do - for tz = z+1, z+dim_z do - if not registered_nodes[get_node({x = tx, y = y_floor , z = tz}).name].walkable - or not registered_nodes[get_node({x = tx, y = y_ceiling, z = tz}).name].walkable then - result1 = false - end - end - end - end - local time2 = minetest.get_us_time() - for i=1,100 do - if #minetest_find_nodes_in_area({x=x+1,y=y_floor,z=z+1}, {x=x+dim_z,y=y_floor,z=z+dim_z}, "group:walkabke") < size - or #minetest_find_nodes_in_area({x=x+1,y=y_floor,z=z+1}, {x=x+dim_z,y=y_floor,z=z+dim_z}, "group:walkabke") < size then - result2 = false - end - end - local time3 = minetest.get_us_time() - if result1 == result2 then - local d1, d2 = time2-time1, time3-time2 - local m1 = m1 + d1 - local m2 = m2 + d2 - minetest.chat_send_all("m1 = " .. tostring(m1)) - minetest.chat_send_all("m2 = " .. tostring(m2)) - else - minetest.log("warning", "results mismatch") + if #minetest_find_nodes_in_area({x=x+1,y=y_floor,z=z+1}, {x=x+dim_z,y=y_floor,z=z+dim_z}, "group:walkabke") < size + or #minetest_find_nodes_in_area({x=x+1,y=y_floor,z=z+1}, {x=x+dim_z,y=y_floor,z=z+dim_z}, "group:walkabke") < size then + return end end diff --git a/mods/MAPGEN/mcl_mapgen_core/clay.lua b/mods/MAPGEN/mcl_mapgen_core/clay.lua new file mode 100644 index 000000000..ea44dc7ec --- /dev/null +++ b/mods/MAPGEN/mcl_mapgen_core/clay.lua @@ -0,0 +1,58 @@ +-- Generate Clay +mcl_mapgen.register_mapgen_lvm(function(c) + local minp, maxp, blockseed, voxelmanip_data, voxelmanip_area, lvm_used = c.minp, c.maxp, c.chunkseed, c.data, c.area, c.write or false + -- TODO: Make clay generation reproducible for same seed. + if maxp.y < -5 or minp.y > 0 then + return c + end + c.vm = c.vm or mcl_mapgen.get_voxel_manip(c) + + minetest.log("warning", "CLAY!") + + local pr = PseudoRandom(blockseed) + + perlin_clay = perlin_clay or minetest.get_perlin({ + offset = 0.5, + scale = 0.2, + spread = {x = 5, y = 5, z = 5}, + seed = -316, + octaves = 1, + persist = 0.0 + }) + + for y=math.max(minp.y, 0), math.min(maxp.y, -8), -1 do + -- Assume X and Z lengths are equal + local divlen = 4 + local divs = (maxp.x-minp.x)/divlen+1; + for divx=0+1,divs-2 do + for divz=0+1,divs-2 do + -- Get position and shift it a bit randomly so the clay do not obviously appear in a grid + local cx = minp.x + math.floor((divx+0.5)*divlen) + pr:next(-1,1) + local cz = minp.z + math.floor((divz+0.5)*divlen) + pr:next(-1,1) + + local water_pos = voxelmanip_area:index(cx, y+1, cz) + local waternode = voxelmanip_data[water_pos] + local surface_pos = voxelmanip_area:index(cx, y, cz) + local surfacenode = voxelmanip_data[surface_pos] + + local genrnd = pr:next(1, 20) + if genrnd == 1 and perlin_clay:get_3d({x=cx,y=y,z=cz}) > 0 and waternode == c_water and + (surfacenode == c_dirt or minetest.get_item_group(minetest.get_name_from_content_id(surfacenode), "sand") == 1) then + local diamondsize = pr:next(1, 3) + for x1 = -diamondsize, diamondsize do + for z1 = -(diamondsize - math.abs(x1)), diamondsize - math.abs(x1) do + local ccpos = voxelmanip_area:index(cx+x1, y, cz+z1) + local claycandidate = voxelmanip_data[ccpos] + if voxelmanip_data[ccpos] == c_dirt or minetest.get_item_group(minetest.get_name_from_content_id(claycandidate), "sand") == 1 then + voxelmanip_data[ccpos] = c_clay + lvm_used = true + end + end + end + end + end + end + end + c.write = lvm_used + return c +end) diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index b1e9d8e09..69841cc62 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -45,13 +45,10 @@ minetest.register_alias("mapgen_stair_sandstonebrick", "mcl_stairs:stair_sandsto minetest.register_alias("mapgen_stair_sandstone_block", "mcl_stairs:stair_sandstone") minetest.register_alias("mapgen_stair_desert_stone", "mcl_stairs:stair_sandstone") -local mg_name = minetest.get_mapgen_setting("mg_name") -local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" - -local WITCH_HUT_HEIGHT = 3 -- Exact Y level to spawn witch huts at. This height refers to the height of the floor - --- End exit portal position -local END_EXIT_PORTAL_POS = vector.new(-3, -27003, -3) +local mg_name = mcl_mapgen.name +local superflat = mcl_mapgen.superflat +local v6 = mcl_mapgen.v6 +local singlenode = mcl_mapgen.singlenode -- Content IDs local c_bedrock = minetest.get_content_id("mcl_core:bedrock") @@ -451,7 +448,7 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then -- Emerald -- - if mg_name == "v6" then + if v6 then -- Generate everywhere in v6, but rarely. -- Common spawn @@ -1104,7 +1101,7 @@ mcl_vars.mg_dungeons = mcl_mapgen.dungeons mg_flags.dungeons = false -- Apply mapgen-specific mapgen code -if mg_name == "v6" then +if v6 then register_mgv6_decorations() elseif superflat then -- Enforce superflat-like mapgen: no caves, decor, lakes and hills @@ -1125,20 +1122,6 @@ if string.len(mg_flags_str) > 0 then end minetest.set_mapgen_setting("mg_flags", mg_flags_str, true) --- Helper function for converting a MC probability to MT, with --- regards to MapBlocks. --- Some MC generated structures are generated on per-chunk --- probability. --- The MC probability is 1/x per Minecraft chunk (16×16). - --- x: The MC probability is 1/x. --- minp, maxp: MapBlock limits --- returns: Probability (1/return_value) for a single MT mapblock -local function minecraft_chunk_probability(x, minp, maxp) - -- 256 is the MC chunk height - return x * (((maxp.x-minp.x+1)*(maxp.z-minp.z+1)) / 256) -end - -- Takes an index of a biomemap table (from minetest.get_mapgen_object), -- minp and maxp (from an on_generated callback) and returns the real world coordinates -- as X, Z. @@ -1151,82 +1134,11 @@ end return x, z end]] --- Takes x and z coordinates and minp and maxp of a generated chunk --- (in on_generated callback) and returns a biomemap index) --- Inverse function of biomemap_to_xz -local function xz_to_biomemap_index(x, z, minp, maxp) - local xwidth = maxp.x - minp.x + 1 - local zwidth = maxp.z - minp.z + 1 - local minix = x % xwidth - local miniz = z % zwidth - - return (minix + miniz * zwidth) + 1 -end - -- Perlin noise objects local perlin_structures local perlin_vines, perlin_vines_fine, perlin_vines_upwards, perlin_vines_length, perlin_vines_density local perlin_clay --- Generate Clay -mcl_mapgen.register_mapgen_lvm(function(c) - local minp, maxp, blockseed, voxelmanip_data, voxelmanip_area, lvm_used = c.minp, c.maxp, c.chunkseed, c.data, c.area, c.write or false - -- TODO: Make clay generation reproducible for same seed. - if maxp.y < -5 or minp.y > 0 then - return c - end - c.vm = c.vm or mcl_mapgen.get_voxel_manip(c) - - minetest.log("warning", "CLAY!") - - local pr = PseudoRandom(blockseed) - - perlin_clay = perlin_clay or minetest.get_perlin({ - offset = 0.5, - scale = 0.2, - spread = {x = 5, y = 5, z = 5}, - seed = -316, - octaves = 1, - persist = 0.0 - }) - - for y=math.max(minp.y, 0), math.min(maxp.y, -8), -1 do - -- Assume X and Z lengths are equal - local divlen = 4 - local divs = (maxp.x-minp.x)/divlen+1; - for divx=0+1,divs-2 do - for divz=0+1,divs-2 do - -- Get position and shift it a bit randomly so the clay do not obviously appear in a grid - local cx = minp.x + math.floor((divx+0.5)*divlen) + pr:next(-1,1) - local cz = minp.z + math.floor((divz+0.5)*divlen) + pr:next(-1,1) - - local water_pos = voxelmanip_area:index(cx, y+1, cz) - local waternode = voxelmanip_data[water_pos] - local surface_pos = voxelmanip_area:index(cx, y, cz) - local surfacenode = voxelmanip_data[surface_pos] - - local genrnd = pr:next(1, 20) - if genrnd == 1 and perlin_clay:get_3d({x=cx,y=y,z=cz}) > 0 and waternode == c_water and - (surfacenode == c_dirt or minetest.get_item_group(minetest.get_name_from_content_id(surfacenode), "sand") == 1) then - local diamondsize = pr:next(1, 3) - for x1 = -diamondsize, diamondsize do - for z1 = -(diamondsize - math.abs(x1)), diamondsize - math.abs(x1) do - local ccpos = voxelmanip_area:index(cx+x1, y, cz+z1) - local claycandidate = voxelmanip_data[ccpos] - if voxelmanip_data[ccpos] == c_dirt or minetest.get_item_group(minetest.get_name_from_content_id(claycandidate), "sand") == 1 then - voxelmanip_data[ccpos] = c_clay - lvm_used = true - end - end - end - end - end - end - end - c.write = lvm_used - return c -end) - local dragon_spawn_pos = false local dragon_spawned, portal_generated = false, false @@ -1252,7 +1164,7 @@ if portal_generated and not dragon_spawned then minetest.after(10, try_to_spawn_ender_dragon) end -local function generate_end_exit_portal(pos) +function mcl_mapgen_core.generate_end_exit_portal(pos) if dragon_spawn_pos then return false end dragon_spawn_pos = vector.add(pos, vector.new(3, 11, 3)) mcl_structures.call_struct(pos, "end_exit_portal", nil, nil, function() @@ -1266,252 +1178,6 @@ local function generate_end_exit_portal(pos) portal_generated = true end --- TODO: Try to use more efficient structure generating code -local function generate_structures(minp, maxp, blockseed, biomemap) - local chunk_has_desert_well = false - local chunk_has_desert_temple = false - local chunk_has_igloo = false - local struct_min, struct_max = -3, 111 --64 - - if maxp.y >= struct_min and minp.y <= struct_max then - -- Generate structures - local pr = PcgRandom(blockseed) - perlin_structures = perlin_structures or minetest.get_perlin(329, 3, 0.6, 100) - -- Assume X and Z lengths are equal - local divlen = 5 - for x0 = minp.x, maxp.x, divlen do for z0 = minp.z, maxp.z, divlen do - -- Determine amount from perlin noise - local amount = math.floor(perlin_structures:get_2d({x=x0, y=z0}) * 9) - -- Find random positions based on this random - local p, ground_y - for i=0, amount do - p = {x = pr:next(x0, x0+divlen-1), y = 0, z = pr:next(z0, z0+divlen-1)} - -- Find ground level - ground_y = nil - local nn - for y = struct_max, struct_min, -1 do - p.y = y - local checknode = minetest.get_node(p) - if checknode then - nn = checknode.name - local def = minetest.registered_nodes[nn] - if def and def.walkable then - ground_y = y - break - end - end - end - - if ground_y then - p.y = ground_y+1 - local nn0 = minetest.get_node(p).name - -- Check if the node can be replaced - if minetest.registered_nodes[nn0] and minetest.registered_nodes[nn0].buildable_to then - -- Desert temples and desert wells - if nn == "mcl_core:sand" or (nn == "mcl_core:sandstone") then - if not chunk_has_desert_temple and not chunk_has_desert_well and ground_y > 3 then - -- Spawn desert temple - -- TODO: Check surface - if pr:next(1,12000) == 1 then - mcl_structures.call_struct(p, "desert_temple", nil, pr) - chunk_has_desert_temple = true - end - end - if not chunk_has_desert_temple and not chunk_has_desert_well and ground_y > 3 then - local desert_well_prob = minecraft_chunk_probability(1000, minp, maxp) - - -- Spawn desert well - if pr:next(1, desert_well_prob) == 1 then - -- Check surface - local surface = minetest.find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, {x=p.x+5, y=p.y-1, z=p.z+5}, "mcl_core:sand") - if #surface >= 25 then - mcl_structures.call_struct(p, "desert_well", nil, pr) - chunk_has_desert_well = true - end - end - end - - -- Igloos - elseif not chunk_has_igloo and (nn == "mcl_core:snowblock" or nn == "mcl_core:snow" or (minetest.get_item_group(nn, "grass_block_snow") == 1)) then - if pr:next(1, 4400) == 1 then - -- Check surface - local floor = {x=p.x+9, y=p.y-1, z=p.z+9} - local surface = minetest.find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, floor, "mcl_core:snowblock") - local surface2 = minetest.find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, floor, "mcl_core:dirt_with_grass_snow") - if #surface + #surface2 >= 63 then - mcl_structures.call_struct(p, "igloo", nil, pr) - chunk_has_igloo = true - end - end - end - - -- Fossil - if nn == "mcl_core:sandstone" or nn == "mcl_core:sand" and not chunk_has_desert_temple and ground_y > 3 then - local fossil_prob = minecraft_chunk_probability(64, minp, maxp) - - if pr:next(1, fossil_prob) == 1 then - -- Spawn fossil below desert surface between layers 40 and 49 - local p1 = {x=p.x, y=pr:next(mcl_worlds.layer_to_y(40), mcl_worlds.layer_to_y(49)), z=p.z} - -- Very rough check of the environment (we expect to have enough stonelike nodes). - -- Fossils may still appear partially exposed in caves, but this is O.K. - local p2 = vector.add(p1, 4) - local nodes = minetest.find_nodes_in_area(p1, p2, {"mcl_core:sandstone", "mcl_core:stone", "mcl_core:diorite", "mcl_core:andesite", "mcl_core:granite", "mcl_core:stone_with_coal", "mcl_core:dirt", "mcl_core:gravel"}) - - if #nodes >= 100 then -- >= 80% - mcl_structures.call_struct(p1, "fossil", nil, pr) - end - end - end - - -- Witch hut - if ground_y <= 0 and nn == "mcl_core:dirt" then - local prob = minecraft_chunk_probability(48, minp, maxp) - if pr:next(1, prob) == 1 then - - local swampland = minetest.get_biome_id("Swampland") - local swampland_shore = minetest.get_biome_id("Swampland_shore") - - -- Where do witches live? - - local here_be_witches = false - if mg_name == "v6" then - -- v6: In Normal biome - if biomeinfo.get_v6_biome(p) == "Normal" then - here_be_witches = true - end - else - -- Other mapgens: In swampland biome - local bi = xz_to_biomemap_index(p.x, p.z, minp, maxp) - if biomemap[bi] == swampland or biomemap[bi] == swampland_shore then - here_be_witches = true - end - end - - if here_be_witches then - local r = tostring(pr:next(0, 3) * 90) -- "0", "90", "180" or 270" - local p1 = {x=p.x-1, y=WITCH_HUT_HEIGHT+2, z=p.z-1} - local size - if r == "0" or r == "180" then - size = {x=10, y=4, z=8} - else - size = {x=8, y=4, z=10} - end - local p2 = vector.add(p1, size) - - -- This checks free space at the “body” of the hut and a bit around. - -- ALL nodes must be free for the placement to succeed. - local free_nodes = minetest.find_nodes_in_area(p1, p2, {"air", "mcl_core:water_source", "mcl_flowers:waterlily"}) - if #free_nodes >= ((size.x+1)*(size.y+1)*(size.z+1)) then - local place = {x=p.x, y=WITCH_HUT_HEIGHT-1, z=p.z} - - -- FIXME: For some mysterious reason (black magic?) this - -- function does sometimes NOT spawn the witch hut. One can only see the - -- oak wood nodes in the water, but no hut. :-/ - mcl_structures.call_struct(place, "witch_hut", r, pr) - - -- TODO: Spawn witch in or around hut when the mob sucks less. - - local function place_tree_if_free(pos, prev_result) - local nn = minetest.get_node(pos).name - if nn == "mcl_flowers:waterlily" or nn == "mcl_core:water_source" or nn == "mcl_core:water_flowing" or nn == "air" then - minetest.set_node(pos, {name="mcl_core:tree", param2=0}) - return prev_result - else - return false - end - end - local offsets - if r == "0" then - offsets = { - {x=1, y=0, z=1}, - {x=1, y=0, z=5}, - {x=6, y=0, z=1}, - {x=6, y=0, z=5}, - } - elseif r == "180" then - offsets = { - {x=2, y=0, z=1}, - {x=2, y=0, z=5}, - {x=7, y=0, z=1}, - {x=7, y=0, z=5}, - } - elseif r == "270" then - offsets = { - {x=1, y=0, z=1}, - {x=5, y=0, z=1}, - {x=1, y=0, z=6}, - {x=5, y=0, z=6}, - } - elseif r == "90" then - offsets = { - {x=1, y=0, z=2}, - {x=5, y=0, z=2}, - {x=1, y=0, z=7}, - {x=5, y=0, z=7}, - } - end - for o=1, #offsets do - local ok = true - for y=place.y-1, place.y-64, -1 do - local tpos = vector.add(place, offsets[o]) - tpos.y = y - ok = place_tree_if_free(tpos, ok) - if not ok then - break - end - end - end - end - end - end - end - - -- Ice spikes in v6 - -- In other mapgens, ice spikes are generated as decorations. - if mg_name == "v6" and not chunk_has_igloo and nn == "mcl_core:snowblock" then - local spike = pr:next(1,58000) - if spike < 3 then - -- Check surface - local floor = {x=p.x+4, y=p.y-1, z=p.z+4} - local surface = minetest.find_nodes_in_area({x=p.x+1,y=p.y-1,z=p.z+1}, floor, {"mcl_core:snowblock"}) - -- Check for collision with spruce - local spruce_collisions = minetest.find_nodes_in_area({x=p.x+1,y=p.y+2,z=p.z+1}, {x=p.x+4, y=p.y+6, z=p.z+4}, {"mcl_core:sprucetree", "mcl_core:spruceleaves"}) - - if #surface >= 9 and #spruce_collisions == 0 then - mcl_structures.call_struct(p, "ice_spike_large", nil, pr) - end - elseif spike < 100 then - -- Check surface - local floor = {x=p.x+6, y=p.y-1, z=p.z+6} - local surface = minetest.find_nodes_in_area({x=p.x+1,y=p.y-1,z=p.z+1}, floor, {"mcl_core:snowblock", "mcl_core:dirt_with_grass_snow"}) - - -- Check for collision with spruce - local spruce_collisions = minetest.find_nodes_in_area({x=p.x+1,y=p.y+1,z=p.z+1}, {x=p.x+6, y=p.y+6, z=p.z+6}, {"mcl_core:sprucetree", "mcl_core:spruceleaves"}) - - if #surface >= 25 and #spruce_collisions == 0 then - mcl_structures.call_struct(p, "ice_spike_small", nil, pr) - end - end - end - end - end - - end - end end - -- End exit portal - elseif minp.y <= END_EXIT_PORTAL_POS.y and maxp.y >= END_EXIT_PORTAL_POS.y and - minp.x <= END_EXIT_PORTAL_POS.x and maxp.x >= END_EXIT_PORTAL_POS.x and - minp.z <= END_EXIT_PORTAL_POS.z and maxp.z >= END_EXIT_PORTAL_POS.z then - for y=maxp.y, minp.y, -1 do - local p = {x=END_EXIT_PORTAL_POS.x, y=y, z=END_EXIT_PORTAL_POS.z} - if minetest.get_node(p).name == "mcl_end:end_stone" then - generate_end_exit_portal(p) - return - end - end - generate_end_exit_portal(END_EXIT_PORTAL_POS) - end -end -- Buffers for LuaVoxelManip -- local lvm_buffer = {} @@ -1754,7 +1420,7 @@ local function generate_underground_mushrooms(minp, maxp, seed) end local nether_wart_chance -if mg_name == "v6" then +if v6 then nether_wart_chance = 85 else nether_wart_chance = 170 @@ -1930,7 +1596,7 @@ local function basic_safe(vm_context) lvm_used = set_layers(data, area, c_void , nil, mcl_mapgen.realm_barrier_overworld_end_max+1, mcl_mapgen.overworld.min -1, minp, maxp, lvm_used, pr) - if mg_name ~= "singlenode" then + if not singlenode then -- Bedrock lvm_used = set_layers(data, area, c_bedrock, bedrock_check, mcl_mapgen.overworld.bedrock_min, mcl_mapgen.overworld.bedrock_max, minp, maxp, lvm_used, pr) lvm_used = set_layers(data, area, c_bedrock, bedrock_check, mcl_mapgen.nether.bedrock_bottom_min, mcl_mapgen.nether.bedrock_bottom_max, minp, maxp, lvm_used, pr) @@ -1963,7 +1629,7 @@ local function basic_safe(vm_context) -- A snowy grass block must be below a top snow or snow block at all times. if minp.y <= mcl_mapgen.overworld.max and maxp.y >= mcl_mapgen.overworld.min then -- v6 mapgen: - if mg_name == "v6" then + if v6 then --[[ Remove broken double plants caused by v6 weirdness. v6 might break the bottom part of double plants because of how it works. @@ -2028,7 +1694,7 @@ local function basic_safe(vm_context) -- * Replace water with Nether lava. -- * Replace stone, sand dirt in v6 so the Nether works in v6. elseif emin.y <= mcl_mapgen.nether.max and emax.y >= mcl_mapgen.nether.min then - if mg_name == "v6" then + if v6 then local nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"}) for n=1, #nodes do local p_pos = area:index(nodes[n].x, nodes[n].y, nodes[n].z) @@ -2056,7 +1722,7 @@ local function basic_safe(vm_context) -- * Generate spawn platform (End portal destination) elseif minp.y <= mcl_mapgen.end_.max and maxp.y >= mcl_mapgen.end_.min then local nodes - if mg_name == "v6" then + if v6 then nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"}) else nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source"}) @@ -2105,14 +1771,17 @@ local function basic_safe(vm_context) lvm_used = true end - if mg_name ~= "singlenode" then + if not singlenode then -- Generate special decorations generate_underground_mushrooms(minp, maxp, blockseed) generate_nether_decorations(minp, maxp, blockseed) - generate_structures(minp, maxp, blockseed, biomemap) end return vm_context --, lvm_used, shadow end mcl_mapgen.register_mapgen_block_lvm(basic_safe, 1) + +local modpath = minetest.get_modpath(minetest.get_current_modname()) +dofile(modpath .. "/clay.lua") +dofile(modpath .. "/structures.lua") diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua new file mode 100644 index 000000000..526060319 --- /dev/null +++ b/mods/MAPGEN/mcl_mapgen_core/structures.lua @@ -0,0 +1,314 @@ +local END_EXIT_PORTAL_POS = vector.new(-3, -27003, -3) -- End exit portal position +local WITCH_HUT_HEIGHT = 3 -- Exact Y level to spawn witch huts at. This height refers to the height of the floor +local OVERWORLD_STRUCT_MIN, OVERWORLD_STRUCT_MAX = mcl_mapgen.overworld.min, mcl_mapgen.overworld.max +local END_STRUCT_MIN, END_STRUCT_MAX = mcl_mapgen.end_.min, mcl_mapgen.end_.max +local DIVLEN = 5 +local V6 = mcl_mapgen.v6 + +local math_min, math_max = math.min, math.max +local math_floor = math.floor +local minetest_get_node = minetest.get_node +local minetest_get_mapgen_object = minetest.get_mapgen_object +local minetest_find_nodes_in_area = minetest.find_nodes_in_area + +-- TODO: Try to use more efficient structure generating code + +local function determine_ground_level(p, vm_context) + local emax = vm_context.emax + local emax_y = emax.y + local y = math_min(OVERWORLD_STRUCT_MAX, emax_y) + if y < emax_y then + y = y + 1 + end + p.y = y + local checknode = minetest_get_node(p) + if checknode.name ~= "air" then + return + end + for y = y - 1, math_max(OVERWORLD_STRUCT_MIN, vm_context.emin.y), -1 do + p.y = y + local checknode = minetest_get_node(p) + if checknode then + local nn = checknode.name + local def = minetest.registered_nodes[nn] + if def and def.walkable then + return p, y, nn + end + end + end +end + +-- Helper function for converting a MC probability to MT, with +-- regards to MapBlocks. +-- Some MC generated structures are generated on per-chunk +-- probability. +-- The MC probability is 1/x per Minecraft chunk (16×16). + +-- x: The MC probability is 1/x. +-- minp, maxp: MapBlock limits +-- returns: Probability (1/return_value) for a single MT mapblock +local function minecraft_chunk_probability(x, minp, maxp) + -- 256 is the MC chunk height + return x * (((maxp.x-minp.x+1)*(maxp.z-minp.z+1)) / 256) +end + +-- Takes x and z coordinates and minp and maxp of a generated chunk +-- (in on_generated callback) and returns a biomemap index) +-- Inverse function of biomemap_to_xz +local function xz_to_biomemap_index(x, z, minp, maxp) + local xwidth = maxp.x - minp.x + 1 + local zwidth = maxp.z - minp.z + 1 + local minix = x % xwidth + local miniz = z % zwidth + + return (minix + miniz * zwidth) + 1 +end + +local chunk_has_desert_struct +local chunk_has_igloo + +local function spawn_desert_temples_and_desert_wells(p, nn, pr, vm_context) + if chunk_has_desert_struct or p.y < 5 then return end + if nn ~= "mcl_core:sand" and nn ~= "mcl_core:sandstone" then return end + -- Spawn desert temple + if pr:next(1,12000) == 1 then + mcl_structures.call_struct(p, "desert_temple", nil, pr) + chunk_has_desert_struct = true + return true + end + -- Spawn desert well + local desert_well_prob = minecraft_chunk_probability(1000, vm_context.minp, vm_context.maxp) + if pr:next(1, desert_well_prob) ~= 1 then return end + -- Check surface + local surface = minetest_find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, {x=p.x+5, y=p.y-1, z=p.z+5}, "mcl_core:sand") + if #surface < 25 then return end + mcl_structures.call_struct(p, "desert_well", nil, pr) + chunk_has_desert_struct = true + return true +end + +local function spawn_igloos(p, nn, pr) + if chunk_has_igloo then return end + if nn ~= "mcl_core:snowblock" and nn ~= "mcl_core:snow" and minetest.get_item_group(nn, "grass_block_snow") ~= 1 then return end + if pr:next(1, 4400) ~= 1 then return end + -- Check surface + local floor = {x=p.x+9, y=p.y-1, z=p.z+9} + local surface = minetest_find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, floor, "mcl_core:snowblock") + local surface2 = minetest_find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, floor, "mcl_core:dirt_with_grass_snow") + if #surface + #surface2 < 63 then return end + mcl_structures.call_struct(p, "igloo", nil, pr) + chunk_has_igloo = true + return true +end + +local function spawn_fossil(p, nn, pr, vm_context) + if chunk_has_desert_struct or p.y > 4 then return end + if nn ~= "mcl_core:sandstone" and nn ~= "mcl_core:sand" then return end + local fossil_prob = minecraft_chunk_probability(64, vm_context.minp, vm_context.maxp) + if pr:next(1, fossil_prob) ~= 1 then return end + -- Spawn fossil below desert surface between layers 40 and 49 + local p1 = {x=p.x, y=pr:next(mcl_worlds.layer_to_y(40), mcl_worlds.layer_to_y(49)), z=p.z} + -- Very rough check of the environment (we expect to have enough stonelike nodes). + -- Fossils may still appear partially exposed in caves, but this is O.K. + local p2 = vector.add(p1, 4) + local nodes = minetest_find_nodes_in_area(p1, p2, {"mcl_core:sandstone", "mcl_core:stone", "mcl_core:diorite", "mcl_core:andesite", "mcl_core:granite", "mcl_core:stone_with_coal", "mcl_core:dirt", "mcl_core:gravel"}) + if #nodes < 100 then return end + -- >= 80% + mcl_structures.call_struct(p1, "fossil", nil, pr) +end + +local witch_hut_offsets = { + ["0"] = { + {x=1, y=0, z=1}, {x=1, y=0, z=5}, {x=6, y=0, z=1}, {x=6, y=0, z=5}, + }, + ["180"] = { + {x=2, y=0, z=1}, {x=2, y=0, z=5}, {x=7, y=0, z=1}, {x=7, y=0, z=5}, + }, + ["270"] = { + {x=1, y=0, z=1}, {x=5, y=0, z=1}, {x=1, y=0, z=6}, {x=5, y=0, z=6}, + }, + ["90"] = { + {x=1, y=0, z=2}, {x=5, y=0, z=2}, {x=1, y=0, z=7}, {x=5, y=0, z=7}, + }, +} + +local function spawn_witch_hut(p, nn, pr, vm_context) + if p.y <= 1 or nn ~= "mcl_core:dirt" then return end + local minp, maxp = vm_context.minp, vm_context.maxp + local prob = minecraft_chunk_probability(48, minp, maxp) + if pr:next(1, prob) ~= 1 then return end + + -- Where do witches live? + if V6 then + -- v6: In Normal biome + if biomeinfo.get_v6_biome(p) ~= "Normal" then return end + else + -- Other mapgens: In swampland biome + local biomemap = vm_context.biomemap + if not biomemap then + vm_context.biomemap = vm_context.biomemap or minetest_get_mapgen_object('biomemap') + biomemap = vm_context.biomemap + end + local swampland = minetest.get_biome_id("Swampland") + local swampland_shore = minetest.get_biome_id("Swampland_shore") + local bi = xz_to_biomemap_index(p.x, p.z, minp, maxp) + if biomemap[bi] ~= swampland and biomemap[bi] ~= swampland_shore then return end + end + + local r = tostring(pr:next(0, 3) * 90) -- "0", "90", "180" or 270" + local p1 = {x=p.x-1, y=WITCH_HUT_HEIGHT+2, z=p.z-1} + local size + if r == "0" or r == "180" then + size = {x=10, y=4, z=8} + else + size = {x=8, y=4, z=10} + end + local p2 = vector.add(p1, size) + + -- This checks free space at the “body” of the hut and a bit around. + -- ALL nodes must be free for the placement to succeed. + local free_nodes = minetest_find_nodes_in_area(p1, p2, {"air", "mcl_core:water_source", "mcl_flowers:waterlily"}) + if #free_nodes < ((size.x+1)*(size.y+1)*(size.z+1)) then return end + + local place = {x=p.x, y=WITCH_HUT_HEIGHT-1, z=p.z} + + -- FIXME: For some mysterious reason (black magic?) this + -- function does sometimes NOT spawn the witch hut. One can only see the + -- oak wood nodes in the water, but no hut. :-/ + mcl_structures.call_struct(place, "witch_hut", r, pr) + + -- TODO: Spawn witch in or around hut when the mob sucks less. + + local function place_tree_if_free(pos, prev_result) + local nn = minetest.get_node(pos).name + if nn == "mcl_flowers:waterlily" or nn == "mcl_core:water_source" or nn == "mcl_core:water_flowing" or nn == "air" then + minetest.set_node(pos, {name="mcl_core:tree", param2=0}) + return prev_result + else + return false + end + end + + local offsets = witch_hut_offsets[r] + for o=1, #offsets do + local ok = true + for y=place.y-1, place.y-64, -1 do + local tpos = vector.add(place, offsets[o]) + tpos.y = y + ok = place_tree_if_free(tpos, ok) + if not ok then + break + end + end + end +end + +-- TODO: Check spikes sizes, it looks like we have to swap them: + +local function spawn_ice_spike_large(p, pr) + -- Check surface + local floor = {x=p.x+4, y=p.y-1, z=p.z+4} + local surface = minetest_find_nodes_in_area({x=p.x+1,y=p.y-1,z=p.z+1}, floor, {"mcl_core:snowblock"}) + if #surface < 9 then return end + + -- Check for collision with spruce + local spruce_collisions = minetest_find_nodes_in_area({x=p.x+1,y=p.y+2,z=p.z+1}, {x=p.x+4, y=p.y+6, z=p.z+4}, {"mcl_core:sprucetree", "mcl_core:spruceleaves"}) + if #spruce_collisions > 0 then return end + + mcl_structures.call_struct(p, "ice_spike_large", nil, pr) + return true +end + +local function spawn_ice_spike_small(p, pr) + -- Check surface + local floor = {x=p.x+6, y=p.y-1, z=p.z+6} + local surface = minetest_find_nodes_in_area({x=p.x+1,y=p.y-1,z=p.z+1}, floor, {"mcl_core:snowblock", "mcl_core:dirt_with_grass_snow"}) + if #surface < 25 then return end + + -- Check for collision with spruce + local spruce_collisions = minetest_find_nodes_in_area({x=p.x+1,y=p.y+1,z=p.z+1}, {x=p.x+6, y=p.y+6, z=p.z+6}, {"mcl_core:sprucetree", "mcl_core:spruceleaves"}) + + if #spruce_collisions > 0 then return end + + mcl_structures.call_struct(p, "ice_spike_small", nil, pr) + return true +end + +local function spawn_spikes_in_v6(p, nn, pr) + -- In other mapgens, ice spikes are generated as decorations. + if chunk_has_igloo or nn ~= "mcl_core:snowblock" then return end + local spike = pr:next(1,58000) + if spike < 3 then + return spawn_ice_spike_large(p, pr) + elseif spike < 100 then + return spawn_ice_spike_small(p, pr) + end +end + +local function generate_structures(vm_context) + local pr = PcgRandom(vm_context.blockseed) + perlin_structures = perlin_structures or minetest.get_perlin(329, 3, 0.6, 100) + chunk_has_desert_struct = false + chunk_has_igloo = false + local minp, maxp = vm_context.minp, vm_context.maxp + + -- Assume X and Z lengths are equal + for x0 = minp.x, maxp.x, DIVLEN do for z0 = minp.z, maxp.z, DIVLEN do + -- Determine amount from perlin noise + local amount = math_floor(perlin_structures:get_2d({x=x0, y=z0}) * 9) + -- Find random positions based on this random + local p, ground_y + for i=0, amount do + p = {x = pr:next(x0, x0 + DIVLEN - 1), y = 0, z = pr:next(z0, z0 + DIVLEN - 1)} + p, ground_y, nn = determine_ground_level(p, vm_context) + if ground_y then + p.y = ground_y + 1 + local nn0 = minetest.get_node(p).name + -- Check if the node can be replaced + if minetest.registered_nodes[nn0] and minetest.registered_nodes[nn0].buildable_to then + if not spawn_desert_temples_and_desert_wells(p, nn, pr, vm_context) then + spawn_igloos(p, nn, pr, vm_context) + end + spawn_fossil(p, nn, pr, vm_context) + spawn_witch_hut(p, nn, pr, vm_context) + if V6 then + spawn_spikes_in_v6(p, nn, pr, vm_context) + end + end + end + end + end end + return vm_context +end + +local function generate_end_structures(vm_context) + local minp, maxp = vm_context.minp, vm_context.maxp + if minp.y <= END_EXIT_PORTAL_POS.y and maxp.y >= END_EXIT_PORTAL_POS.y + and minp.x <= END_EXIT_PORTAL_POS.x and maxp.x >= END_EXIT_PORTAL_POS.x + and minp.z <= END_EXIT_PORTAL_POS.z and maxp.z >= END_EXIT_PORTAL_POS.z + then + local p = {x=END_EXIT_PORTAL_POS.x, z=END_EXIT_PORTAL_POS.z} + for y = maxp.y, minp.y, -1 do + p.y = y + if minetest.get_node(p).name == "mcl_end:end_stone" then + mcl_mapgen_core.generate_end_exit_portal(p) + break + end + end + end + return vm_context +end + +if not mcl_mapgen.singlenode then + mcl_mapgen.register_on_generated(function(vm_context) + local minp, maxp = vm_context.minp, vm_context.maxp + local minp_y, maxp_y = minp.y, maxp.y + if maxp_y >= OVERWORLD_STRUCT_MIN and minp_y <= OVERWORLD_STRUCT_MAX then + return generate_structures(vm_context) + -- End exit portal + elseif maxp_y >= END_STRUCT_MIN and minp_y <= END_STRUCT_MAX then + return generate_end_structures(vm_context) + end + return vm_context + end) +end From da8e92e071541ac95ceaec0cc3157fad3f3b2017 Mon Sep 17 00:00:00 2001 From: kay27 Date: Fri, 7 Jan 2022 07:16:31 +0400 Subject: [PATCH 27/61] Fix layers --- mods/MAPGEN/mcl_mapgen_core/init.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 3e5cec0fa..443dfc3ee 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1731,10 +1731,12 @@ local function basic_safe(vm_context) -- Nether block fixes: -- * Replace water with Nether lava. -- * Replace stone, sand dirt in v6 so the Nether works in v6. - elseif emin.y <= mcl_mapgen.nether.max and emax.y >= mcl_mapgen.nether.min then + elseif minp.y <= mcl_mapgen.nether.max and maxp.y >= mcl_mapgen.nether.min then + -- elseif emin.y <= mcl_mapgen.nether.max and emax.y >= mcl_mapgen.nether.min then if c_nether then if v6 then - local nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"}) + -- local nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"}) + local nodes = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"}) for n=1, #nodes do local p_pos = area:index(nodes[n].x, nodes[n].y, nodes[n].z) if data[p_pos] == c_water then @@ -1749,7 +1751,8 @@ local function basic_safe(vm_context) end end else - local nodes = minetest.find_nodes_in_area(emin, emax, {"group:water"}) + -- local nodes = minetest.find_nodes_in_area(emin, emax, {"group:water"}) + local nodes = minetest.find_nodes_in_area(minp, maxp, {"group:water"}) for _, n in pairs(nodes) do data[area:index(n.x, n.y, n.z)] = c_nether.lava end @@ -1763,9 +1766,11 @@ local function basic_safe(vm_context) elseif minp.y <= mcl_mapgen.end_.max and maxp.y >= mcl_mapgen.end_.min then local nodes if v6 then - nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"}) + nodes = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"}) + -- nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"}) else - nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source"}) + nodes = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:water_source"}) + -- nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source"}) end if #nodes > 0 then lvm_used = true @@ -1817,6 +1822,8 @@ local function basic_safe(vm_context) generate_nether_decorations(minp, maxp, blockseed) end + vm_context.write = vm_context.write or lvm_used + return vm_context --, lvm_used, shadow end From 667ebf13857a2b1c68a0ac40a0d55656c807cd79 Mon Sep 17 00:00:00 2001 From: kay27 Date: Fri, 7 Jan 2022 08:41:04 +0400 Subject: [PATCH 28/61] Fix several mapgen_issue warnings --- mods/CORE/mcl_mapgen/init.lua | 11 ++++++----- mods/MAPGEN/mcl_mapgen_core/clay.lua | 8 +++++++- mods/MAPGEN/mcl_mapgen_core/init.lua | 8 +++----- mods/MAPGEN/mcl_mapgen_core/structures.lua | 5 +++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 16271b4d2..586545e73 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -86,7 +86,7 @@ local CS_3D = CS * CS * CS local DEFAULT_ORDER = order.DEFAULT function mcl_mapgen.register_on_generated(callback_function, order) - queue_unsafe_engine[#queue_unsafe_engine+1] = {i = priority or DEFAULT_ORDER, f = callback_function} + queue_unsafe_engine[#queue_unsafe_engine+1] = {i = order or DEFAULT_ORDER, f = callback_function} table.sort(queue_unsafe_engine, function(a, b) return (a.i <= b.i) end) end function mcl_mapgen.register_mapgen(callback_function, order) @@ -98,14 +98,14 @@ end function mcl_mapgen.register_mapgen_lvm(callback_function, order) lvm_chunk = lvm_chunk + 1 safe_functions = safe_functions + 1 - queue_chunks_lvm[lvm_chunk] = {i = priority or DEFAULT_ORDER, f = callback_function} + queue_chunks_lvm[lvm_chunk] = {i = order or DEFAULT_ORDER, f = callback_function} table.sort(queue_chunks_lvm, function(a, b) return (a.i <= b.i) end) end -function mcl_mapgen.register_mapgen_block(callback_function, priority) +function mcl_mapgen.register_mapgen_block(callback_function, order) block = block + 1 nodes_block = nodes_block + 1 safe_functions = safe_functions + 1 - queue_blocks_nodes[nodes_block] = {i = priority or DEFAULT_ORDER, f = callback_function} + queue_blocks_nodes[nodes_block] = {i = order or DEFAULT_ORDER, f = callback_function} table.sort(queue_blocks_nodes, function(a, b) return (a.i <= b.i) end) end function mcl_mapgen.register_mapgen_block_lvm(callback_function, order) @@ -319,7 +319,8 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) if vm_context.write_light then vm:set_light_data(light) end - vm:calc_lighting(minp, maxp, vm_context.shadow or true) + -- caused error from torches (?) + -- vm:calc_lighting(minp, maxp, vm_context.shadow or true) vm:write_to_map() vm:update_liquids() end diff --git a/mods/MAPGEN/mcl_mapgen_core/clay.lua b/mods/MAPGEN/mcl_mapgen_core/clay.lua index ea44dc7ec..cad6c7d85 100644 --- a/mods/MAPGEN/mcl_mapgen_core/clay.lua +++ b/mods/MAPGEN/mcl_mapgen_core/clay.lua @@ -1,4 +1,9 @@ --- Generate Clay +local c_water = minetest.get_content_id("mcl_core:water_source") +local c_dirt = minetest.get_content_id("mcl_core:dirt") +local c_clay = minetest.get_content_id("mcl_core:clay") + +local perlin_clay + mcl_mapgen.register_mapgen_lvm(function(c) local minp, maxp, blockseed, voxelmanip_data, voxelmanip_area, lvm_used = c.minp, c.maxp, c.chunkseed, c.data, c.area, c.write or false -- TODO: Make clay generation reproducible for same seed. @@ -45,6 +50,7 @@ mcl_mapgen.register_mapgen_lvm(function(c) local claycandidate = voxelmanip_data[ccpos] if voxelmanip_data[ccpos] == c_dirt or minetest.get_item_group(minetest.get_name_from_content_id(claycandidate), "sand") == 1 then voxelmanip_data[ccpos] = c_clay + minetest.log("warning", "CLAY! "..minetest.pos_to_string({x=cx+x1,y=y,z=cz+z1})) lvm_used = true end end diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 443dfc3ee..e50a2d4d4 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1168,9 +1168,7 @@ minetest.set_mapgen_setting("mg_flags", mg_flags_str, true) end]] -- Perlin noise objects -local perlin_structures local perlin_vines, perlin_vines_fine, perlin_vines_upwards, perlin_vines_length, perlin_vines_density -local perlin_clay local dragon_spawn_pos = false local dragon_spawned, portal_generated = false, false @@ -1606,7 +1604,7 @@ end -- Below the bedrock, generate air/void local function basic_safe(vm_context) local vm, data, emin, emax, area, minp, maxp, chunkseed, blockseed = vm_context.vm, vm_context.data, vm_context.emin, vm_context.emax, vm_context.area, vm_context.minp, vm_context.maxp, vm_context.chunkseed, vm_context.blockseed - vm_context.data2 = vm_context.data2 or vm:get_param2_data(lvm_param2_buffer) + vm_context.data2 = vm_context.data2 or vm:get_param2_data(vm_context.lvm_param2_buffer) local data2 = vm_context.data2 local lvm_used = false @@ -1647,7 +1645,7 @@ local function basic_safe(vm_context) if mcl_mapgen.lava then lvm_used = set_layers(data, area, c_lava, c_air, mcl_mapgen.overworld.min, mcl_mapgen.overworld.lava_max, minp, maxp, lvm_used, pr) if c_nether then - lvm_used = set_layers(data, area, c_nether_lava, c_air, mcl_mapgen.nether.min, mcl_mapgen.nether.lava_max, minp, maxp, lvm_used, pr) + lvm_used = set_layers(data, area, c_nether.lava, c_air, mcl_mapgen.nether.min, mcl_mapgen.nether.lava_max, minp, maxp, lvm_used, pr) end end @@ -1740,7 +1738,7 @@ local function basic_safe(vm_context) for n=1, #nodes do local p_pos = area:index(nodes[n].x, nodes[n].y, nodes[n].z) if data[p_pos] == c_water then - data[p_pos] = c_nether_lava + data[p_pos] = c_nether.lava lvm_used = true elseif data[p_pos] == c_stone then data[p_pos] = c_netherrack diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua index 526060319..39fc3dbd4 100644 --- a/mods/MAPGEN/mcl_mapgen_core/structures.lua +++ b/mods/MAPGEN/mcl_mapgen_core/structures.lua @@ -1,3 +1,4 @@ + local END_EXIT_PORTAL_POS = vector.new(-3, -27003, -3) -- End exit portal position local WITCH_HUT_HEIGHT = 3 -- Exact Y level to spawn witch huts at. This height refers to the height of the floor local OVERWORLD_STRUCT_MIN, OVERWORLD_STRUCT_MAX = mcl_mapgen.overworld.min, mcl_mapgen.overworld.max @@ -11,7 +12,7 @@ local minetest_get_node = minetest.get_node local minetest_get_mapgen_object = minetest.get_mapgen_object local minetest_find_nodes_in_area = minetest.find_nodes_in_area --- TODO: Try to use more efficient structure generating code +local perlin_structures local function determine_ground_level(p, vm_context) local emax = vm_context.emax @@ -257,7 +258,7 @@ local function generate_structures(vm_context) -- Determine amount from perlin noise local amount = math_floor(perlin_structures:get_2d({x=x0, y=z0}) * 9) -- Find random positions based on this random - local p, ground_y + local p, ground_y, nn for i=0, amount do p = {x = pr:next(x0, x0 + DIVLEN - 1), y = 0, z = pr:next(z0, z0 + DIVLEN - 1)} p, ground_y, nn = determine_ground_level(p, vm_context) From 16116df4c67ffd1d1a98498a4cdc64039033001a Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 10 Jan 2022 19:35:04 +0400 Subject: [PATCH 29/61] Generate only desert seeds for some structs and lots of debugging glass blocks in the sky --- mods/MAPGEN/mcl_mapgen_core/structures.lua | 280 ++++++++++++++++----- 1 file changed, 212 insertions(+), 68 deletions(-) diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua index 39fc3dbd4..b18c31415 100644 --- a/mods/MAPGEN/mcl_mapgen_core/structures.lua +++ b/mods/MAPGEN/mcl_mapgen_core/structures.lua @@ -7,26 +7,28 @@ local DIVLEN = 5 local V6 = mcl_mapgen.v6 local math_min, math_max = math.min, math.max -local math_floor = math.floor +local math_floor, math_ceil = math.floor, math.ceil local minetest_get_node = minetest.get_node local minetest_get_mapgen_object = minetest.get_mapgen_object local minetest_find_nodes_in_area = minetest.find_nodes_in_area +local minetest_get_item_group = minetest.get_item_group local perlin_structures local function determine_ground_level(p, vm_context) - local emax = vm_context.emax - local emax_y = emax.y - local y = math_min(OVERWORLD_STRUCT_MAX, emax_y) - if y < emax_y then + local maxp = vm_context.maxp + local maxp_y = maxp.y + local y = math_min(OVERWORLD_STRUCT_MAX, maxp_y) + if y < maxp_y then y = y + 1 end p.y = y + local checknode = minetest_get_node(p) - if checknode.name ~= "air" then - return - end - for y = y - 1, math_max(OVERWORLD_STRUCT_MIN, vm_context.emin.y), -1 do + local nn = checknode.name + if nn ~= "air" and minetest_get_item_group(nn, "attached_node") == 0 and minetest_get_item_group(nn, "deco_block") == 0 then return end + + for y = y - 1, math_max(OVERWORLD_STRUCT_MIN, vm_context.minp.y), -1 do p.y = y local checknode = minetest_get_node(p) if checknode then @@ -57,53 +59,136 @@ end -- (in on_generated callback) and returns a biomemap index) -- Inverse function of biomemap_to_xz local function xz_to_biomemap_index(x, z, minp, maxp) - local xwidth = maxp.x - minp.x + 1 - local zwidth = maxp.z - minp.z + 1 - local minix = x % xwidth - local miniz = z % zwidth - - return (minix + miniz * zwidth) + 1 + local zstride = maxp.z - minp.z + 1 + return (z - minp.z) * zstride + (x - minp.x) + 1 end -local chunk_has_desert_struct -local chunk_has_igloo +--local chunk_has_desert_struct +--local chunk_has_desert_temple +--local chunk_has_igloo -local function spawn_desert_temples_and_desert_wells(p, nn, pr, vm_context) - if chunk_has_desert_struct or p.y < 5 then return end + + + +minetest.register_node("mcl_mapgen_core:desert_temple", { + -- drawtype="airlike", + tiles = {"mcl_core_stonebrick_carved.png"}, + groups = { + struct = 1, + not_in_creative_inventory = 1, + }, +}) + +local octaves = 3 +local persistence = 0.6 +local offset = 0 +local scale = 1 +local max_noise = 0 +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 - -- Spawn desert temple - if pr:next(1,12000) == 1 then - mcl_structures.call_struct(p, "desert_temple", nil, pr) - chunk_has_desert_struct = true - return true - end - -- Spawn desert well - local desert_well_prob = minecraft_chunk_probability(1000, vm_context.minp, vm_context.maxp) - if pr:next(1, desert_well_prob) ~= 1 then return end - -- Check surface - local surface = minetest_find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, {x=p.x+5, y=p.y-1, z=p.z+5}, "mcl_core:sand") - if #surface < 25 then return end - mcl_structures.call_struct(p, "desert_well", nil, pr) - chunk_has_desert_struct = true + -- if pr:next(1,12000) ~= 1 then return end + mcl_structures.call_struct(p, "desert_temple", nil, pr) return true end -local function spawn_igloos(p, nn, pr) - if chunk_has_igloo then return end - if nn ~= "mcl_core:snowblock" and nn ~= "mcl_core:snow" and minetest.get_item_group(nn, "grass_block_snow") ~= 1 then return end - if pr:next(1, 4400) ~= 1 then return end +local function spawn_desert_well(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 + local desert_well_prob = minecraft_chunk_probability(1000, vm_context.minp, vm_context.maxp) + -- if pr:next(1, desert_well_prob) ~= 1 then return end + local surface = minetest_find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, {x=p.x+5, y=p.y-1, z=p.z+5}, "mcl_core:sand") + if #surface < 25 then return end + mcl_structures.call_struct(p, "desert_well", nil, pr) + return true +end + +local function spawn_igloo(p, nn, pr, vm_context) + if nn ~= "mcl_core:snowblock" and nn ~= "mcl_core:snow" and minetest_get_item_group(nn, "grass_block_snow") ~= 1 then return end + -- if pr:next(1, 4400) ~= 1 then return end -- Check surface local floor = {x=p.x+9, y=p.y-1, z=p.z+9} - local surface = minetest_find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, floor, "mcl_core:snowblock") - local surface2 = minetest_find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, floor, "mcl_core:dirt_with_grass_snow") - if #surface + #surface2 < 63 then return end + local surface = minetest_find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, floor, {"mcl_core:snowblock", "mcl_core:dirt_with_grass_snow"}) + if #surface < 63 then return end mcl_structures.call_struct(p, "igloo", nil, pr) - chunk_has_igloo = true + -- chunk_has_igloo = true return true end local function spawn_fossil(p, nn, pr, vm_context) - if chunk_has_desert_struct or p.y > 4 then return end + -- if chunk_has_desert_temple or p.y < 4 then return end + if p.y < 4 then return end if nn ~= "mcl_core:sandstone" and nn ~= "mcl_core:sand" then return end local fossil_prob = minecraft_chunk_probability(64, vm_context.minp, vm_context.maxp) if pr:next(1, fossil_prob) ~= 1 then return end @@ -134,10 +219,12 @@ local witch_hut_offsets = { } local function spawn_witch_hut(p, nn, pr, vm_context) - if p.y <= 1 or nn ~= "mcl_core:dirt" then return end + minetest.log("warning", "p="..minetest.pos_to_string(p)..", nn="..nn) + -- if p.y > 1 or minetest_get_item_group(nn, "dirt") == 0 then return end local minp, maxp = vm_context.minp, vm_context.maxp local prob = minecraft_chunk_probability(48, minp, maxp) - if pr:next(1, prob) ~= 1 then return end + minetest.log("warning", "prob="..tostring(prob)) + -- if pr:next(1, prob) ~= 1 then return end -- Where do witches live? if V6 then @@ -147,13 +234,20 @@ local function spawn_witch_hut(p, nn, pr, vm_context) -- Other mapgens: In swampland biome local biomemap = vm_context.biomemap if not biomemap then - vm_context.biomemap = vm_context.biomemap or minetest_get_mapgen_object('biomemap') + vm_context.biomemap = minetest_get_mapgen_object('biomemap') biomemap = vm_context.biomemap end + -- minetest.chat_send_all(minetest.serialize(biomemap)) local swampland = minetest.get_biome_id("Swampland") local swampland_shore = minetest.get_biome_id("Swampland_shore") - local bi = xz_to_biomemap_index(p.x, p.z, minp, maxp) - if biomemap[bi] ~= swampland and biomemap[bi] ~= swampland_shore then return end + local bi = xz_to_biomemap_index(p.x, p.z, vm_context.minp, vm_context.maxp) + if (biomemap[bi] == swampland) then + minetest.chat_send_all('swampland') + end + if (biomemap[bi] == swampland_shore) then + minetest.chat_send_all('swampland_shore') + end + -- if biomemap[bi] ~= swampland and biomemap[bi] ~= swampland_shore then return end end local r = tostring(pr:next(0, 3) * 90) -- "0", "90", "180" or 270" @@ -237,7 +331,8 @@ end local function spawn_spikes_in_v6(p, nn, pr) -- In other mapgens, ice spikes are generated as decorations. - if chunk_has_igloo or nn ~= "mcl_core:snowblock" then return end + -- if chunk_has_igloo or nn ~= "mcl_core:snowblock" then return end + if nn ~= "mcl_core:snowblock" then return end local spike = pr:next(1,58000) if spike < 3 then return spawn_ice_spike_large(p, pr) @@ -247,31 +342,77 @@ local function spawn_spikes_in_v6(p, nn, pr) end local function generate_structures(vm_context) - local pr = PcgRandom(vm_context.blockseed) - perlin_structures = perlin_structures or minetest.get_perlin(329, 3, 0.6, 100) - chunk_has_desert_struct = false - chunk_has_igloo = false + +local levels = { + [-9] = "black", + [-8] = "brown", + [-7] = "brown", + [-6] = "gray", + [-5] = "gray", + [-4] = "red", + [-3] = "orange", + [-2] = "purple", + [-1] = "magenta", + [0] = "pink", + [1] = "yellow", + [2] = "green", + [3] = "lime", + [4] = "blue", + [5] = "cyan", + [6] = "light_blue", + [7] = "silver", + [8] = "silver", + [9] = "white", + } + + -- local pr = PcgRandom(vm_context.blockseed) + local pr = PcgRandom(vm_context.chunkseed) + -- chunk_has_desert_struct = false + -- chunk_has_desert_temple = false + -- chunk_has_igloo = false local minp, maxp = vm_context.minp, vm_context.maxp + perlin_structures = perlin_structures or minetest.get_perlin(329, 3, 0.6, 100) + -- Assume X and Z lengths are equal + local DIVLEN = 5 for x0 = minp.x, maxp.x, DIVLEN do for z0 = minp.z, maxp.z, DIVLEN do -- Determine amount from perlin noise - local amount = math_floor(perlin_structures:get_2d({x=x0, y=z0}) * 9) + local noise = perlin_structures:get_2d({x=x0, y=z0}) + local amount + if noise < 0 then + amount = math_ceil(noise * 9) + else + amount = math_floor(noise * 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 + end end + -- Find random positions based on this random local p, ground_y, nn - for i=0, amount do - p = {x = pr:next(x0, x0 + DIVLEN - 1), y = 0, z = pr:next(z0, z0 + DIVLEN - 1)} + for i = 0, 24 do + --for i=0, amount do + -- p = {x = pr:next(x0, x0 + DIVLEN - 1), y = 0, z = pr:next(z0, z0 + DIVLEN - 1)} + p = {x = x0 + i % 5, z = z0 + math_floor(i/5)} p, ground_y, nn = determine_ground_level(p, vm_context) if ground_y then p.y = ground_y + 1 local nn0 = minetest.get_node(p).name -- Check if the node can be replaced if minetest.registered_nodes[nn0] and minetest.registered_nodes[nn0].buildable_to then - if not spawn_desert_temples_and_desert_wells(p, nn, pr, vm_context) then - spawn_igloos(p, nn, pr, vm_context) - end - spawn_fossil(p, nn, pr, vm_context) - spawn_witch_hut(p, nn, pr, vm_context) + --spawn_desert_temple(p, nn, pr, vm_context) + --spawn_desert_well(p, nn, pr, vm_context) + --spawn_igloo(p, nn, pr, vm_context) + --spawn_fossil(p, nn, pr, vm_context) + --spawn_witch_hut(p, nn, pr, vm_context) if V6 then spawn_spikes_in_v6(p, nn, pr, vm_context) end @@ -301,15 +442,18 @@ local function generate_end_structures(vm_context) end if not mcl_mapgen.singlenode then - mcl_mapgen.register_on_generated(function(vm_context) - local minp, maxp = vm_context.minp, vm_context.maxp + mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) + -- mcl_mapgen.register_on_generated(function(vm_context) + -- local minp, maxp = vm_context.minp, vm_context.maxp + local minp, maxp = minp, maxp local minp_y, maxp_y = minp.y, maxp.y - if maxp_y >= OVERWORLD_STRUCT_MIN and minp_y <= OVERWORLD_STRUCT_MAX then - return generate_structures(vm_context) + generate_structures(vm_context) +-- if maxp_y >= OVERWORLD_STRUCT_MIN and minp_y <= OVERWORLD_STRUCT_MAX then +-- return generate_structures(vm_context) -- End exit portal - elseif maxp_y >= END_STRUCT_MIN and minp_y <= END_STRUCT_MAX then - return generate_end_structures(vm_context) - end - return vm_context +-- elseif maxp_y >= END_STRUCT_MIN and minp_y <= END_STRUCT_MAX then +-- return generate_end_structures(vm_context) +-- end +-- return vm_context end) end From c6754fd39ecf6ac5558f51f7f174f8cd0c76bcc4 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 12 Jan 2022 03:27:28 +0400 Subject: [PATCH 30/61] Start adding new structures API --- mods/CORE/mcl_mapgen/API.md | 2 +- mods/ITEMS/mcl_portals/portal_gateway.lua | 12 +- mods/MAPGEN/mcl_end_island/init.lua | 18 ++- mods/MAPGEN/mcl_structures/init.lua | 132 +++++++++++++++++----- mods/MAPGEN/mcl_structures/mod.conf | 6 +- mods/MAPGEN/mcl_villages/buildings.lua | 18 ++- 6 files changed, 131 insertions(+), 57 deletions(-) diff --git a/mods/CORE/mcl_mapgen/API.md b/mods/CORE/mcl_mapgen/API.md index 1587e19f4..bcd6d2f8f 100644 --- a/mods/CORE/mcl_mapgen/API.md +++ b/mods/CORE/mcl_mapgen/API.md @@ -71,7 +71,7 @@ Registers callback function to be called when current chunk generation is REALLY For LVM it's the most frustrating function from this mod. It can't provide you access to mapgen objects. They are probably gone long ago. Don't use it for accessing mapgen objects please. -To use VM you have to run `vm_context.vm = minetest.get_voxel_manip(vm_context.emin, vm_context.emax)`. +To use VM you have to run `vm_context.vm = mcl_mapgen.get_voxel_manip(vm_context.emin, vm_context.emax)`. Set `callback_function`: callback function definition: `function(minp, maxp, seed, vm_context)`: diff --git a/mods/ITEMS/mcl_portals/portal_gateway.lua b/mods/ITEMS/mcl_portals/portal_gateway.lua index ca15a61d5..48d2b52fd 100644 --- a/mods/ITEMS/mcl_portals/portal_gateway.lua +++ b/mods/ITEMS/mcl_portals/portal_gateway.lua @@ -29,9 +29,15 @@ local gateway_positions = { local path_gateway_portal = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_end_gateway_portal.mts" local function spawn_gateway_portal(pos, dest_str) - return mcl_structures.place_schematic(vector.add(pos, vector.new(-1, -2, -1)), path_gateway_portal, "0", nil, true, nil, dest_str and function() - minetest.get_meta(pos):set_string("mcl_portals:gateway_destination", dest_str) - end) + return mcl_structures.place_schematic({ + pos = vector.add(pos, vector.new(-1, -2, -1)), + schematic = path_gateway_portal, + rotation = "0", + force_placement = true, + after_place = dest_str and function() + minetest.get_meta(pos):set_string("mcl_portals:gateway_destination", dest_str) + end, + }) end function mcl_portals.spawn_gateway_portal() diff --git a/mods/MAPGEN/mcl_end_island/init.lua b/mods/MAPGEN/mcl_end_island/init.lua index b0e5e68eb..5a0bde2c7 100644 --- a/mods/MAPGEN/mcl_end_island/init.lua +++ b/mods/MAPGEN/mcl_end_island/init.lua @@ -10,25 +10,21 @@ local noisemap = PerlinNoiseMap({ local c_end_stone = minetest.get_content_id("mcl_end:end_stone") local y_offset = -2 -mcl_mapgen.register_mapgen(function(minp, maxp) +mcl_mapgen.register_on_generated(function(vm_context) + local minp, maxp = vm_context.minp, vm_context.maxp if maxp.y < (-27025 + y_offset) or minp.y > (-27000 + y_offset + 4) or maxp.x < -75 or minp.x > 75 or maxp.z < -75 or minp.z > 75 then return end - - local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") - local data = vm:get_data() - local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax}) - + local data = vm_context.data + local area = vm_context.area + local write = false for idx in area:iter(math.max(minp.x, -75), math.max(minp.y, -27025 + y_offset + 4), math.max(minp.z, -75), math.min(maxp.x, 75), math.min(maxp.y, -27000 + y_offset), math.min(maxp.z, 75)) do local pos = area:position(idx) local y = 27025 + pos.y - y_offset if noisemap[pos.x + 75 + 1][y + 1][pos.z + 75 + 1] > (math.abs(1 - y / 25) ^ 2 + math.abs(pos.x / 75) ^ 2 + math.abs(pos.z / 75) ^ 2) then data[idx] = c_end_stone + write = true end end - - vm:set_data(data) - vm:calc_lighting() - vm:update_liquids() - vm:write_to_map() + vm_context.write = vm_context.write or write end) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index bb9e5e8df..d54cd600f 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -11,37 +11,106 @@ local rotations = { "270" } -local function ecb_place(blockpos, action, calls_remaining, param) - if calls_remaining >= 1 then return end - minetest.place_schematic(param.pos, param.schematic, param.rotation, param.replacements, param.force_placement, param.flags) - if param.after_placement_callback and param.p1 and param.p2 then - param.after_placement_callback(param.p1, param.p2, param.size, param.rotation, param.pr, param.callback_param) +local registered_structures = {} + +function mcl_structures.register_structure(def) + local name = def.name + if not name then + minetest.log('warning', 'Structure name is not passed for registering - ignoring') + return end + if registered_structures[name] then + minetest.log('warning', 'Structure '..name..' is already registered - owerwriting') + end + registered_structures[name] = { + on_place = def.on_place, + decoration = def.decoration, + on_mapgen_prep = def.on_mapgen_prep, + on_generated = def.on_generated, + } end -function mcl_structures.place_schematic(pos, schematic, rotation, replacements, force_placement, flags, after_placement_callback, pr, callback_param) - local s = loadstring(minetest.serialize_schematic(schematic, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic")() - if s and s.size then - local x, z = s.size.x, s.size.z - if rotation then - if rotation == "random" and pr then - rotation = rotations[pr:next(1,#rotations)] - end - if rotation == "random" then - x = math.max(x, z) - z = x - elseif rotation == "90" or rotation == "270" then - x, z = z, x - end - end - local p1 = {x=pos.x , y=pos.y , z=pos.z } - local p2 = {x=pos.x+x-1, y=pos.y+s.size.y-1, z=pos.z+z-1} - minetest.log("verbose", "[mcl_structures] size=" ..minetest.pos_to_string(s.size) .. ", rotation=" .. tostring(rotation) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2)) - local param = {pos=vector.new(pos), schematic=s, rotation=rotation, replacements=replacements, force_placement=force_placement, flags=flags, p1=p1, p2=p2, after_placement_callback = after_placement_callback, size=vector.new(s.size), pr=pr, callback_param=callback_param} - -- minetest.emerge_area(p1, p2, ecb_place, param) - -- TODO: Make it better - ecb_place(0, 0, 0, param) +function mcl_structures.unregister_structure(name) + if not registered_structures[name] then + minetest.log('warning','Structure '..name..' is not registered - skipping') + return end + registered_structures[name] = nil +end + +local function ecb_place(blockpos, action, calls_remaining, param) + if calls_remaining >= 1 then return end + local pos = param.pos + local rotation = param.rotation + minetest.place_schematic(pos, param.schematic, rotation, param.replacements, param.force_placement, param.flags) + local after_place = param.after_place + if not after_place then + return + end + after_place(pos, rotation, param.pr, param.param, param.size) +end + +function mcl_structures.place_schematic(def) + local pos = def.pos + local schematic = def.schematic + local rotation = def.rotation + local pr = def.pr + if not pos then + minetest.log('warning', '[mcl_structures] No pos. specified to place schematic') + return + end + if not schematic then + minetest.log('warning', '[mcl_structures] No schematic specified to place at ' .. minetest.pos_to_string(pos)) + return + end + if not rotation or rotation == 'random' then + if pr then + rotation = rotations[pr:next(1,#rotations)] + else + rotation = rotations[math.random(1,#rotations)] + end + end + if not def.emerge then + minetest.place_schematic(pos, schematic, rotation, def.replacements, def.force_placement, def.flags) + if not def.after_place then + return + end + def.after_place(pos, rotation, pr, def.after_place_param) + return + end + + local loaded_schematic = loadstring(minetest.serialize_schematic(schematic, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic")() + if not loaded_schematic then + minetest.log('warning', '[mcl_structures] Schematic ' .. schematic .. ' load serialized string problem at ' .. minetest.pos_to_string(pos)) + return + end + local size = loaded_schematic.size + if not size then + minetest.log('warning', '[mcl_structures] Schematic ' .. schematic .. ' has no size at ' .. minetest.pos_to_string(pos)) + return + end + local size_x, size_y, size_z = size.x, size.y, size.z + if rotation == "90" or rotation == "270" then + size_x, size_z = size_z, size_x + end + local x, y, z = pos.x, pos.y, pos.z + local p1 = {x = x, y = y, z = z} + local p2 = {x = x + size_x - 1, y = y + size_y - 1, z = size_z - 1} + minetest.log("verbose", "[mcl_structures] Emerge area " .. minetest.pos_to_string(p1) .. " - " .. minetest.pos_to_string(p2) + .. " of size " ..minetest.pos_to_string(size) .. " to place " .. schematic .. ", rotation " .. tostring(rotation)) + local ecb_param = { + pos = vector.new(pos), + schematic = loaded_schematic, + rotation = rotation, + replacements = replacements, + force_placement = force_placement, + flags = flags, + after_place = after_place, + size = vector.new(size), + pr = pr, + param = param, + } + minetest.emerge_area(p1, p2, ecb_place, ecb_param) end function mcl_structures.get_struct(file) @@ -124,7 +193,12 @@ end function mcl_structures.generate_desert_well(pos, rot) local newpos = {x=pos.x,y=pos.y-2,z=pos.z} local path = modpath.."/schematics/mcl_structures_desert_well.mts" - return mcl_structures.place_schematic(newpos, path, rot or "0", nil, true) + return mcl_structures.place_schematic({ + pos = newpos, + schematic = path, + rotation = rot or "0", + force_placement = true + }) end function mcl_structures.generate_igloo(pos, rotation, pr) @@ -227,7 +301,7 @@ end function mcl_structures.generate_igloo_top(pos, pr) -- FIXME: This spawns bookshelf instead of furnace. Fix this! - -- Furnace does ot work atm because apparently meta is not set. :-( + -- Furnace does not work atm because apparently meta is not set. :-( local newpos = {x=pos.x,y=pos.y-1,z=pos.z} local path = modpath.."/schematics/mcl_structures_igloo_top.mts" local rotation = tostring(pr:next(0,3)*90) diff --git a/mods/MAPGEN/mcl_structures/mod.conf b/mods/MAPGEN/mcl_structures/mod.conf index 3150c7cec..f22f7c738 100644 --- a/mods/MAPGEN/mcl_structures/mod.conf +++ b/mods/MAPGEN/mcl_structures/mod.conf @@ -1,4 +1,4 @@ name = mcl_structures -author = Wuzzy -description = Structures for MCL2 -depends = mcl_loot +author = Wuzzy, kay27 +description = Structures for MineClone 2/5 +depends = mcl_loot, mcl_mapgen diff --git a/mods/MAPGEN/mcl_villages/buildings.lua b/mods/MAPGEN/mcl_villages/buildings.lua index 69b1c84da..7c70e1d3b 100644 --- a/mods/MAPGEN/mcl_villages/buildings.lua +++ b/mods/MAPGEN/mcl_villages/buildings.lua @@ -268,15 +268,13 @@ function settlements.place_schematics(settlement_info, pr) local schematic = loadstring(schem_lua)() -- build foundation for the building an make room above -- place schematic - mcl_structures.place_schematic( - pos, - schematic, - rotation, - nil, - true, - nil, - init_nodes, - pr - ) + mcl_structures.place_schematic({ + pos = pos, + schematic = schematic, + rotation = rotation, + force_placement = true, + on_place = init_nodes, + pr = pr, + }) end end From 9d171a6b7ba7dff7f97b0f14d3c72ab38cd2648e Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 12 Jan 2022 04:02:56 +0400 Subject: [PATCH 31/61] Fix Nether roof light --- mods/CORE/mcl_mapgen/API.md | 2 +- mods/MAPGEN/mcl_mapgen_core/init.lua | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mods/CORE/mcl_mapgen/API.md b/mods/CORE/mcl_mapgen/API.md index bcd6d2f8f..fed1fd1d8 100644 --- a/mods/CORE/mcl_mapgen/API.md +++ b/mods/CORE/mcl_mapgen/API.md @@ -25,7 +25,7 @@ See https://git.minetest.land/MineClone2/MineClone2/issues/1395 `vm_context.data2 = vm_context.data2 or vm_context.vm.get_param2_data(vm_context.lvm_param2_buffer)` `write_param2`: set it to true in your lvm callback function, if you used `data2` and want to write it; `light`: LVM buffer data array of light, !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourself: - `vm_context.light = vm_context.light or vm_context.vm.get_light2_data(vm_context.lvm_light_buffer)` + `vm_context.light = vm_context.light or vm_context.vm.get_light_data(vm_context.lvm_light_buffer)` `write_light`: set it to true in your lvm callback function, if you used `light` and want to write it; `lvm_param2_buffer`: static `param2` buffer pointer, used to load `data2` array; `shadow`: set it to false to disable shadow propagation; diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index e50a2d4d4..f36bf8b9a 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1832,3 +1832,15 @@ dofile(modpath .. "/clay.lua") if minetest.get_modpath("mcl_structures") then dofile(modpath .. "/structures.lua") end + +mcl_mapgen.register_mapgen_block_lvm(function(vm_context) + local minp = vm_context.minp + local miny = minp.y + if miny > mcl_mapgen.nether.max+127 then return end + local maxp = vm_context.maxp + local maxy = maxp.y + if maxy <= mcl_mapgen.nether.max then return end + local p1 = {x = minp.x, y = math.max(miny, mcl_mapgen.nether.max + 1), z = minp.z} + local p2 = {x = maxp.x, y = math.min(maxy, mcl_mapgen.nether.max + 127), z = maxp.z} + vm_context.vm:set_lighting({day=15, night=15}, p1, p2) +end, 999999999) From 096b38467644e132548ac1588b546d83ef15859e Mon Sep 17 00:00:00 2001 From: kay27 Date: Fri, 14 Jan 2022 04:25:39 +0400 Subject: [PATCH 32/61] 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 = {} From e2928c4afcf94f061faf1577010286f53cc17b40 Mon Sep 17 00:00:00 2001 From: kay27 Date: Sat, 15 Jan 2022 08:04:43 +0400 Subject: [PATCH 33/61] Add red desert temples --- mods/MAPGEN/mcl_mapgen_core/structures.lua | 58 ++++++++++++++++++++++ mods/MAPGEN/mcl_structures/init.lua | 34 +++++++++---- 2 files changed, 83 insertions(+), 9 deletions(-) diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua index b000f77f4..f265e5e74 100644 --- a/mods/MAPGEN/mcl_mapgen_core/structures.lua +++ b/mods/MAPGEN/mcl_mapgen_core/structures.lua @@ -15,6 +15,8 @@ local minetest_get_item_group = minetest.get_item_group local perlin_structures +local schematic_path = minetest.get_modpath('mcl_structures') + local function determine_ground_level(p, vm_context) local maxp = vm_context.maxp local maxp_y = maxp.y @@ -123,6 +125,62 @@ mcl_structures.register_structure({ 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 diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 3bea78cef..b48c7cbda 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -17,7 +17,6 @@ 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 @@ -29,13 +28,20 @@ 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 + for node_name, pos_list in pairs(nodes) do + for _, pos in pairs(pos_list) do + local node = minetest.get_node(pos) + if string.sub(node.name, 1, 15) == 'mcl_structures:' then + minetest.swap_node(pos, {name = 'air'}) + end + end + end end -------------------------------------------------------------------------------------- @@ -106,7 +112,6 @@ function mcl_structures.register_structure(def) 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 @@ -137,10 +142,12 @@ local function ecb_place(blockpos, action, calls_remaining, param) end function mcl_structures.place_schematic(def) - local pos = def.pos - local schematic = def.schematic - local rotation = def.rotation - local pr = def.pr + local pos = def.pos + local schematic = def.schematic + local rotation = def.rotation + local pr = def.pr + local on_schematic_loaded = def.on_schematic_loaded + local emerge = def.emerge if not pos then minetest.log('warning', '[mcl_structures] No pos. specified to place schematic') return @@ -156,7 +163,8 @@ function mcl_structures.place_schematic(def) rotation = rotations[math.random(1,#rotations)] end end - if not def.emerge then + + if not emerge and not on_schematic_loaded then minetest.place_schematic(pos, schematic, rotation, def.replacements, def.force_placement, def.flags) if not def.after_place then return @@ -165,7 +173,11 @@ function mcl_structures.place_schematic(def) return end - local loaded_schematic = loadstring(minetest.serialize_schematic(schematic, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic")() + local serialized_schematic = minetest.serialize_schematic(schematic, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic" + if on_schematic_loaded then + serialized_schematic = on_schematic_loaded(serialized_schematic) + end + local loaded_schematic = loadstring(serialized_schematic)() if not loaded_schematic then minetest.log('warning', '[mcl_structures] Schematic ' .. schematic .. ' load serialized string problem at ' .. minetest.pos_to_string(pos)) return @@ -196,6 +208,10 @@ function mcl_structures.place_schematic(def) pr = pr, param = param, } + if not emerge then + ecb_place(p1, nil, 0, ecb_param) + return + end minetest.emerge_area(p1, p2, ecb_place, ecb_param) end From 37725cc1dcab0b705a418e3b9b18f300ad27da21 Mon Sep 17 00:00:00 2001 From: kay27 Date: Sat, 15 Jan 2022 20:32:48 +0400 Subject: [PATCH 34/61] 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") From 95fd9e9105649f254f85a0adcf98b2d7cface03b Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 16 Jan 2022 04:46:07 +0400 Subject: [PATCH 35/61] Flush current work on spawnstruct, refactor strongholds --- mods/CORE/mcl_mapgen/init.lua | 15 ++ mods/MAPGEN/mcl_strongholds/init.lua | 103 --------- mods/MAPGEN/mcl_strongholds/mod.conf | 4 - mods/MAPGEN/mcl_structures/desert_temple.lua | 4 +- mods/MAPGEN/mcl_structures/init.lua | 222 ++++++------------- mods/MAPGEN/mcl_structures/structures.lua | 1 + 6 files changed, 81 insertions(+), 268 deletions(-) delete mode 100644 mods/MAPGEN/mcl_strongholds/init.lua delete mode 100644 mods/MAPGEN/mcl_strongholds/mod.conf diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 586545e73..f34211b06 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -463,3 +463,18 @@ function mcl_mapgen.get_voxel_manip(vm_context) vm_context.area = VoxelArea:new({MinEdge=vm_context.emin, MaxEdge=vm_context.emax}) return vm_context.vm end + +local CS_NODES = mcl_mapgen.CS_NODES +function mcl_mapgen.clamp_to_chunk(x, size) + if size > CS_NODES then + minetest.log("warning", "[mcl_mapgen] Couldn't clamp " .. tostring(x) .. " - given size " .. tostring(size) .. " greater than chunk size " .. tostring(mcl_mapgen.CS_NODES)) + return x + end + local offset_in_chunk = (x + central_chunk_min_pos) % CS_NODES + local x2_in_chunk = offset_in_chunk + size + if x2_in_chunk <= CS_NODES then + return x + end + local overflow = x2_in_chunk - CS_NODES + return x - overflow +end diff --git a/mods/MAPGEN/mcl_strongholds/init.lua b/mods/MAPGEN/mcl_strongholds/init.lua deleted file mode 100644 index db48a93ae..000000000 --- a/mods/MAPGEN/mcl_strongholds/init.lua +++ /dev/null @@ -1,103 +0,0 @@ --- Generate strongholds. - --- A total of 128 strongholds are generated in rings around the world origin. --- This is the list of rings, starting with the innermost ring first. -local stronghold_rings = { - -- amount: Number of strongholds in ring. - -- min, max: Minimum and maximum distance from (X=0, Z=0). - { amount = 3, min = 1408, max = 2688 }, - { amount = 6, min = 4480, max = 5760 }, - { amount = 10, min = 7552, max = 8832 }, - { amount = 15, min = 10624, max = 11904 }, - { amount = 21, min = 13696, max = 14976 }, - { amount = 28, min = 16768, max = 18048 }, - { amount = 36, min = 19840, max = 21120 }, - { amount = 9, min = 22912, max = 24192 }, -} - -local strongholds = {} -local strongholds_inited = false - -local superflat = mcl_mapgen.superflat - --- Determine the stronghold positions and store them into the strongholds table. --- The stronghold positions are based on the world seed. --- The actual position might be offset by a few blocks because it might be shifted --- to make sure the end portal room is completely within the boundaries of a mapchunk. -local function init_strongholds() - if strongholds_inited then - return - end - -- Don't generate strongholds in singlenode - if mcl_mapgen.singlenode then - strongholds_inited = true - return - end - local seed = tonumber(minetest.get_mapgen_setting("seed")) - local pr = PseudoRandom(seed) - for s=1, #stronghold_rings do - local ring = stronghold_rings[s] - - -- Get random angle - local angle = pr:next() - -- Scale angle to 0 .. 2*math.pi - angle = (angle / 32767) * (math.pi*2) - for a=1, ring.amount do - local dist = pr:next(ring.min, ring.max) - local y - if superflat then - y = mcl_mapgen.overworld.bedrock_max + 3 - else - y = pr:next(mcl_mapgen.overworld.bedrock_max+1, mcl_mapgen.overworld.bedrock_min+48) - end - local pos = { x = math.cos(angle) * dist, y = y, z = math.sin(angle) * dist } - pos = vector.round(pos) - table.insert(strongholds, { pos = pos, generated = false }) - - -- Rotate angle by (360 / amount) degrees. - -- This will cause the angles to be evenly distributed in the stronghold ring - angle = math.fmod(angle + ((math.pi*2) / ring.amount), math.pi*2) - end - end - - mcl_structures.register_structures("stronghold", table.copy(strongholds)) - - strongholds_inited = true -end - -init_strongholds() - --- Stronghold generation for register_on_generated. -mcl_mapgen.register_mapgen(function(minp, maxp, blockseed) - local pr = PseudoRandom(blockseed) - for s=1, #strongholds do - if not strongholds[s].generated then - local pos = strongholds[s].pos - if minp.x <= pos.x and maxp.x >= pos.x and minp.z <= pos.z and maxp.z >= pos.z and minp.y <= pos.y and maxp.y >= pos.y then - -- Make sure the end portal room is completely within the current mapchunk - -- The original pos is changed intentionally. - if pos.x - 6 < minp.x then - pos.x = minp.x + 7 - end - if pos.x + 6 > maxp.x then - pos.x = maxp.x - 7 - end - if pos.y - 4 < minp.y then - pos.y = minp.y + 5 - end - if pos.y + 4 > maxp.y then - pos.y = maxp.y - 5 - end - if pos.z - 6 < minp.z then - pos.z = minp.z + 7 - end - if pos.z + 6 > maxp.z then - pos.z = maxp.z - 7 - end - - mcl_structures.call_struct(pos, "end_portal_shrine", nil, pr) - strongholds[s].generated = true - end - end - end -end, mcl_mapgen.order.STRONGHOLDS) diff --git a/mods/MAPGEN/mcl_strongholds/mod.conf b/mods/MAPGEN/mcl_strongholds/mod.conf deleted file mode 100644 index 8edec9a51..000000000 --- a/mods/MAPGEN/mcl_strongholds/mod.conf +++ /dev/null @@ -1,4 +0,0 @@ -name = mcl_strongholds -author = Wuzzy -description = Generates strongholds with end portals in the Overworld -depends = mcl_init, mcl_structures, mcl_mapgen_core diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua index c0dbd3ca8..7ca637900 100644 --- a/mods/MAPGEN/mcl_structures/desert_temple.lua +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -66,7 +66,7 @@ mcl_structures.register_structure({ "Taiga_beach", }, }, - on_generated = function(minp, maxp, seed, vm_context, pos_list) + on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) local pos = pos_list[1] if #pos_list > 1 then local count = node_counter(pos) @@ -82,5 +82,5 @@ mcl_structures.register_structure({ local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, - on_place = place, + place_function = place, }) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 7bdc72f8a..44c876564 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -2,6 +2,8 @@ local modname = minetest.get_current_modname() local S = minetest.get_translator(modname) local modpath = minetest.get_modpath(modname) +local name_prefix = "mcl_structures:" + mcl_structures = {} local rotations = { "0", @@ -12,13 +14,13 @@ local rotations = { local registered_structures = {} local use_process_mapgen_block_lvm = false local use_process_mapgen_chunk = false -local lvm_callbacks = {} -local chunk_callbacks = {} +local on_finished_block_callbacks = {} +local on_finished_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) for node_name, pos_list in pairs(nodes) do - local lvm_callback = lvm_callbacks[node_name] + local lvm_callback = on_finished_block_callbacks[node_name] if lvm_callback then lvm_callback(vm_context, pos_list) end @@ -29,7 +31,7 @@ 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)) for node_name, pos_list in pairs(nodes) do - local chunk_callback = chunk_callbacks[node_name] + local chunk_callback = on_finished_chunk_callbacks[node_name] if chunk_callback then chunk_callback(minp, maxp, seed, vm_context, pos_list) end @@ -47,17 +49,18 @@ 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) +-- name - name like 'desert_temple' +-- decoration - decoration definition if needed +-- on_finished_block - callback if needed +-- on_finished_chunk - next callback if needed +-- place_function - placer function(pos, rotation, pr) +-- order_number - (optional) function mcl_structures.register_structure(def) - local name = "mcl_structures:" .. def.name - local decoration = def.decoration - local on_mapgen_prep = def.on_mapgen_prep - local on_generated = def.on_generated + local short_name = def.name + local name = "mcl_structures:" .. short_name + local decoration = def.decoration + local on_finished_block = def.on_finished_block + local on_finished_chunk = def.on_finished_chunk if not name then minetest.log('warning', 'Structure name is not passed for registration - ignoring') return @@ -99,20 +102,21 @@ function mcl_structures.register_structure(def) }) end registered_structures[name] = { - on_place = def.on_place, - on_mapgen_prep = on_mapgen_prep, - on_generated = on_generated, - decoration_id = decoration_id, + place_function = def.place_function, + on_finished_block = on_finished_block, + on_finished_chunk = on_finished_chunk, + decoration_id = decoration_id, + short_name = short_name, } - if on_mapgen_prep then - lvm_callbacks[name] = on_mapgen_prep + if on_finished_block then + on_finished_block_callbacks[name] = on_finished_block 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 - chunk_callbacks[name] = on_generated + if on_finished_chunk then + on_finished_chunk_callbacks[name] = on_finished_chunk if not use_process_mapgen_chunk then use_process_mapgen_chunk = true mcl_mapgen.register_mapgen(process_mapgen_chunk, mcl_mapgen.order.BUILDINGS) @@ -535,93 +539,6 @@ function mcl_structures.generate_end_gateway_portal(pos, rot) return mcl_structures.place_schematic(pos, path, rot or "0", nil, true) end -local function shrine_placement_callback(p1, p2, size, rotation, pr) - -- Find and setup spawner with silverfish - local spawners = minetest.find_nodes_in_area(p1, p2, "mcl_mobspawners:spawner") - for s=1, #spawners do - --local meta = minetest.get_meta(spawners[s]) - mcl_mobspawners.setup_spawner(spawners[s], "mobs_mc:silverfish") - end - - -- Shuffle stone brick types - local bricks = minetest.find_nodes_in_area(p1, p2, "mcl_core:stonebrick") - for b=1, #bricks do - local r_bricktype = pr:next(1, 100) - local r_infested = pr:next(1, 100) - local bricktype - if r_infested <= 5 then - if r_bricktype <= 30 then -- 30% - bricktype = "mcl_monster_eggs:monster_egg_stonebrickmossy" - elseif r_bricktype <= 50 then -- 20% - bricktype = "mcl_monster_eggs:monster_egg_stonebrickcracked" - else -- 50% - bricktype = "mcl_monster_eggs:monster_egg_stonebrick" - end - else - if r_bricktype <= 30 then -- 30% - bricktype = "mcl_core:stonebrickmossy" - elseif r_bricktype <= 50 then -- 20% - bricktype = "mcl_core:stonebrickcracked" - end - -- 50% stonebrick (no change necessary) - end - if bricktype then - minetest.set_node(bricks[b], { name = bricktype }) - end - end - - -- Also replace stairs - local stairs = minetest.find_nodes_in_area(p1, p2, {"mcl_stairs:stair_stonebrick", "mcl_stairs:stair_stonebrick_outer", "mcl_stairs:stair_stonebrick_inner"}) - for s=1, #stairs do - local stair = minetest.get_node(stairs[s]) - local r_type = pr:next(1, 100) - if r_type <= 30 then -- 30% mossy - if stair.name == "mcl_stairs:stair_stonebrick" then - stair.name = "mcl_stairs:stair_stonebrickmossy" - elseif stair.name == "mcl_stairs:stair_stonebrick_outer" then - stair.name = "mcl_stairs:stair_stonebrickmossy_outer" - elseif stair.name == "mcl_stairs:stair_stonebrick_inner" then - stair.name = "mcl_stairs:stair_stonebrickmossy_inner" - end - minetest.set_node(stairs[s], stair) - elseif r_type <= 50 then -- 20% cracky - if stair.name == "mcl_stairs:stair_stonebrick" then - stair.name = "mcl_stairs:stair_stonebrickcracked" - elseif stair.name == "mcl_stairs:stair_stonebrick_outer" then - stair.name = "mcl_stairs:stair_stonebrickcracked_outer" - elseif stair.name == "mcl_stairs:stair_stonebrick_inner" then - stair.name = "mcl_stairs:stair_stonebrickcracked_inner" - end - minetest.set_node(stairs[s], stair) - end - -- 50% no change - end - - -- Randomly add ender eyes into end portal frames, but never fill the entire frame - local frames = minetest.find_nodes_in_area(p1, p2, "mcl_portals:end_portal_frame") - local eyes = 0 - for f=1, #frames do - local r_eye = pr:next(1, 10) - if r_eye == 1 then - eyes = eyes + 1 - if eyes < #frames then - local frame_node = minetest.get_node(frames[f]) - frame_node.name = "mcl_portals:end_portal_frame_eye" - minetest.set_node(frames[f], frame_node) - end - end - end -end - -function mcl_structures.generate_end_portal_shrine(pos, rotation, pr) - local offset = {x=6, y=4, z=6} - --local size = {x=13, y=8, z=13} - local newpos = { x = pos.x - offset.x, y = pos.y, z = pos.z - offset.z } - - local path = modpath.."/schematics/mcl_structures_end_portal_room_simple.mts" - mcl_structures.place_schematic(newpos, path, rotation or "0", nil, true, nil, shrine_placement_callback, pr) -end - local function temple_placement_callback(p1, p2, size, rotation, pr) -- Delete cacti leftovers: @@ -710,7 +627,7 @@ function mcl_structures.generate_desert_temple(pos, rotation, pr) mcl_structures.place_schematic({pos = pos, schematic = path, rotation = rotation or "random", pr = pr, emerge = true}) end -local registered_structures = {} +--local registered_structures = {} --[[ Returns a table of structure of the specified type. Currently the only valid parameter is "stronghold". @@ -723,6 +640,7 @@ Format of return value: TODO: Implement this function for all other structure types as well. ]] +--[[ function mcl_structures.get_registered_structures(structure_type) if registered_structures[structure_type] then return table.copy(registered_structures[structure_type]) @@ -730,13 +648,14 @@ function mcl_structures.get_registered_structures(structure_type) return {} end end - +]] -- Register a structures table for the given type. The table format is the same as for -- mcl_structures.get_registered_structures. +--[[ function mcl_structures.register_structures(structure_type, structures) registered_structures[structure_type] = structures end - +]] local function dir_to_rotation(dir) local ax, az = math.abs(dir.x), math.abs(dir.z) if ax > az then @@ -751,64 +670,49 @@ local function dir_to_rotation(dir) return "0" end + +dofile(modpath .. "/structures.lua") + -- Debug command +local spawnstruct_params = "" +for _, registered_structure in pairs(registered_structures) do + if spawnstruct_params ~= "" then + spawnstruct_params = spawnstruct_params .. " | " + end + spawnstruct_params = spawnstruct_params .. registered_structure.short_name +end +local spawnstruct_hint = S("Use /help spawnstruct to see a list of avaiable types.") minetest.register_chatcommand("spawnstruct", { - params = "desert_temple | desert_well | igloo | witch_hut | boulder | ice_spike_small | ice_spike_large | fossil | end_exit_portal | end_exit_portal_open | end_gateway_portal | end_portal_shrine | end_portal | nether_portal | dungeon", + params = spawnstruct_params, description = S("Generate a pre-defined structure near your position."), privs = {debug = true}, func = function(name, param) local player = minetest.get_player_by_name(name) if not player then return end + if param == "" then + minetest.chat_send_player(name, S("Error: No structure type given. Please use “/spawnstruct ”.")) + minetest.chat_send_player(name, spawnstruct_hint) + return + end + local struct = registered_structures[param] + if not struct then + struct = registered_structures[name_prefix .. param] + end + if not struct then + minetest.chat_send_player(name, S("Error: Unknown structure type. Please use “/spawnstruct ”.")) + minetest.chat_send_player(name, spawnstruct_hint) + return + end + local place = struct.place_function + if not place then return end + local pos = player:get_pos() if not pos then return end + local pr = PseudoRandom(math.floor(pos.x * 333 + pos.y * 19 - pos.z + 4)) pos = vector.round(pos) local dir = minetest.yaw_to_dir(player:get_look_horizontal()) local rot = dir_to_rotation(dir) - local pr = PseudoRandom(pos.x+pos.y+pos.z) - local errord = false - local message = S("Structure placed.") - if param == "desert_temple" then - mcl_structures.generate_desert_temple(pos, rot, pr) - elseif param == "desert_well" then - mcl_structures.generate_desert_well(pos, rot) - elseif param == "igloo" then - mcl_structures.generate_igloo(pos, rot, pr) - elseif param == "witch_hut" then - mcl_structures.generate_witch_hut(pos, rot, pr) - elseif param == "boulder" then - mcl_structures.generate_boulder(pos, rot, pr) - elseif param == "fossil" then - mcl_structures.generate_fossil(pos, rot, pr) - elseif param == "ice_spike_small" then - mcl_structures.generate_ice_spike_small(pos, rot, pr) - elseif param == "ice_spike_large" then - mcl_structures.generate_ice_spike_large(pos, rot, pr) - elseif param == "end_exit_portal" then - mcl_structures.generate_end_exit_portal(pos, rot, pr) - elseif param == "end_exit_portal_open" then - mcl_structures.generate_end_exit_portal_open(pos, rot, pr) - elseif param == "end_gateway_portal" then - mcl_structures.generate_end_gateway_portal(pos, rot, pr) - elseif param == "end_portal_shrine" then - mcl_structures.generate_end_portal_shrine(pos, rot, pr) - elseif param == "dungeon" and mcl_dungeons and mcl_dungeons.spawn_dungeon then - mcl_dungeons.spawn_dungeon(pos, rot, pr) - elseif param == "end_portal" then - mcl_structures.generate_end_portal(pos, rot, pr) - elseif param == "nether_portal" and mcl_portals and mcl_portals.spawn_nether_portal then - mcl_portals.spawn_nether_portal(pos, rot, pr, name) - elseif param == "" then - message = S("Error: No structure type given. Please use “/spawnstruct ”.") - errord = true - else - message = S("Error: Unknown structure type. Please use “/spawnstruct ”.") - errord = true - end - minetest.chat_send_player(name, message) - if errord then - minetest.chat_send_player(name, S("Use /help spawnstruct to see a list of avaiable types.")) - end + place(pos, rot, pr) + minetest.chat_send_player(name, S("Structure placed.")) end }) - -dofile(modpath .. "/structures.lua") diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index 4039ef6e1..c0f1b3d3e 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -2,3 +2,4 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) dofile(modpath .. "/desert_temple.lua") +dofile(modpath .. "/stronghold.lua") From 6d4f7d2e62c07e55a4fe2e38e0afe3e92c92e33a Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 16 Jan 2022 05:20:34 +0400 Subject: [PATCH 36/61] Fix strongholds --- mods/CORE/mcl_mapgen/init.lua | 6 + mods/ITEMS/mcl_end/eye_of_ender.lua | 2 +- mods/MAPGEN/mcl_structures/stronghold.lua | 185 ++++++++++++++++++++++ 3 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 mods/MAPGEN/mcl_structures/stronghold.lua diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index f34211b06..a64bc1e6f 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -476,5 +476,11 @@ function mcl_mapgen.clamp_to_chunk(x, size) return x end local overflow = x2_in_chunk - CS_NODES + if overflow > size / 2 then + local next_x = x + (size - overflow) + if next_x < mcl_mapgen.EDGE_MAX then + return next_x + end + end return x - overflow end diff --git a/mods/ITEMS/mcl_end/eye_of_ender.lua b/mods/ITEMS/mcl_end/eye_of_ender.lua index ea3d70aba..5974e59dd 100644 --- a/mods/ITEMS/mcl_end/eye_of_ender.lua +++ b/mods/ITEMS/mcl_end/eye_of_ender.lua @@ -87,7 +87,7 @@ minetest.register_craftitem("mcl_end:ender_eye", { end local origin = user:get_pos() origin.y = origin.y + 1.5 - local strongholds = mcl_structures.get_registered_structures("stronghold") + local strongholds = mcl_structures.strongholds local dim = mcl_worlds.pos_to_dimension(origin) local is_creative = minetest.is_creative_enabled(user:get_player_name()) diff --git a/mods/MAPGEN/mcl_structures/stronghold.lua b/mods/MAPGEN/mcl_structures/stronghold.lua new file mode 100644 index 000000000..a33c79fcf --- /dev/null +++ b/mods/MAPGEN/mcl_structures/stronghold.lua @@ -0,0 +1,185 @@ +-- Generate strongholds. + +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +-- A total of 128 strongholds are generated in rings around the world origin. +-- This is the list of rings, starting with the innermost ring first. +local stronghold_rings = { + -- amount: Number of strongholds in ring. + -- min, max: Minimum and maximum distance from (X=0, Z=0). + { amount = 3, min = 1408, max = 2688 }, + { amount = 6, min = 4480, max = 5760 }, + { amount = 10, min = 7552, max = 8832 }, + { amount = 15, min = 10624, max = 11904 }, + { amount = 21, min = 13696, max = 14976 }, + { amount = 28, min = 16768, max = 18048 }, + { amount = 36, min = 19840, max = 21120 }, + { amount = 9, min = 22912, max = 24192 }, +} + +local strongholds = {} +local strongholds_inited = false + +local superflat = mcl_mapgen.superflat + +local size = {x = 13, y = 8, z = 13} +local offset = vector.round(vector.divide(size, 2)) + +local function place(pos, rotation, pr) + local p1 = { x = pos.x - offset.x, y = pos.y - offset.y, z = pos.z - offset.z } + local p2 = vector.add(p1, vector.subtract(size, 1)) + + local path = modpath.."/schematics/mcl_structures_end_portal_room_simple.mts" + + mcl_structures.place_schematic({ + pos = p1, + schematic = path, + rotation = rotation or "0", + pr = pr, + }) + minetest.chat_send_all("place! pos=" .. minetest.pos_to_string(p1) .. ", " .. minetest.pos_to_string(p2) .. ", " .. minetest.pos_to_string(size) .. ", " .. minetest.pos_to_string(offset)) + -- Find and setup spawner with silverfish + local spawners = minetest.find_nodes_in_area(p1, p2, "mcl_mobspawners:spawner") + for s=1, #spawners do + mcl_mobspawners.setup_spawner(spawners[s], "mobs_mc:silverfish") + end + + -- Shuffle stone brick types + local bricks = minetest.find_nodes_in_area(p1, p2, "mcl_core:stonebrick") + for b=1, #bricks do + local r_bricktype = pr:next(1, 100) + local r_infested = pr:next(1, 100) + local bricktype + if r_infested <= 5 then + if r_bricktype <= 30 then -- 30% + bricktype = "mcl_monster_eggs:monster_egg_stonebrickmossy" + elseif r_bricktype <= 50 then -- 20% + bricktype = "mcl_monster_eggs:monster_egg_stonebrickcracked" + else -- 50% + bricktype = "mcl_monster_eggs:monster_egg_stonebrick" + end + else + if r_bricktype <= 30 then -- 30% + bricktype = "mcl_core:stonebrickmossy" + elseif r_bricktype <= 50 then -- 20% + bricktype = "mcl_core:stonebrickcracked" + end + -- 50% stonebrick (no change necessary) + end + if bricktype then + minetest.set_node(bricks[b], { name = bricktype }) + end + end + + -- Also replace stairs + local stairs = minetest.find_nodes_in_area(p1, p2, {"mcl_stairs:stair_stonebrick", "mcl_stairs:stair_stonebrick_outer", "mcl_stairs:stair_stonebrick_inner"}) + for s=1, #stairs do + local stair = minetest.get_node(stairs[s]) + local r_type = pr:next(1, 100) + if r_type <= 30 then -- 30% mossy + if stair.name == "mcl_stairs:stair_stonebrick" then + stair.name = "mcl_stairs:stair_stonebrickmossy" + elseif stair.name == "mcl_stairs:stair_stonebrick_outer" then + stair.name = "mcl_stairs:stair_stonebrickmossy_outer" + elseif stair.name == "mcl_stairs:stair_stonebrick_inner" then + stair.name = "mcl_stairs:stair_stonebrickmossy_inner" + end + minetest.set_node(stairs[s], stair) + elseif r_type <= 50 then -- 20% cracky + if stair.name == "mcl_stairs:stair_stonebrick" then + stair.name = "mcl_stairs:stair_stonebrickcracked" + elseif stair.name == "mcl_stairs:stair_stonebrick_outer" then + stair.name = "mcl_stairs:stair_stonebrickcracked_outer" + elseif stair.name == "mcl_stairs:stair_stonebrick_inner" then + stair.name = "mcl_stairs:stair_stonebrickcracked_inner" + end + minetest.set_node(stairs[s], stair) + end + -- 50% no change + end + + -- Randomly add ender eyes into end portal frames, but never fill the entire frame + local frames = minetest.find_nodes_in_area(p1, p2, "mcl_portals:end_portal_frame") + local eyes = 0 + for f=1, #frames do + local r_eye = pr:next(1, 10) + if r_eye == 1 then + eyes = eyes + 1 + if eyes < #frames then + local frame_node = minetest.get_node(frames[f]) + frame_node.name = "mcl_portals:end_portal_frame_eye" + minetest.set_node(frames[f], frame_node) + end + end + end +end + + +-- Determine the stronghold positions and store them into the strongholds table. +-- The stronghold positions are based on the world seed. +-- The actual position might be offset by a few blocks because it might be shifted +-- to make sure the end portal room is completely within the boundaries of a mapchunk. +local function init_strongholds() + if strongholds_inited then + return + end + -- Don't generate strongholds in singlenode + if mcl_mapgen.singlenode then + strongholds_inited = true + return + end + local pr = PseudoRandom(mcl_mapgen.seed) + for s=1, #stronghold_rings do + local ring = stronghold_rings[s] + + -- Get random angle + local angle = pr:next() + -- Scale angle to 0 .. 2*math.pi + angle = (angle / 32767) * (math.pi*2) + for a=1, ring.amount do + local dist = pr:next(ring.min, ring.max) + local y + if superflat then + y = mcl_mapgen.overworld.bedrock_max + offset.y + else + y = pr:next(mcl_mapgen.overworld.bedrock_max+1+offset.y, mcl_mapgen.overworld.bedrock_min+48+offset.y) + end + local pos = { + x = mcl_mapgen.clamp_to_chunk(math.floor(math.cos(angle) * dist) - offset.x, size.x) + offset.x, + y = mcl_mapgen.clamp_to_chunk(y - offset.y, size.y) + offset.y, + z = mcl_mapgen.clamp_to_chunk(math.floor(math.sin(angle) * dist) - offset.z, size.z) + offset.z, + } + table.insert(strongholds, { pos = pos, generated = false }) + + -- Rotate angle by (360 / amount) degrees. + -- This will cause the angles to be evenly distributed in the stronghold ring + angle = math.fmod(angle + ((math.pi*2) / ring.amount), math.pi*2) + end + end + + mcl_structures.strongholds = strongholds + + mcl_structures.register_structure({ + name = "stronghold", + place_function = place, + }) + + strongholds_inited = true +end + +init_strongholds() + +-- Stronghold generation for register_on_generated. +mcl_mapgen.register_mapgen(function(minp, maxp, blockseed) + local pr = PseudoRandom(blockseed) + for s=1, #strongholds do + if not strongholds[s].generated then + local pos = strongholds[s].pos + if minp.x <= pos.x and maxp.x >= pos.x and minp.z <= pos.z and maxp.z >= pos.z and minp.y <= pos.y and maxp.y >= pos.y then + place(pos, nil, pr) + strongholds[s].generated = true + end + end + end +end, mcl_mapgen.order.STRONGHOLDS) From fefa9c8b4f50c145616d43ea12d7bcb19425f6ba Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 16 Jan 2022 06:42:18 +0400 Subject: [PATCH 37/61] Initialize temples --- mods/ITEMS/mcl_portals/portal_gateway.lua | 2 +- mods/MAPGEN/mcl_structures/desert_temple.lua | 120 ++++++++++-- mods/MAPGEN/mcl_structures/init.lua | 182 +++---------------- mods/MAPGEN/mcl_structures/stronghold.lua | 1 - 4 files changed, 130 insertions(+), 175 deletions(-) diff --git a/mods/ITEMS/mcl_portals/portal_gateway.lua b/mods/ITEMS/mcl_portals/portal_gateway.lua index 48d2b52fd..505935105 100644 --- a/mods/ITEMS/mcl_portals/portal_gateway.lua +++ b/mods/ITEMS/mcl_portals/portal_gateway.lua @@ -34,7 +34,7 @@ local function spawn_gateway_portal(pos, dest_str) schematic = path_gateway_portal, rotation = "0", force_placement = true, - after_place = dest_str and function() + on_placed = dest_str and function() minetest.get_meta(pos):set_string("mcl_portals:gateway_destination", dest_str) end, }) diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua index 7ca637900..399cc4666 100644 --- a/mods/MAPGEN/mcl_structures/desert_temple.lua +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -1,6 +1,8 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) +local node_list = {"mcl_core:sand", "mcl_core:sandstone", "mcl_core:redsand", "mcl_colorblocks:hardened_clay_orange"} + 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" @@ -15,27 +17,102 @@ red_temple_schematic_lua = red_temple_schematic_lua:gsub("mcl_stairs:slab_sandst 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}) +local function on_placed(p1, rotation, pr, size) + local p2 = {x = p1.x + size.x - 1, y = p1.y + size.y - 1, z = p1.z + size.z - 1} + -- Delete cacti leftovers: + local cactus_nodes = minetest.find_nodes_in_area_under_air({x = p1.x, y = p1.y + 11, z = p1.z}, {x = p2.x, y = p2.y - 2, z = p2.z}, "mcl_core:cactus", false) + for _, pos in pairs(cactus_nodes) do + local node_below = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) + local nn = node_below.name + if nn == "mcl_core:sandstone" then + minetest.swap_node(pos, {name="air"}) + end + end + + -- Find chests. + local chests = minetest.find_nodes_in_area(p1, {x = p2.x, y = p1.y + 5, z = p2.z}, "mcl_chests:chest") + + -- Add desert temple loot into chests + for c=1, #chests do + local lootitems = mcl_loot.get_multi_loot({ + { + stacks_min = 2, + stacks_max = 4, + items = { + { itemstring = "mcl_mobitems:bone", weight = 25, amount_min = 4, amount_max=6 }, + { itemstring = "mcl_mobitems:rotten_flesh", weight = 25, amount_min = 3, amount_max=7 }, + { itemstring = "mcl_mobitems:spider_eye", weight = 25, amount_min = 1, amount_max=3 }, + { itemstring = "mcl_books:book", weight = 20, func = function(stack, pr) + mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) + end }, + { itemstring = "mcl_mobitems:saddle", weight = 20, }, + { itemstring = "mcl_core:apple_gold", weight = 20, }, + { itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 }, + { itemstring = "mcl_core:iron_ingot", weight = 15, amount_min = 1, amount_max = 5 }, + { itemstring = "mcl_core:emerald", weight = 15, amount_min = 1, amount_max = 3 }, + { itemstring = "", weight = 15, }, + { itemstring = "mobs_mc:iron_horse_armor", weight = 15, }, + { itemstring = "mobs_mc:gold_horse_armor", weight = 10, }, + { itemstring = "mobs_mc:diamond_horse_armor", weight = 5, }, + { itemstring = "mcl_core:diamond", weight = 5, amount_min = 1, amount_max = 3 }, + { itemstring = "mcl_core:apple_gold_enchanted", weight = 2, }, + } + }, + { + stacks_min = 4, + stacks_max = 4, + items = { + { itemstring = "mcl_mobitems:bone", weight = 10, amount_min = 1, amount_max = 8 }, + { itemstring = "mcl_mobitems:rotten_flesh", weight = 10, amount_min = 1, amount_max = 8 }, + { itemstring = "mcl_mobitems:gunpowder", weight = 10, amount_min = 1, amount_max = 8 }, + { itemstring = "mcl_core:sand", weight = 10, amount_min = 1, amount_max = 8 }, + { itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 }, + } + }}, pr) + mcl_structures.init_node_construct(chests[c]) + local meta = minetest.get_meta(chests[c]) + local inv = meta:get_inventory() + mcl_loot.fill_inventory(inv, "main", lootitems, pr) + end + + -- Initialize pressure plates and randomly remove up to 5 plates + local pplates = minetest.find_nodes_in_area(p1, {x = p2.x, y = p1.y + 5, z = p2.z}, "mesecons_pressureplates:pressure_plate_stone_off") + local pplates_remove = 5 + for p=1, #pplates do + if pplates_remove > 0 and pr:next(1, 100) >= 50 then + -- Remove plate + minetest.remove_node(pplates[p]) + pplates_remove = pplates_remove - 1 + else + -- Initialize plate + minetest.registered_nodes["mesecons_pressureplates:pressure_plate_stone_off"].on_construct(pplates[p]) + end end end -local node_list = {"mcl_core:sand", "mcl_core:sandstone", "mcl_core:redsand", "mcl_colorblocks:hardened_clay_orange"} +local function place(pos, rotation, pr) + local pos_below = {x = pos.x, y = pos.y - 1, z = pos.z} + local pos_temple = {x = pos.x - 10, y = pos.y - 12, z = pos.z - 10} + 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, on_placed = on_placed}) + else + mcl_structures.place_schematic({pos = pos_temple, schematic = temple_schematic, pr = pr, on_placed = on_placed}) + end +end -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 +local function get_place_rank(pos) + local x, y, z = pos.x, pos.y - 1, pos.z + local p1 = {x = x - 8, y = y, z = z - 8} + local p2 = {x = x + 8, y = y, z = z + 8} + local best_pos_list_surface = minetest.find_nodes_in_area(p1, p2, node_list, false) + local other_pos_list_surface = minetest.find_nodes_in_area(p1, p2, "group:opaque", false) + p1 = {x = x - 4, y = y - 7, z = z - 4} + p2 = {x = x + 4, y = y - 3, z = z + 4} + local best_pos_list_underground = minetest.find_nodes_in_area(p1, p2, node_list, false) + local other_pos_list_underground = minetest.find_nodes_in_area(p1, p2, "group:opaque", false) + return 10 * (#best_pos_list_surface) + 2 * (#other_pos_list_surface) + 5 * (#best_pos_list_underground) + #other_pos_list_underground end mcl_structures.register_structure({ @@ -44,7 +121,7 @@ mcl_structures.register_structure({ deco_type = "simple", place_on = node_list, flags = "all_floors", - fill_ratio = 0.00001, + fill_ratio = 0.00003, y_min = 3, y_max = mcl_mapgen.overworld.max, height = 1, @@ -67,12 +144,15 @@ mcl_structures.register_structure({ }, }, on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) + local a = seed % 14 + local b = (math.floor(seed / 39) + 4) % 12 + if a ~= b then return end local pos = pos_list[1] if #pos_list > 1 then - local count = node_counter(pos) + local count = get_place_rank(pos) for i = 2, #pos_list do local pos_i = pos_list[i] - local count_i = node_counter(pos_i) + local count_i = get_place_rank(pos_i) if count_i > count then count = count_i pos = pos_i diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 44c876564..1011b4cbe 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -29,7 +29,6 @@ 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)) for node_name, pos_list in pairs(nodes) do local chunk_callback = on_finished_chunk_callbacks[node_name] if chunk_callback then @@ -49,12 +48,12 @@ end -------------------------------------------------------------------------------------- -- mcl_structures.register_structure(struct_def) -- struct_def: --- name - name like 'desert_temple' --- decoration - decoration definition if needed --- on_finished_block - callback if needed --- on_finished_chunk - next callback if needed --- place_function - placer function(pos, rotation, pr) --- order_number - (optional) +-- name - name, like 'desert_temple' +-- decoration - decoration definition, to use as structure seed (thanks cora for the idea) +-- on_finished_block - callback, if needed, to use with decorations: funcion(vm_context, pos_list) +-- on_finished_chunk - next callback if needed: funcion(minp, maxp, seed, vm_context, pos_list) +-- place_function - callback to place schematic by /spawnstruct debug command: function(pos, rotation, pr) +-- on_placed - useful when you want to process the area after placement: function(pos, rotation, pr, size) function mcl_structures.register_structure(def) local short_name = def.name local name = "mcl_structures:" .. short_name @@ -71,8 +70,13 @@ function mcl_structures.register_structure(def) local decoration_id if decoration then minetest.register_node(':' .. name, { - drawtype="airlike", - groups = { + drawtype = "airlike", + sunlight_propagates = true, + pointable = false, + walkable = false, + diggable = false, + buildable_to = true, + groups = { struct = 1, not_in_creative_inventory = 1, }, @@ -138,20 +142,20 @@ local function ecb_place(blockpos, action, calls_remaining, param) local pos = param.pos local rotation = param.rotation minetest.place_schematic(pos, param.schematic, rotation, param.replacements, param.force_placement, param.flags) - local after_place = param.after_place - if not after_place then + local on_placed = param.on_placed + if not on_placed then return end - after_place(pos, rotation, param.pr, param.param, param.size) + on_placed(pos, rotation, param.pr, param.size) end function mcl_structures.place_schematic(def) - local pos = def.pos - local schematic = def.schematic - local rotation = def.rotation - local pr = def.pr - local on_schematic_loaded = def.on_schematic_loaded - local emerge = def.emerge + local pos = def.pos + local schematic = def.schematic + local rotation = def.rotation + local pr = def.pr + local on_placed = def.on_placed -- on_placed(pos, rotation, pr, size) + local emerge = def.emerge if not pos then minetest.log('warning', '[mcl_structures] No pos. specified to place schematic') return @@ -168,19 +172,12 @@ function mcl_structures.place_schematic(def) end end - if not emerge and not on_schematic_loaded then + if not emerge and not on_placed then minetest.place_schematic(pos, schematic, rotation, def.replacements, def.force_placement, def.flags) - if not def.after_place then - return - end - def.after_place(pos, rotation, pr, def.after_place_param) return end local serialized_schematic = minetest.serialize_schematic(schematic, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic" - if on_schematic_loaded then - serialized_schematic = on_schematic_loaded(serialized_schematic) - end local loaded_schematic = loadstring(serialized_schematic)() if not loaded_schematic then minetest.log('warning', '[mcl_structures] Schematic ' .. schematic .. ' load serialized string problem at ' .. minetest.pos_to_string(pos)) @@ -198,8 +195,6 @@ function mcl_structures.place_schematic(def) local x, y, z = pos.x, pos.y, pos.z local p1 = {x = x, y = y, z = z} local p2 = {x = x + size_x - 1, y = y + size_y - 1, z = size_z - 1} - minetest.log("verbose", "[mcl_structures] Emerge area " .. minetest.pos_to_string(p1) .. " - " .. minetest.pos_to_string(p2) - .. " of size " ..minetest.pos_to_string(size) .. " to place " .. schematic .. ", rotation " .. tostring(rotation)) local ecb_param = { pos = vector.new(pos), schematic = loaded_schematic, @@ -207,15 +202,16 @@ function mcl_structures.place_schematic(def) replacements = replacements, force_placement = force_placement, flags = flags, - after_place = after_place, size = vector.new(size), pr = pr, - param = param, + on_placed = on_placed, } if not emerge then ecb_place(p1, nil, 0, ecb_param) return end + minetest.log("verbose", "[mcl_structures] Emerge area " .. minetest.pos_to_string(p1) .. " - " .. minetest.pos_to_string(p2) + .. " of size " ..minetest.pos_to_string(size) .. " to place " .. schematic .. ", rotation " .. tostring(rotation)) minetest.emerge_area(p1, p2, ecb_place, ecb_param) end @@ -235,7 +231,7 @@ end -- Call on_construct on pos. -- Useful to init chests from formspec. -local function init_node_construct(pos) +function mcl_structures.init_node_construct(pos) local node = minetest.get_node(pos) local def = minetest.registered_nodes[node.name] if def and def.on_construct then @@ -251,9 +247,7 @@ function mcl_structures.call_struct(pos, struct_style, rotation, pr, callback) if not rotation then rotation = "random" end - if struct_style == "desert_temple" then - return mcl_structures.generate_desert_temple(pos, rotation, pr) - elseif struct_style == "desert_well" then + if struct_style == "desert_well" then return mcl_structures.generate_desert_well(pos, rotation) elseif struct_style == "igloo" then return mcl_structures.generate_igloo(pos, rotation, pr) @@ -451,7 +445,7 @@ local function igloo_placement_callback(p1, p2, size, orientation, pr) }}, pr) local chest_pos = vector.add(p1, chest_offset) - init_node_construct(chest_pos) + mcl_structures.init_node_construct(chest_pos) local meta = minetest.get_meta(chest_pos) local inv = meta:get_inventory() mcl_loot.fill_inventory(inv, "main", lootitems, pr) @@ -539,123 +533,6 @@ function mcl_structures.generate_end_gateway_portal(pos, rot) return mcl_structures.place_schematic(pos, path, rot or "0", nil, true) end -local function temple_placement_callback(p1, p2, size, rotation, pr) - - -- Delete cacti leftovers: - local cactus_nodes = minetest.find_nodes_in_area_under_air(p1, p2, "mcl_core:cactus") - if cactus_nodes and #cactus_nodes > 0 then - for _, pos in pairs(cactus_nodes) do - local node_below = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) - if node_below and node_below.name == "mcl_core:sandstone" then - minetest.swap_node(pos, {name="air"}) - end - end - end - - -- Find chests. - -- FIXME: Searching this large area just for the chets is not efficient. Need a better way to find the chests; - -- probably let's just infer it from newpos because the schematic always the same. - local chests = minetest.find_nodes_in_area(p1, p2, "mcl_chests:chest") - - -- Add desert temple loot into chests - for c=1, #chests do - local lootitems = mcl_loot.get_multi_loot({ - { - stacks_min = 2, - stacks_max = 4, - items = { - { itemstring = "mcl_mobitems:bone", weight = 25, amount_min = 4, amount_max=6 }, - { itemstring = "mcl_mobitems:rotten_flesh", weight = 25, amount_min = 3, amount_max=7 }, - { itemstring = "mcl_mobitems:spider_eye", weight = 25, amount_min = 1, amount_max=3 }, - { itemstring = "mcl_books:book", weight = 20, func = function(stack, pr) - mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) - end }, - { itemstring = "mcl_mobitems:saddle", weight = 20, }, - { itemstring = "mcl_core:apple_gold", weight = 20, }, - { itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 }, - { itemstring = "mcl_core:iron_ingot", weight = 15, amount_min = 1, amount_max = 5 }, - { itemstring = "mcl_core:emerald", weight = 15, amount_min = 1, amount_max = 3 }, - { itemstring = "", weight = 15, }, - { itemstring = "mobs_mc:iron_horse_armor", weight = 15, }, - { itemstring = "mobs_mc:gold_horse_armor", weight = 10, }, - { itemstring = "mobs_mc:diamond_horse_armor", weight = 5, }, - { itemstring = "mcl_core:diamond", weight = 5, amount_min = 1, amount_max = 3 }, - { itemstring = "mcl_core:apple_gold_enchanted", weight = 2, }, - } - }, - { - stacks_min = 4, - stacks_max = 4, - items = { - { itemstring = "mcl_mobitems:bone", weight = 10, amount_min = 1, amount_max = 8 }, - { itemstring = "mcl_mobitems:rotten_flesh", weight = 10, amount_min = 1, amount_max = 8 }, - { itemstring = "mcl_mobitems:gunpowder", weight = 10, amount_min = 1, amount_max = 8 }, - { itemstring = "mcl_core:sand", weight = 10, amount_min = 1, amount_max = 8 }, - { itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 }, - } - }}, pr) - init_node_construct(chests[c]) - local meta = minetest.get_meta(chests[c]) - local inv = meta:get_inventory() - mcl_loot.fill_inventory(inv, "main", lootitems, pr) - end - - -- Initialize pressure plates and randomly remove up to 5 plates - local pplates = minetest.find_nodes_in_area(p1, p2, "mesecons_pressureplates:pressure_plate_stone_off") - local pplates_remove = 5 - for p=1, #pplates do - if pplates_remove > 0 and pr:next(1, 100) >= 50 then - -- Remove plate - minetest.remove_node(pplates[p]) - pplates_remove = pplates_remove - 1 - else - -- Initialize plate - minetest.registered_nodes["mesecons_pressureplates:pressure_plate_stone_off"].on_construct(pplates[p]) - end - end -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 size = {x=22, y=24, z=22} - --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 = {} - ---[[ Returns a table of structure of the specified type. -Currently the only valid parameter is "stronghold". -Format of return value: -{ - { pos = , generated= }, -- first structure - { pos = , generated= }, -- second structure - -- and so on -} - -TODO: Implement this function for all other structure types as well. -]] ---[[ -function mcl_structures.get_registered_structures(structure_type) - if registered_structures[structure_type] then - return table.copy(registered_structures[structure_type]) - else - return {} - end -end -]] --- Register a structures table for the given type. The table format is the same as for --- mcl_structures.get_registered_structures. ---[[ -function mcl_structures.register_structures(structure_type, structures) - registered_structures[structure_type] = structures -end -]] local function dir_to_rotation(dir) local ax, az = math.abs(dir.x), math.abs(dir.z) if ax > az then @@ -670,7 +547,6 @@ local function dir_to_rotation(dir) return "0" end - dofile(modpath .. "/structures.lua") -- Debug command diff --git a/mods/MAPGEN/mcl_structures/stronghold.lua b/mods/MAPGEN/mcl_structures/stronghold.lua index a33c79fcf..3493173d5 100644 --- a/mods/MAPGEN/mcl_structures/stronghold.lua +++ b/mods/MAPGEN/mcl_structures/stronghold.lua @@ -38,7 +38,6 @@ local function place(pos, rotation, pr) rotation = rotation or "0", pr = pr, }) - minetest.chat_send_all("place! pos=" .. minetest.pos_to_string(p1) .. ", " .. minetest.pos_to_string(p2) .. ", " .. minetest.pos_to_string(size) .. ", " .. minetest.pos_to_string(offset)) -- Find and setup spawner with silverfish local spawners = minetest.find_nodes_in_area(p1, p2, "mcl_mobspawners:spawner") for s=1, #spawners do From 2cfca0518679b32b82b31986a90a837e3bb0746d Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 16 Jan 2022 19:20:42 +0400 Subject: [PATCH 38/61] Move noise indicator into separate file --- mods/MAPGEN/mcl_mapgen_core/structures.lua | 38 ----------------- mods/MAPGEN/mcl_structures/desert_temple.lua | 6 ++- mods/MAPGEN/mcl_structures/init.lua | 4 +- .../MAPGEN/mcl_structures/noise_indicator.lua | 42 +++++++++++++++++++ mods/MAPGEN/mcl_structures/structures.lua | 8 +++- 5 files changed, 55 insertions(+), 43 deletions(-) create mode 100644 mods/MAPGEN/mcl_structures/noise_indicator.lua diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua index 5f751db50..3a25d1cfd 100644 --- a/mods/MAPGEN/mcl_mapgen_core/structures.lua +++ b/mods/MAPGEN/mcl_mapgen_core/structures.lua @@ -268,30 +268,6 @@ local function spawn_spikes_in_v6(p, nn, pr) end local function generate_structures(vm_context) - -local levels = { - [-9] = "black", - [-8] = "brown", - [-7] = "brown", - [-6] = "gray", - [-5] = "gray", - [-4] = "red", - [-3] = "orange", - [-2] = "purple", - [-1] = "magenta", - [0] = "pink", - [1] = "yellow", - [2] = "green", - [3] = "lime", - [4] = "blue", - [5] = "cyan", - [6] = "light_blue", - [7] = "silver", - [8] = "silver", - [9] = "white", - } - - -- local pr = PcgRandom(vm_context.blockseed) local pr = PcgRandom(vm_context.chunkseed) -- chunk_has_desert_struct = false -- chunk_has_desert_temple = false @@ -304,20 +280,6 @@ local levels = { local DIVLEN = 5 for x0 = minp.x, maxp.x, DIVLEN do for z0 = minp.z, maxp.z, DIVLEN do -- Determine amount from perlin noise - local noise = perlin_structures:get_2d({x=x0, y=z0}) - local amount - if noise < 0 then - amount = math_max(math_ceil(noise * 9), -9) - else - 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 - minetest.set_node({x=x1, y=y1, z=z1}, {name = "mcl_core:glass_"..levels[amount]}) - end end - -- Find random positions based on this random local p, ground_y, nn for i = 0, 24 do diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua index 399cc4666..682af9d4d 100644 --- a/mods/MAPGEN/mcl_structures/desert_temple.lua +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -121,11 +121,12 @@ mcl_structures.register_structure({ deco_type = "simple", place_on = node_list, flags = "all_floors", - fill_ratio = 0.00003, + --fill_ratio = 0.00003, + fill_ratio = 0.003, y_min = 3, y_max = mcl_mapgen.overworld.max, height = 1, - biomes = { + biomes = not mcl_mapgen.v6 and { "ColdTaiga_beach", "ColdTaiga_beach_water", "Desert", @@ -146,6 +147,7 @@ mcl_structures.register_structure({ on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) local a = seed % 14 local b = (math.floor(seed / 39) + 4) % 12 + minetest.chat_send_all("seed=" .. tostring(seed) .. ", a=" .. tostring(a) .. ", b=" ..tostring(b)) if a ~= b then return end local pos = pos_list[1] if #pos_list > 1 then diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 1011b4cbe..65e538024 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -17,6 +17,8 @@ local use_process_mapgen_chunk = false local on_finished_block_callbacks = {} local on_finished_chunk_callbacks = {} +mcl_structures.perlin_noise = minetest.get_perlin(329, 3, 0.6, 100) + function process_mapgen_block_lvm(vm_context) local nodes = minetest.find_nodes_in_area(vm_context.minp, vm_context.maxp, {"group:struct"}, true) for node_name, pos_list in pairs(nodes) do @@ -70,7 +72,7 @@ function mcl_structures.register_structure(def) local decoration_id if decoration then minetest.register_node(':' .. name, { - drawtype = "airlike", + -- drawtype = "airlike", sunlight_propagates = true, pointable = false, walkable = false, diff --git a/mods/MAPGEN/mcl_structures/noise_indicator.lua b/mods/MAPGEN/mcl_structures/noise_indicator.lua new file mode 100644 index 000000000..3f45040c0 --- /dev/null +++ b/mods/MAPGEN/mcl_structures/noise_indicator.lua @@ -0,0 +1,42 @@ +local levels = { + [-9] = "black", + [-8] = "brown", + [-7] = "brown", + [-6] = "gray", + [-5] = "gray", + [-4] = "red", + [-3] = "orange", + [-2] = "purple", + [-1] = "magenta", + [0] = "pink", + [1] = "yellow", + [2] = "green", + [3] = "lime", + [4] = "blue", + [5] = "cyan", + [6] = "light_blue", + [7] = "silver", + [8] = "silver", + [9] = "white", +} + +local math_min, math_max = math.min, math.max +local math_floor, math_ceil = math.floor, math.ceil + +mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) + mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100) + local perlin_noise = mcl_structures.perlin_noise + for x0 = minp.x, maxp.x do + for z0 = minp.z, maxp.z do + local current_noise_level = perlin_noise:get_2d({x=x0, y=z0}) + local amount + if current_noise_level < 0 then + amount = math_max(math_ceil(current_noise_level * 9), -9) + else + amount = math_min(math_floor(current_noise_level * 9), 9) + end + local y0 = maxp.y - 9 + amount + minetest.set_node({x=x0, y=y0, z=z0}, {name = "mcl_core:glass_"..levels[amount]}) + end + end +end, -1) diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index c0f1b3d3e..91f0022cb 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -1,5 +1,9 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) -dofile(modpath .. "/desert_temple.lua") -dofile(modpath .. "/stronghold.lua") +if not mcl_mapgen.singlenode then + dofile(modpath .. "/desert_temple.lua") + dofile(modpath .. "/stronghold.lua") + + dofile(modpath .. "/noise_indicator.lua") +end From 12e85f9f121cbecea68fa280ebc1facfcdff2323 Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 16 Jan 2022 22:50:58 +0400 Subject: [PATCH 39/61] Add Jungle Temple schematic by cora --- mods/MAPGEN/mcl_structures/mod.conf | 2 +- .../schematics/mcl_structures_jungle_temple.mts | Bin 0 -> 1893 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 mods/MAPGEN/mcl_structures/schematics/mcl_structures_jungle_temple.mts diff --git a/mods/MAPGEN/mcl_structures/mod.conf b/mods/MAPGEN/mcl_structures/mod.conf index f22f7c738..4a04c65cd 100644 --- a/mods/MAPGEN/mcl_structures/mod.conf +++ b/mods/MAPGEN/mcl_structures/mod.conf @@ -1,4 +1,4 @@ name = mcl_structures -author = Wuzzy, kay27 +author = Wuzzy, kay27, cora description = Structures for MineClone 2/5 depends = mcl_loot, mcl_mapgen diff --git a/mods/MAPGEN/mcl_structures/schematics/mcl_structures_jungle_temple.mts b/mods/MAPGEN/mcl_structures/schematics/mcl_structures_jungle_temple.mts new file mode 100644 index 0000000000000000000000000000000000000000..04dae9b617972de717990884cbbf6e8bda18908c GIT binary patch literal 1893 zcmZ`(d0dj|8pUR+YmGl!bWBp4GAoxFy(Ok%HkElNhfon6E%~k@8VaI(B%p{>PRrYV z3)}b)Q!vASAn^gzC{2>dvUG|7(m)3qH6S8_5Cq_tS^y*mkVvqtWCBRQQ^G-ju4zex zC<4`CsREWufD#-G+xEc{L0nn~bodoDZ`Q2LT=tm#KhNoik8SYZZ4PuIl>k`VSTCRD zh`(yqzpBfc$?tPO5P=lH)a>{hE~$VGBYV;>@yhitKC4=JqF080pUq^+)brl!wO_C5 z=vjSRU_amm|LTpIb_EJ^F(={KMi*wWXZ$WSHgw%k(J`GoB(~_Qv;qs;i$dJGRt%`` z#tB|{uAGHOb*9V)MrIcA%wqjK+K!u6`)ETKhh_UDSXIcYW0T$SEuqG%P>w%Nw%*Ek z?u+F9yW#NgMBP(3&r>=yM>it%E(*}bgIIpZ1H3s*Rz8IZ2;Qk z2i1DxuSd?8KZ%|(8LFjpr(a4UrQ!_APFl|2yX0%t;g~c~J>ZwRu)iuQ9NTzPGKOvt zAKSgbn{g{)!ftqm@hMk0glth@6jqI{is#K+-xO}qS73}{+L7B&cn~jSf5D;TWVqBx z1m{fi?AvZDzTrS=Rq8Y)c9hwEHPHEL&kCjg*n`7i#X@>GwRDgCaz0DeUASW$oii17 z+v&>1X4#_#Xn^-v@Z4on@vGx?LZ1{{WWI04zH!`mXT;(eMU7==Vgq*1m(@vECnl;o zByNz%jP+h&p2KZ;kUI=|TL=r$HT{>~VMt`;2&?sY2(RP}$*h?PulM2=oWV%>|50}( zijwkh|X_Lt~ZV2j=Cd*9ZZI9<B6}>%ndxwE{oTDk`14;nu7ZF2m4)P^!t03SsF}LJrWpa zBvy^?ZHB_WmPD`g^%+UN?wp_ueu}m~+`e}nbZTswx7r+gnZNe2rTG*(9%_;A8x+*? zAEnuRZ~CqvUs1HrPWqCgFz*ZD9np1_M-i)^wpP~5*txRYL5N$==~~O)a@u73`vQCQ zO6mU;qYG@y*fsgHA_?1>Ep+#DPH#}1Tx%>Aqw^#EbrJJGa%rM661!%^XY^a{A*Ttq z+Vg|LqMaznE^-SEVbANFug%W&T%1%FFt;VuuDX*St$;i(RJ5W?UQktcaJ~i*=CvxX z;0I{c`0R8{{C-n&K3`%H>&*yd4NtVD@M0)0bQT!$yvVXRD z>iU>|E9S&~jH7n>^!|pKoRoU;5YD|AY&tv6p&elw@8&9E%arL}eEKQsy%TGEWh@-2 zTYs@6?aeEQ>1_=6JDcv)boi|yjE#11M zUtdOKdWmjul|Owl(6NV{2@e5lpA1E;jl7Lgt{12foLigU(u}=J%bF1BPZ&q7yWy6x z8-*>%*zdSKyJSN8-Bi^&*)ST=rr+7}&>`!<%kL5y&n60#h36R7i^sIaJlpuWjq(*; kA#y=Kpo24mMD`P?)~U7d+~DG003#&2_5c6? literal 0 HcmV?d00001 From e528cc7d8b2aa594ed7da4646523f0c1d35fc0b1 Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 17 Jan 2022 00:39:53 +0400 Subject: [PATCH 40/61] Place Jungle Temple by cora --- mods/MAPGEN/mcl_structures/jungle_temple.lua | 128 ++++++++++++++++++ .../mcl_structures_jungle_temple.mts | Bin 1893 -> 2586 bytes mods/MAPGEN/mcl_structures/structures.lua | 1 + 3 files changed, 129 insertions(+) create mode 100644 mods/MAPGEN/mcl_structures/jungle_temple.lua diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua new file mode 100644 index 000000000..414c2c53f --- /dev/null +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -0,0 +1,128 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +local node_list = {"mcl_core:dirt_with_grass", "mcl_core:dirt", "mcl_core:stone", "mcl_core:granite", "mcl_core:gravel", "mcl_core:diorite"} + +local schematic_file = modpath .. "/schematics/mcl_structures_jungle_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 size = temple_schematic.size +local offset = vector.round(vector.divide(size, 2)) +offset.y = 5 + +local function on_placed(p1, rotation, pr, size) + local p2 = {x = p1.x + size.x - 1, y = p1.y + size.y - 1, z = p1.z + size.z - 1} + + -- Find chests. + local chests = minetest.find_nodes_in_area(p1, {x = p2.x, y = p1.y + 5, z = p2.z}, "mcl_chests:chest") + + -- Add desert temple loot into chests + for c=1, #chests do + local lootitems = mcl_loot.get_multi_loot({ + { + stacks_min = 2, + stacks_max = 4, + items = { + { itemstring = "mcl_mobitems:bone", weight = 25, amount_min = 4, amount_max=6 }, + { itemstring = "mcl_mobitems:rotten_flesh", weight = 25, amount_min = 3, amount_max=7 }, + { itemstring = "mcl_mobitems:spider_eye", weight = 25, amount_min = 1, amount_max=3 }, + { itemstring = "mcl_books:book", weight = 20, func = function(stack, pr) + mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) + end }, + { itemstring = "mcl_mobitems:saddle", weight = 20, }, + { itemstring = "mcl_core:apple_gold", weight = 20, }, + { itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 }, + { itemstring = "mcl_core:iron_ingot", weight = 15, amount_min = 1, amount_max = 5 }, + { itemstring = "mcl_core:emerald", weight = 15, amount_min = 1, amount_max = 3 }, + { itemstring = "", weight = 15, }, + { itemstring = "mobs_mc:iron_horse_armor", weight = 15, }, + { itemstring = "mobs_mc:gold_horse_armor", weight = 10, }, + { itemstring = "mobs_mc:diamond_horse_armor", weight = 5, }, + { itemstring = "mcl_core:diamond", weight = 5, amount_min = 1, amount_max = 3 }, + { itemstring = "mcl_core:apple_gold_enchanted", weight = 2, }, + } + }, + { + stacks_min = 4, + stacks_max = 4, + items = { + { itemstring = "mcl_mobitems:bone", weight = 10, amount_min = 1, amount_max = 8 }, + { itemstring = "mcl_mobitems:rotten_flesh", weight = 10, amount_min = 1, amount_max = 8 }, + { itemstring = "mcl_mobitems:gunpowder", weight = 10, amount_min = 1, amount_max = 8 }, + { itemstring = "mcl_core:sand", weight = 10, amount_min = 1, amount_max = 8 }, + { itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 }, + } + }}, pr) + mcl_structures.init_node_construct(chests[c]) + local meta = minetest.get_meta(chests[c]) + local inv = meta:get_inventory() + mcl_loot.fill_inventory(inv, "main", lootitems, pr) + end + +end + +local function place(pos, rotation, pr) + mcl_structures.place_schematic({pos = vector.subtract(pos, offset), schematic = temple_schematic, pr = pr, on_placed = on_placed}) +end + +local function get_place_rank(pos) + local x, y, z = pos.x, pos.y, pos.z + local p1 = {x = x - 6, y = y, z = z - 6} + local p2 = {x = x + 6, y = y, z = z + 6} + local pos_list_air = minetest.find_nodes_in_area(p1, p2, {"air", "group:buildable_to", "group:deco_block", "group:water"}, false) + p1.y = y - 1 + p2.y = y - 1 + local pos_list_ground = minetest.find_nodes_in_area(p1, p2, node_list, false) + return #pos_list_ground + #pos_list_air +end + +mcl_structures.register_structure({ + name = "jungle_temple", + decoration = { + deco_type = "simple", + place_on = node_list, + flags = "all_floors", + --fill_ratio = 0.00003, + fill_ratio = 0.003, + y_min = 3, + y_max = mcl_mapgen.overworld.max, + height = 1, + biomes = + mcl_mapgen.v6 and { + "Jungle" + } or { + "Jungle", + "JungleEdge", + "JungleEdgeM", + "JungleEdgeM_ocean", + "JungleEdge_ocean", + "JungleM", + "JungleM_ocean", + "JungleM_shore", + "Jungle_ocean", + "Jungle_shore", + }, + }, + on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) +-- local a = seed % 14 +-- local b = (math.floor(seed / 39) + 4) % 12 +-- minetest.chat_send_all("seed=" .. tostring(seed) .. ", a=" .. tostring(a) .. ", b=" ..tostring(b)) +-- if a ~= b then return end + local pos = pos_list[1] + if #pos_list > 1 then + local count = get_place_rank(pos) + for i = 2, #pos_list do + local pos_i = pos_list[i] + local count_i = get_place_rank(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, + place_function = place, +}) diff --git a/mods/MAPGEN/mcl_structures/schematics/mcl_structures_jungle_temple.mts b/mods/MAPGEN/mcl_structures/schematics/mcl_structures_jungle_temple.mts index 04dae9b617972de717990884cbbf6e8bda18908c..ec98a83ea359fafabc55ec0df882634a601a9790 100644 GIT binary patch delta 2290 zcmZvbZ8Ve#8^`B1%{{~1F@ww?+-NK*#!IT%O!qKpDp`Z1h5-n#s#j z?S{rnC1-4J!)`ThgK252C)Eh8taf9wN3ATa^w^KjInVXw`tbXm^FQZ0*Z;NYIZMag z5#hTrD=?NAQw&-BKZ7A*u>7P<Z^+gSe}U&znQPKdAY0@hR*0Edbn0K1AhV0FbFV3)GoUO8?l z&WRODfFLjkbOBe~CnWgP0W~JF{Zf0;6r8B#$V`K?2+_4#4{cj{DUj&wj&;BAKrdN| zL`dRmsE7!>AgKZbMjX4;Jtq)1*|)8Tl|x8TOB-Kzx!iagc$*P%K7F{Kj=^k*tQ||j zkGjEGqOnkL!2%WVwX;61+2SE>6J5K*Z`~9;X%LmUzk%l+?o`Rbr+F;vtP>mos zDja|7{i)J?a!;Ae&@2Bko;;F3x&nD*t$VcJJTlGumHu}*G(QSd&?4=&4#tLd3UuLZ ztT3kT!+a)QoYn6#`yO{TQT+{`L~-h)%pFDKjG#knCAE^_*xA{FJE}rM>1sdSEoXHz zg$YLe$!8}Y;Je4EpWmOT4s3-MAvq*_1T0h+<*(YVDvak(GZrU}s@n*S_EG+N$&(=V z66=P=Oe00gGW4$;nCXr+?FuL|zFdh`<7*YD*sS`By3Z@)HHgJ#Oov;kY>dNf1Zmrm z;KIQ;MNWbW-sR&h*&j@}C^_-)q2wyWP91u6yHW{+#d7z*fcLMEyS`?2cEDK!5CpZ* z9B$1Q$;gp?(m~JeUs4NHRGGN8Zo&TiJ#Jvt_wRAfPUa6`jqTp|Qx;Qf;(t-sOT}KU zCF(KJJ#9d3dfo~mADzUBADVMJ>12+l%-g*BVS1IPI>LsBRC6n7D`v_^x+MRikDg_eaDdJ^J_+q)G_IOxa{~T_G z3{&exA0YRg{iYLwm}>{5(_;AE_+g9d=wB}N)jqo5NO183xnZEB(P7{{ZX%8YUGJi` zKaJi3{Rq|F_044Tw3P#`rfd{7Kfe4z@v`Kot48O=NT(wcr_}UQBCOv|@f_tBVyW#n zoYhsfhL4~e(hTReoXnrSshp<8+@*Vs&8^q1aRJ$`-eWjvznH?d?$%4(nJ~>>A1OU1 zf;2BSk8r#V{S+6_1Du#O%EWs71=Dcs4Q;c~t}JH%TRx5Zzv7P-u7pULx|4WSM{w<+ z`gQh59wFXmpS6KXRl@q)i<|!0t~h6Q{F-bkY%sm|+hoGuXW#@Ar%_}ajMmhBbI8#5 z^^i3}A~WjVbO#C)^WD>Ur+`Hpv6!S+}*Ukf0r+%UYA6E}U z*C~EWsPy0oO0~HCX*T2w1iRK7?HV$SQ=a4|g5!f;quG82t%-tFM@2*Amk;YEd*#Rbh4Lfi~8Qz4R(8Mn5UbXb^r`z~=dF)i%?dw%{-f(< zF~eckCJQ?c!X1Jc*Qpozl)eyWHs`UWTKjV$!SVDbJkWrO8}0Y4(%+$*35f-{Yrb3x z1kOd}eG-StwMU-|%g(SIJV^KIf5SmuZ<8q7HHc7(Xa2J7aa2Q_k9f|IB^j z7BvK$QP$PRov~ugL65O|g3_5DDi7FndUlY`_hwwSHFfu^X{mYoMsfIZghPF2Wobyy z173*dtO*wU2pa8}EHeHbolrh`nIN#)m$HF8TYjBdNVTv~P+47YLBb4A)rb{6_Lrg< KOf2`H&3^&OCfXqY delta 1633 zcmZvcX;9J$7>BX8T5DZ9bWQW9v_r90x5QM;F0(R3MKmp8lhja=6(~Rvw(QhINe%OW z$uhi23za-NjW+Yd!W41KYrQ~2`->c|yB~IEk9X#s-^}yO`}_Fj7!7?3g9RX9pszqi zpfw;9#=i%&7PKCRi9uuVgmBk0SON)6#*)sWBMGO8M9|XHSOUo4ADXpk`+Ac<2$8fX ziLQUf;&oV9On64No)s(4{OI3>L=rwWJdA+FMC0&8A{Dgmudcrh$n<|8<}~4a_!-ub zO)Rl>hL4_i#t(YtCT6&BVmJmLOLQe;3E^l52M5Q+bzn`~FerJGAt|@+Zu~~D>}0PT z^Cgc;lk4UK*XVy--qEw-q0nU@z-<4gE&7!(#I^k7H|sp9CH_g<;mD}fL&e7o3ZTg1 z{h2&Fr)whA>Q)5N*qa%ld8?i^JKvc;8y1&S%-NC{;@9S5T^*zkTpO0}mLj#0AC66S zC$&UbEQh(>U`)0?$bK6PW&hA{aCoBbwHe1>HZ(^zkLg_y!Yu}o{K%_#&GgsQsI5L7 zr7YANbpSrW#bCf(WGYlyy90gL6Q+H0!E(i+y<}hhhCwK8FWM>XBC4+{j|Yj@>23gE zs+;Vhi;ZfemI0nacn7kKjZ?`wq9%f$D(} zmS&IOd@Qo@zH|)UAUU>UZ6M`A@`Us74CO1fXb9S(La6K;y;N_TH+?FyGFBnX6WXB+ zo0ERnt9cul`21|oI;rrob%9IUL)CF6kSWk*s*$7A_S<0|w|kbTL&u&Sj4lz8V+mzD zl^KOJd3Vv)ad^HW`l0)+Yt8Z(4Zr~BrSPri`jQVmb)ukjCum`C_U>`ic;`$v>b)|^aajBcDJe=<3*t}b|WS3YSz0H6wAxYjrDxO~oJoqc!dwwuy zCw%Y}ZiDTYsmN5CX+?6ApSeOd_uF?Bn`GNi*rGP|u5+PM!%Ad{w@dGIJ;T!dF1Lk$ zCCH%?HTUXxd9h^+CQ0E*bWX}A4>;EJv)i64lW!{|0a5I#94{<=EIN=Rr7}Wpa&Ns? zq9okUJ+`tH*>TmUExjDmw6Ml!x-JNQfI-gU*A?gv9Jb?I^XhUry{G7AbM^|LZ%;(X z9ZG+we>vDhA$TFQ$Y!JnMt3y>(MP56%YuVO((ZaBt0P{+T@JSInkTw9w#?gaNX+1` zdI`2wz>|O$62yhmIbWN{^r7gxGX(oJl%Fwb;Q{C6=qR z0{G;!geNCg2Fq!vm~P{R(#%gE0IG*=c`5Y1uHfS0d(f2b)7crVynNt}@Am&jr6XO> zXn}b^?+&ETGD^&tTw_la7Qt%t1f!m~$NEn@pFq`|s1+ka7~Es^Z)xbQu@i=I;)MRQ z6$>T%qQohmXAXD$DCSR1V@3soUd@N!_k8En{RpziQYrHei_tUXn=1#DuArK!OeXz> zASJzfrmFKkjn&d^Savi6k`o}l$5#Kkbf9A=F2{@#NvwS}^wX-ihcNXTp%%h?uwj~H z5m;8<1j%|uIqcAF22NZjYJn#H%5cif@wtu4C0&t9VL#dsF3fGB#KT-G(aI_fxJir)5o%ZK^f2s*lHUOWQdxum diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index 91f0022cb..5bbc18774 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -3,6 +3,7 @@ local modpath = minetest.get_modpath(modname) if not mcl_mapgen.singlenode then dofile(modpath .. "/desert_temple.lua") + dofile(modpath .. "/jungle_temple.lua") dofile(modpath .. "/stronghold.lua") dofile(modpath .. "/noise_indicator.lua") From 66fded90d55eaab1aa9ec561a8ba72310b843d3d Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 17 Jan 2022 03:25:47 +0400 Subject: [PATCH 41/61] Fix vines --- mods/CORE/mcl_mapgen/API.md | 10 +- mods/CORE/mcl_mapgen/init.lua | 10 +- mods/ITEMS/mcl_core/functions.lua | 11 +- mods/ITEMS/mcl_core/mod.conf | 2 +- mods/MAPGEN/mcl_mapgen_core/init.lua | 237 +---------------- mods/MAPGEN/mcl_mapgen_core/structures.lua | 7 - .../mcl_mapgen_core/tree_decoration.lua | 251 ++++++++++++++++++ 7 files changed, 273 insertions(+), 255 deletions(-) create mode 100644 mods/MAPGEN/mcl_mapgen_core/tree_decoration.lua diff --git a/mods/CORE/mcl_mapgen/API.md b/mods/CORE/mcl_mapgen/API.md index fed1fd1d8..23365b357 100644 --- a/mods/CORE/mcl_mapgen/API.md +++ b/mods/CORE/mcl_mapgen/API.md @@ -15,19 +15,19 @@ See https://git.minetest.land/MineClone2/MineClone2/issues/1395 `vm_context` will pass into next lvm callback function from the queue! `vm_context`: a table which already contains some LVM data as the fields, and some of them can be added in your lvm callback function: `vm`: curent voxel manipulator object itself; - `blockseed`: seed of this mapchunk; + `chunkseed`: seed of this mapchunk; `minp` & `maxp`: minimum and maximum chunk position; `emin` & `emax`: minimum and maximum chunk position WITH SHELL AROUND IT; `area`: voxel area, can be helpful to access data; `data`: LVM buffer data array, data loads into it before the callbacks; `write`: set it to true in your lvm callback functionm, if you changed `data` and want to write it; - `data2`: LVM buffer data array of `param2`, !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourself: - `vm_context.data2 = vm_context.data2 or vm_context.vm.get_param2_data(vm_context.lvm_param2_buffer)` - `write_param2`: set it to true in your lvm callback function, if you used `data2` and want to write it; + `param2_data`: LVM buffer data array of `param2`, !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourself: + `vm_context.param2_data = vm_context.param2_data or vm_context.vm:get_param2_data(vm_context.lvm_param2_buffer)` + `write_param2`: set it to true in your lvm callback function, if you used `param2_data` and want to write it; `light`: LVM buffer data array of light, !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - you load it yourself: `vm_context.light = vm_context.light or vm_context.vm.get_light_data(vm_context.lvm_light_buffer)` `write_light`: set it to true in your lvm callback function, if you used `light` and want to write it; - `lvm_param2_buffer`: static `param2` buffer pointer, used to load `data2` array; + `lvm_param2_buffer`: static `param2` buffer pointer, used to load `param2_data` array; `shadow`: set it to false to disable shadow propagation; `heightmap`: mapgen object contanting y coordinates of ground level, !NO ANY DATA LOADS INTO IT BEFORE THE CALLBACKS! - load it yourself: diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index a64bc1e6f..7210d85c6 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -125,7 +125,7 @@ minetest.register_on_shutdown(function() end) local vm_context -- here will be many references and flags, like: param2, light_data, heightmap, biomemap, heatmap, humiditymap, gennotify, write_lvm, write_param2, shadow -local data, data2, light, area +local data, param2_data, light, area local current_blocks = {} local current_chunks = {} local lvm_buffer, lvm_param2_buffer, lvm_light_buffer = {}, {}, {} -- Static buffer pointers @@ -139,7 +139,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) area = VoxelArea:new({MinEdge=emin, MaxEdge=emax}) vm_context = { data = data, - data2 = data2, + param2_data = param2_data, light = light, area = area, lvm_buffer = lvm_buffer, @@ -270,7 +270,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) vm:set_data(data) end if vm_context.write_param2 then - vm:set_param2_data(data2) + vm:set_param2_data(vm_context.param2_data) end if vm_context.write_light then vm:set_light_data(light) @@ -291,7 +291,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) area = VoxelArea:new({MinEdge=minp, MaxEdge=maxp}) vm_context = { data = data, - data2 = data2, + param2_data = param2_data, light = light, area = area, lvm_buffer = lvm_buffer, @@ -314,7 +314,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) vm:set_data(data) end if vm_context.write_param2 then - vm:set_param2_data(data2) + vm:set_param2_data(param2_data) end if vm_context.write_light then vm:set_light_data(light) diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index 7107a2373..20978e26f 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -4,7 +4,8 @@ local modpath = minetest.get_modpath(minetest.get_current_modname()) -local mg_name = minetest.get_mapgen_setting("mg_name") +local mg_name = mcl_mapgen.name +local v6 = mcl_mapgen.v6 local math = math local vector = vector @@ -381,7 +382,7 @@ function mcl_core.generate_tree(pos, tree_type, options) local balloon = options and options.balloon if tree_type == nil or tree_type == OAK_TREE_ID then - if mg_name == "v6" then + if v6 then mcl_core.generate_v6_oak_tree(pos) else if balloon then @@ -396,7 +397,7 @@ function mcl_core.generate_tree(pos, tree_type, options) if two_by_two then mcl_core.generate_huge_spruce_tree(pos) else - if mg_name == "v6" then + if v6 then mcl_core.generate_v6_spruce_tree(pos) else mcl_core.generate_spruce_tree(pos) @@ -408,7 +409,7 @@ function mcl_core.generate_tree(pos, tree_type, options) if two_by_two then mcl_core.generate_huge_jungle_tree(pos) else - if mg_name == "v6" then + if v6 then mcl_core.generate_v6_jungle_tree(pos) else mcl_core.generate_jungle_tree(pos) @@ -786,7 +787,7 @@ function mcl_core.generate_huge_jungle_tree(pos) end -local grass_spread_randomizer = PseudoRandom(minetest.get_mapgen_setting("seed")) +local grass_spread_randomizer = PseudoRandom(mcl_mapgen.seed) function mcl_core.get_grass_palette_index(pos) local biome_data = minetest.get_biome_data(pos) diff --git a/mods/ITEMS/mcl_core/mod.conf b/mods/ITEMS/mcl_core/mod.conf index 45018df75..3d7f59245 100644 --- a/mods/ITEMS/mcl_core/mod.conf +++ b/mods/ITEMS/mcl_core/mod.conf @@ -1,4 +1,4 @@ name = mcl_core description = Core items of MineClone 2: Basic biome blocks (dirt, sand, stones, etc.), derived items, glass, sugar cane, cactus, barrier, mining tools, hand, craftitems, and misc. items which don't really fit anywhere else. -depends = mcl_autogroup, mcl_init, mcl_sounds, mcl_particles, mcl_util, mcl_worlds, doc_items, mcl_enchanting, mcl_colors +depends = mcl_autogroup, mcl_init, mcl_sounds, mcl_particles, mcl_util, mcl_worlds, doc_items, mcl_enchanting, mcl_colors, mcl_mapgen optional_depends = doc diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index f36bf8b9a..5a9d3582e 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -84,21 +84,9 @@ local c_realm_barrier = minetest.get_content_id("mcl_core:realm_barrier") local c_top_snow = minetest.get_content_id("mcl_core:snow") local c_snow_block = minetest.get_content_id("mcl_core:snowblock") local c_clay = minetest.get_content_id("mcl_core:clay") -local c_leaves = minetest.get_content_id("mcl_core:leaves") -local c_jungleleaves = minetest.get_content_id("mcl_core:jungleleaves") --local c_jungletree = minetest.get_content_id("mcl_core:jungletree") -local c_vine = minetest.get_content_id("mcl_core:vine") local c_air = minetest.CONTENT_AIR -local c_cocoas = nil -if minetest.get_modpath("mcl_cocoas") then - c_cocoas = { - minetest.get_content_id("mcl_cocoas:cocoa_1"), - minetest.get_content_id("mcl_cocoas:cocoa_2"), - minetest.get_content_id("mcl_cocoas:cocoa_3") - } -end - -- -- Ore generation -- @@ -1167,9 +1155,6 @@ minetest.set_mapgen_setting("mg_flags", mg_flags_str, true) return x, z end]] --- Perlin noise objects -local perlin_vines, perlin_vines_fine, perlin_vines_upwards, perlin_vines_length, perlin_vines_density - local dragon_spawn_pos = false local dragon_spawned, portal_generated = false, false @@ -1209,214 +1194,6 @@ function mcl_mapgen_core.generate_end_exit_portal(pos) portal_generated = true end - --- Buffers for LuaVoxelManip --- local lvm_buffer = {} --- local lvm_buffer_param2 = {} - --- Generate tree decorations in the bounding box. This adds: --- * Cocoa at jungle trees --- * Jungle tree vines --- * Oak vines in swamplands -local function generate_tree_decorations(minp, maxp, seed, data, param2_data, area, biomemap, lvm_used, pr) - if maxp.y < 0 then - return lvm_used - end - - local oaktree, oakleaves, jungletree, jungleleaves = {}, {}, {}, {} - local swampland = minetest.get_biome_id("Swampland") - local swampland_shore = minetest.get_biome_id("Swampland_shore") - local jungle = minetest.get_biome_id("Jungle") - local jungle_shore = minetest.get_biome_id("Jungle_shore") - local jungle_m = minetest.get_biome_id("JungleM") - local jungle_m_shore = minetest.get_biome_id("JungleM_shore") - local jungle_edge = minetest.get_biome_id("JungleEdge") - local jungle_edge_shore = minetest.get_biome_id("JungleEdge_shore") - local jungle_edge_m = minetest.get_biome_id("JungleEdgeM") - local jungle_edge_m_shore = minetest.get_biome_id("JungleEdgeM_shore") - - -- Modifier for Jungle M biome: More vines and cocoas - local dense_vegetation = false - - if biomemap then - -- Biome map available: Check if the required biome (jungle or swampland) - -- is in this mapchunk. We are only interested in trees in the correct biome. - -- The nodes are added if the correct biome is *anywhere* in the mapchunk. - -- TODO: Strictly generate vines in the correct biomes only. - local swamp_biome_found, jungle_biome_found = false, false - for b=1, #biomemap do - local id = biomemap[b] - - if not swamp_biome_found and (id == swampland or id == swampland_shore) then - oaktree = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:tree"}) - oakleaves = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:leaves"}) - swamp_biome_found = true - end - if not jungle_biome_found and (id == jungle or id == jungle_shore or id == jungle_m or id == jungle_m_shore or id == jungle_edge or id == jungle_edge_shore or id == jungle_edge_m or id == jungle_edge_m_shore) then - jungletree = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:jungletree"}) - jungleleaves = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:jungleleaves"}) - jungle_biome_found = true - end - if not dense_vegetation and (id == jungle_m or id == jungle_m_shore) then - dense_vegetation = true - end - if swamp_biome_found and jungle_biome_found and dense_vegetation then - break - end - end - else - -- If there is no biome map, we just count all jungle things we can find. - -- Oak vines will not be generated. - jungletree = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:jungletree"}) - jungleleaves = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:jungleleaves"}) - end - - local pos, treepos, dir - - if c_cocoas ~= nil then - local cocoachance = 40 - if dense_vegetation then - cocoachance = 32 - end - - -- Pass 1: Generate cocoas at jungle trees - for n = 1, #jungletree do - - pos = table.copy(jungletree[n]) - treepos = table.copy(pos) - - if minetest.find_node_near(pos, 1, {"mcl_core:jungleleaves"}) then - - dir = pr:next(1, cocoachance) - - if dir == 1 then - pos.z = pos.z + 1 - elseif dir == 2 then - pos.z = pos.z - 1 - elseif dir == 3 then - pos.x = pos.x + 1 - elseif dir == 4 then - pos.x = pos.x -1 - end - - local p_pos = area:index(pos.x, pos.y, pos.z) - local l = minetest.get_node_light(pos) - - if dir < 5 - and data[p_pos] == c_air - and l and l > 12 then - local c = pr:next(1, 3) - data[p_pos] = c_cocoas[c] - param2_data[p_pos] = minetest.dir_to_facedir(vector.subtract(treepos, pos)) - lvm_used = true - end - end - end - end - - -- Pass 2: Generate vines at jungle wood, jungle leaves in jungle and oak wood, oak leaves in swampland - perlin_vines = perlin_vines or minetest.get_perlin(555, 4, 0.6, 500) - perlin_vines_fine = perlin_vines_fine or minetest.get_perlin(43000, 3, 0.6, 1) - perlin_vines_length = perlin_vines_length or minetest.get_perlin(435, 4, 0.6, 75) - perlin_vines_upwards = perlin_vines_upwards or minetest.get_perlin(436, 3, 0.6, 10) - perlin_vines_density = perlin_vines_density or minetest.get_perlin(436, 3, 0.6, 500) - - -- Extra long vines in Jungle M - local maxvinelength = 7 - if dense_vegetation then - maxvinelength = 14 - end - local treething - for i=1, 4 do - if i==1 then - treething = jungletree - elseif i == 2 then - treething = jungleleaves - elseif i == 3 then - treething = oaktree - elseif i == 4 then - treething = oakleaves - end - - for n = 1, #treething do - pos = treething[n] - - treepos = table.copy(pos) - - local dirs = { - {x=1,y=0,z=0}, - {x=-1,y=0,z=0}, - {x=0,y=0,z=1}, - {x=0,y=0,z=-1}, - } - - for d = 1, #dirs do - local pos = vector.add(pos, dirs[d]) - local p_pos = area:index(pos.x, pos.y, pos.z) - - local vine_threshold = math.max(0.33333, perlin_vines_density:get_2d(pos)) - if dense_vegetation then - vine_threshold = vine_threshold * (2/3) - end - - if perlin_vines:get_2d(pos) > -1.0 and perlin_vines_fine:get_3d(pos) > vine_threshold and data[p_pos] == c_air then - - local rdir = {} - rdir.x = -dirs[d].x - rdir.y = dirs[d].y - rdir.z = -dirs[d].z - local param2 = minetest.dir_to_wallmounted(rdir) - - -- Determine growth direction - local grow_upwards = false - -- Only possible on the wood, not on the leaves - if i == 1 then - grow_upwards = perlin_vines_upwards:get_3d(pos) > 0.8 - end - if grow_upwards then - -- Grow vines up 1-4 nodes, even through jungleleaves. - -- This may give climbing access all the way to the top of the tree :-) - -- But this will be fairly rare. - local length = math.ceil(math.abs(perlin_vines_length:get_3d(pos)) * 4) - for l=0, length-1 do - local t_pos = area:index(treepos.x, treepos.y, treepos.z) - - if (data[p_pos] == c_air or data[p_pos] == c_jungleleaves or data[p_pos] == c_leaves) and mcl_core.supports_vines(minetest.get_name_from_content_id(data[t_pos])) then - data[p_pos] = c_vine - param2_data[p_pos] = param2 - lvm_used = true - - else - break - end - pos.y = pos.y + 1 - p_pos = area:index(pos.x, pos.y, pos.z) - treepos.y = treepos.y + 1 - end - else - -- Grow vines down, length between 1 and maxvinelength - local length = math.ceil(math.abs(perlin_vines_length:get_3d(pos)) * maxvinelength) - for l=0, length-1 do - if data[p_pos] == c_air then - data[p_pos] = c_vine - param2_data[p_pos] = param2 - lvm_used = true - - else - break - end - pos.y = pos.y - 1 - p_pos = area:index(pos.x, pos.y, pos.z) - end - end - end - end - - end - end - return lvm_used -end - -- Generate mushrooms in caves manually. -- Minetest's API does not support decorations in caves yet. :-( local function generate_underground_mushrooms(minp, maxp, seed) @@ -1604,8 +1381,8 @@ end -- Below the bedrock, generate air/void local function basic_safe(vm_context) local vm, data, emin, emax, area, minp, maxp, chunkseed, blockseed = vm_context.vm, vm_context.data, vm_context.emin, vm_context.emax, vm_context.area, vm_context.minp, vm_context.maxp, vm_context.chunkseed, vm_context.blockseed - vm_context.data2 = vm_context.data2 or vm:get_param2_data(vm_context.lvm_param2_buffer) - local data2 = vm_context.data2 + vm_context.param2_data = vm_context.param2_data or vm:get_param2_data(vm_context.lvm_param2_buffer) + local param2_data = vm_context.param2_data local lvm_used = false local pr = PseudoRandom(blockseed) @@ -1649,14 +1426,9 @@ local function basic_safe(vm_context) end end - -- Clay, vines, cocoas - -- lvm_used = generate_clay(minp, maxp, chunkseed, data, area, lvm_used) - vm_context.biomemap = vm_context.biomemap or minetest.get_mapgen_object("biomemap") local biomemap = vm_context.biomemap - lvm_used = generate_tree_decorations(minp, maxp, blockseed, data, data2, area, biomemap, lvm_used, pr) - ----- Interactive block fixing section ----- ----- The section to perform basic block overrides of the core mapgen generated world. ----- @@ -1714,8 +1486,8 @@ local function basic_safe(vm_context) if bn then local biome = minetest.registered_biomes[bn] if biome and biome._mcl_biome_type then - data2[p_pos] = biome._mcl_palette_index - lvm_used = true + param2_data[p_pos] = biome._mcl_palette_index + vm_context.write_param2 = true end end if data[p_pos] == c_dirt_with_grass_snow and p_pos_above and data[p_pos_above] ~= c_top_snow and data[p_pos_above] ~= c_snow_block then @@ -1829,6 +1601,7 @@ mcl_mapgen.register_mapgen_block_lvm(basic_safe, 1) local modpath = minetest.get_modpath(minetest.get_current_modname()) dofile(modpath .. "/clay.lua") +dofile(modpath .. "/tree_decoration.lua") if minetest.get_modpath("mcl_structures") then dofile(modpath .. "/structures.lua") end diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua index 3a25d1cfd..5c0632c98 100644 --- a/mods/MAPGEN/mcl_mapgen_core/structures.lua +++ b/mods/MAPGEN/mcl_mapgen_core/structures.lua @@ -163,16 +163,9 @@ local function spawn_witch_hut(p, nn, pr, vm_context) vm_context.biomemap = minetest_get_mapgen_object('biomemap') biomemap = vm_context.biomemap end - -- minetest.chat_send_all(minetest.serialize(biomemap)) local swampland = minetest.get_biome_id("Swampland") local swampland_shore = minetest.get_biome_id("Swampland_shore") local bi = xz_to_biomemap_index(p.x, p.z, vm_context.minp, vm_context.maxp) - if (biomemap[bi] == swampland) then - minetest.chat_send_all('swampland') - end - if (biomemap[bi] == swampland_shore) then - minetest.chat_send_all('swampland_shore') - end -- if biomemap[bi] ~= swampland and biomemap[bi] ~= swampland_shore then return end end diff --git a/mods/MAPGEN/mcl_mapgen_core/tree_decoration.lua b/mods/MAPGEN/mcl_mapgen_core/tree_decoration.lua new file mode 100644 index 000000000..5cdcd023e --- /dev/null +++ b/mods/MAPGEN/mcl_mapgen_core/tree_decoration.lua @@ -0,0 +1,251 @@ +-- Generate tree decorations in the bounding box. This adds: +-- * Cocoa at jungle trees +-- * Jungle tree vines +-- * Oak vines in swamplands + +local minetest_find_nodes_in_area = minetest.find_nodes_in_area +local minetest_find_node_near = minetest.find_node_near +local minetest_get_node_light = minetest.get_node_light +local minetest_dir_to_facedir = minetest.dir_to_facedir +local minetest_dir_to_wallmounted = minetest.dir_to_wallmounted +local table_copy = table.copy +local vector_subtract = vector.subtract +local vector_add = vector.add +local math_max = math.max +local math_ceil = math.ceil +local math_abs = math.abs + +local c_air = minetest.CONTENT_AIR +local c_cocoas +local c_jungleleaves = minetest.get_content_id("mcl_core:jungleleaves") +local c_leaves = minetest.get_content_id("mcl_core:leaves") +local c_vine = minetest.get_content_id("mcl_core:vine") + +if minetest.get_modpath("mcl_cocoas") then + c_cocoas = { + minetest.get_content_id("mcl_cocoas:cocoa_1"), + minetest.get_content_id("mcl_cocoas:cocoa_2"), + minetest.get_content_id("mcl_cocoas:cocoa_3"), + } +end + +local swampland +local swampland_shore +local jungle +local jungle_shore +local jungle_m +local jungle_m_shore +local jungle_edge +local jungle_edge_shore +local jungle_edge_m +local jungle_edge_m_shore + +local perlin_vines, perlin_vines_fine, perlin_vines_upwards, perlin_vines_length, perlin_vines_density + +local dirs = { + {x = 1, y = 0, z = 0}, + {x = -1, y = 0, z = 0}, + {x = 0, y = 0, z = 1}, + {x = 0, y = 0, z = -1}, +} + +local function generate_tree_decorations(vm_context) + local maxp = vm_context.maxp + if maxp.y < 0 then return end + local minp = vm_context.minp + + local data = vm_context.data + vm_context.param2_data = vm_context.param2_data or vm_context.vm:get_param2_data(vm_context.lvm_param2_buffer) + local param2_data = vm_context.param2_data + local area = vm_context.area + + local biomemap = vm_context.biomemap + + local pr = PseudoRandom(vm_context.chunkseed) + + local oaktree, oakleaves, jungletree, jungleleaves = {}, {}, {}, {} + + -- Modifier for Jungle M biome: More vines and cocoas + local dense_vegetation = false + + if biomemap then + swampland = swampland or minetest.get_biome_id("Swampland") + swampland_shore = swampland_shore or minetest.get_biome_id("Swampland_shore") + jungle = jungle or minetest.get_biome_id("Jungle") + jungle_shore = jungle_shore or minetest.get_biome_id("Jungle_shore") + jungle_m = jungle_m or minetest.get_biome_id("JungleM") + jungle_m_shore = jungle_m_shore or minetest.get_biome_id("JungleM_shore") + jungle_edge = jungle_edge or minetest.get_biome_id("JungleEdge") + jungle_edge_shore = jungle_edge_shore or minetest.get_biome_id("JungleEdge_shore") + jungle_edge_m = jungle_edge_m or minetest.get_biome_id("JungleEdgeM") + jungle_edge_m_shore = jungle_edge_m_shore or minetest.get_biome_id("JungleEdgeM_shore") + + -- Biome map available: Check if the required biome (jungle or swampland) + -- is in this mapchunk. We are only interested in trees in the correct biome. + -- The nodes are added if the correct biome is *anywhere* in the mapchunk. + -- TODO: Strictly generate vines in the correct biomes only. + local swamp_biome_found, jungle_biome_found = false, false + for b=1, #biomemap do + local id = biomemap[b] + + if not swamp_biome_found and (id == swampland or id == swampland_shore) then + oaktree = minetest_find_nodes_in_area(minp, maxp, {"mcl_core:tree"}) + oakleaves = minetest_find_nodes_in_area(minp, maxp, {"mcl_core:leaves"}) + swamp_biome_found = true + end + if not jungle_biome_found and (id == jungle or id == jungle_shore or id == jungle_m or id == jungle_m_shore or id == jungle_edge or id == jungle_edge_shore or id == jungle_edge_m or id == jungle_edge_m_shore) then + jungletree = minetest_find_nodes_in_area(minp, maxp, {"mcl_core:jungletree"}) + jungleleaves = minetest_find_nodes_in_area(minp, maxp, {"mcl_core:jungleleaves"}) + jungle_biome_found = true + end + if not dense_vegetation and (id == jungle_m or id == jungle_m_shore) then + dense_vegetation = true + end + if swamp_biome_found and jungle_biome_found and dense_vegetation then + break + end + end + else + -- If there is no biome map, we just count all jungle things we can find. + -- Oak vines will not be generated. + jungletree = minetest_find_nodes_in_area(minp, maxp, {"mcl_core:jungletree"}) + jungleleaves = minetest_find_nodes_in_area(minp, maxp, {"mcl_core:jungleleaves"}) + end + + local pos, treepos, dir + + if c_cocoas then + local cocoachance = 40 + if dense_vegetation then + cocoachance = 32 + end + + -- Pass 1: Generate cocoas at jungle trees + for n = 1, #jungletree do + + pos = table_copy(jungletree[n]) + treepos = table_copy(pos) + + if minetest_find_node_near(pos, 1, {"mcl_core:jungleleaves"}) then + + dir = pr:next(1, cocoachance) + + if dir == 1 then + pos.z = pos.z + 1 + elseif dir == 2 then + pos.z = pos.z - 1 + elseif dir == 3 then + pos.x = pos.x + 1 + elseif dir == 4 then + pos.x = pos.x -1 + end + + local p_pos = area:index(pos.x, pos.y, pos.z) + local l = minetest_get_node_light(pos) + + if dir < 5 + and data[p_pos] == c_air + and l and l > 12 then + local c = pr:next(1, 3) + data[p_pos] = c_cocoas[c] + vm_context.write = true + param2_data[p_pos] = minetest_dir_to_facedir(vector_subtract(treepos, pos)) + vm_context.write_param2 = true + end + end + end + end + + -- Pass 2: Generate vines at jungle wood, jungle leaves in jungle and oak wood, oak leaves in swampland + perlin_vines = perlin_vines or minetest.get_perlin(555, 4, 0.6, 500) + perlin_vines_fine = perlin_vines_fine or minetest.get_perlin(43000, 3, 0.6, 1) + perlin_vines_length = perlin_vines_length or minetest.get_perlin(435, 4, 0.6, 75) + perlin_vines_upwards = perlin_vines_upwards or minetest.get_perlin(436, 3, 0.6, 10) + perlin_vines_density = perlin_vines_density or minetest.get_perlin(436, 3, 0.6, 500) + + -- Extra long vines in Jungle M + local maxvinelength = 7 + if dense_vegetation then + maxvinelength = 14 + end + local treething + for i=1, 4 do + if i==1 then + treething = jungletree + elseif i == 2 then + treething = jungleleaves + elseif i == 3 then + treething = oaktree + elseif i == 4 then + treething = oakleaves + end + + for n = 1, #treething do + pos = treething[n] + + treepos = table_copy(pos) + + for d = 1, #dirs do + local pos = vector_add(pos, dirs[d]) + local p_pos = area:index(pos.x, pos.y, pos.z) + + local vine_threshold = math_max(0.33333, perlin_vines_density:get_2d(pos)) + if dense_vegetation then + vine_threshold = vine_threshold * (2/3) + end + + if perlin_vines:get_2d(pos) > -1.0 and perlin_vines_fine:get_3d(pos) > vine_threshold and data[p_pos] == c_air then + + local rdir = {} + rdir.x = -dirs[d].x + rdir.y = dirs[d].y + rdir.z = -dirs[d].z + local param2 = minetest_dir_to_wallmounted(rdir) + + -- Determine growth direction + local grow_upwards = false + -- Only possible on the wood, not on the leaves + if i == 1 then + grow_upwards = perlin_vines_upwards:get_3d(pos) > 0.8 + end + if grow_upwards then + -- Grow vines up 1-4 nodes, even through jungleleaves. + -- This may give climbing access all the way to the top of the tree :-) + -- But this will be fairly rare. + local length = math_ceil(math_abs(perlin_vines_length:get_3d(pos)) * 4) + for l=0, length-1 do + local t_pos = area:index(treepos.x, treepos.y, treepos.z) + + if (data[p_pos] == c_air or data[p_pos] == c_jungleleaves or data[p_pos] == c_leaves) and mcl_core.supports_vines(minetest.get_name_from_content_id(data[t_pos])) then + data[p_pos] = c_vine + param2_data[p_pos] = param2 + vm_context.write = true + else + break + end + pos.y = pos.y + 1 + p_pos = area:index(pos.x, pos.y, pos.z) + treepos.y = treepos.y + 1 + end + else + -- Grow vines down, length between 1 and maxvinelength + local length = math_ceil(math_abs(perlin_vines_length:get_3d(pos)) * maxvinelength) + for l=0, length-1 do + if data[p_pos] == c_air then + data[p_pos] = c_vine + param2_data[p_pos] = param2 + vm_context.write = true + else + break + end + pos.y = pos.y - 1 + p_pos = area:index(pos.x, pos.y, pos.z) + end + end + end + end + end + end +end + +mcl_mapgen.register_on_generated(generate_tree_decorations, 0) From 93922a00d51fbef3642905a9003b74b3f1a7f224 Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 17 Jan 2022 04:26:37 +0400 Subject: [PATCH 42/61] Find better places for Jungle Templates --- mods/CORE/mcl_mapgen/init.lua | 4 + mods/MAPGEN/mcl_structures/jungle_temple.lua | 77 +++++++++++++++----- 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 7210d85c6..35090b714 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -466,6 +466,10 @@ end local CS_NODES = mcl_mapgen.CS_NODES function mcl_mapgen.clamp_to_chunk(x, size) + if not size then + minetest.log("warning", "[mcl_mapgen] Couldn't clamp " .. tostring(x) .. " - missing size") + return x + end if size > CS_NODES then minetest.log("warning", "[mcl_mapgen] Couldn't clamp " .. tostring(x) .. " - given size " .. tostring(size) .. " greater than chunk size " .. tostring(mcl_mapgen.CS_NODES)) return x diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua index 414c2c53f..9bdf1d111 100644 --- a/mods/MAPGEN/mcl_structures/jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -8,11 +8,22 @@ local schematic_file = modpath .. "/schematics/mcl_structures_jungle_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 size = temple_schematic.size +local sx = size.x +local sy = size.y +local sz = size.z local offset = vector.round(vector.divide(size, 2)) offset.y = 5 +local ox = offset.x +local oy = offset.y +local oz = offset.z +local corner_x = sx - 3 +local corner_z = sz - 3 +local air_offset_x = ox - 6 +local air_offset_z = oz - 6 + local function on_placed(p1, rotation, pr, size) - local p2 = {x = p1.x + size.x - 1, y = p1.y + size.y - 1, z = p1.z + size.z - 1} + local p2 = {x = p1.x + sx - 1, y = p1.y + sy - 1, z = p1.z + sz - 1} -- Find chests. local chests = minetest.find_nodes_in_area(p1, {x = p2.x, y = p1.y + 5, z = p2.z}, "mcl_chests:chest") @@ -63,18 +74,45 @@ local function on_placed(p1, rotation, pr, size) end local function place(pos, rotation, pr) - mcl_structures.place_schematic({pos = vector.subtract(pos, offset), schematic = temple_schematic, pr = pr, on_placed = on_placed}) + mcl_structures.place_schematic({pos = pos, schematic = temple_schematic, pr = pr, on_placed = on_placed}) +end + +local mcl_mapgen_clamp_to_chunk = mcl_mapgen.clamp_to_chunk +local function process_pos(pos) + minetest.log('warning', minetest.pos_to_string(pos)) + return { + x = mcl_mapgen_clamp_to_chunk(pos.x - ox, sx), + y = mcl_mapgen_clamp_to_chunk(pos.y - oy, sy), + z = mcl_mapgen_clamp_to_chunk(pos.z - oz, sz), + } +end + +local function is_air(pos) + local node = minetest.get_node(pos) + return node.name == "air" end local function get_place_rank(pos) - local x, y, z = pos.x, pos.y, pos.z - local p1 = {x = x - 6, y = y, z = z - 6} - local p2 = {x = x + 6, y = y, z = z + 6} - local pos_list_air = minetest.find_nodes_in_area(p1, p2, {"air", "group:buildable_to", "group:deco_block", "group:water"}, false) - p1.y = y - 1 - p2.y = y - 1 - local pos_list_ground = minetest.find_nodes_in_area(p1, p2, node_list, false) - return #pos_list_ground + #pos_list_air + local x1 = pos.x + 1 + local x2 = x1 + corner_x + local z1 = pos.z + 1 + local z2 = z1 + corner_z + local y2 = pos.y + 1 + local y1 = y2 - 2 + if is_air({x = x1, y = y1, z = z1}) then return -1 end + if is_air({x = x2, y = y1, z = z1}) then return -1 end + if is_air({x = x1, y = y1, z = z2}) then return -1 end + if is_air({x = x2, y = y1, z = z2}) then return -1 end + + local p1 = {x = x1 + air_offset_x, y = y2, z = z1 + air_offset_z} + local p2 = {x = x2 - air_offset_x, y = y2, z = z2 + air_offset_z} + local pos_counter_air = #minetest.find_nodes_in_area(p1, p2, {"air", "group:buildable_to", "group:deco_block"}, false) + local pos_counter_air = pos_counter_air - #minetest.find_nodes_in_area(p1, p2, {"group:tree"}, false) + + local p1 = {x = x1 + 1, y = y1, z = z1 + 1} + local p2 = {x = x2 - 1, y = y1, z = z2 - 1} + local pos_counter_ground = #minetest.find_nodes_in_area(p1, p2, node_list, false) + return pos_counter_ground + pos_counter_air end mcl_structures.register_structure({ @@ -109,18 +147,17 @@ mcl_structures.register_structure({ -- local b = (math.floor(seed / 39) + 4) % 12 -- minetest.chat_send_all("seed=" .. tostring(seed) .. ", a=" .. tostring(a) .. ", b=" ..tostring(b)) -- if a ~= b then return end - local pos = pos_list[1] - if #pos_list > 1 then - local count = get_place_rank(pos) - for i = 2, #pos_list do - local pos_i = pos_list[i] - local count_i = get_place_rank(pos_i) - if count_i > count then - count = count_i - pos = pos_i - end + local pos + local count = -1 + for i = 1, #pos_list do + local pos_i = process_pos(pos_list[i]) + local count_i = get_place_rank(pos_i) + if count_i > count then + count = count_i + pos = pos_i end end + if count < 0 then return end local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, From d3265a2f721d87938cbd2352c8b3c55d338bb857 Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 17 Jan 2022 05:54:36 +0400 Subject: [PATCH 43/61] Find better place for jungle temples again, add cobbles to support some stair parts --- mods/CORE/mcl_mapgen/init.lua | 3 +++ mods/MAPGEN/mcl_structures/jungle_temple.lua | 26 +++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 35090b714..2d7e0eba7 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -488,3 +488,6 @@ function mcl_mapgen.clamp_to_chunk(x, size) end return x - overflow end +function mcl_mapgen.get_chunk_beginning(x) + return x - ((x + central_chunk_min_pos) % CS_NODES) +end diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua index 9bdf1d111..2fe1fdd2b 100644 --- a/mods/MAPGEN/mcl_structures/jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -22,9 +22,28 @@ local corner_z = sz - 3 local air_offset_x = ox - 6 local air_offset_z = oz - 6 +local function is_air(pos) + local node = minetest.get_node(pos) + return node.name == "air" +end + +local stair_support_node = {name = "mcl_core:cobble"} local function on_placed(p1, rotation, pr, size) local p2 = {x = p1.x + sx - 1, y = p1.y + sy - 1, z = p1.z + sz - 1} + -- Support stairs + local y = p1.y + 5 + local bottom = mcl_mapgen.get_chunk_beginning(y) + local stair_list = minetest.find_nodes_in_area({x = p1.x, y = y, z = p1.z}, {x = p2.x, y = y, z = p2.z}, {"mcl_stairs:stair_cobble"}, false) + for i = 1, #stair_list do + local pos = stair_list[i] + pos.y = y - 1 + while is_air(pos) and pos.y > bottom do + minetest.swap_node(pos, stair_support_node) + pos.y = pos.y - 1 + end + end + -- Find chests. local chests = minetest.find_nodes_in_area(p1, {x = p2.x, y = p1.y + 5, z = p2.z}, "mcl_chests:chest") @@ -87,11 +106,6 @@ local function process_pos(pos) } end -local function is_air(pos) - local node = minetest.get_node(pos) - return node.name == "air" -end - local function get_place_rank(pos) local x1 = pos.x + 1 local x2 = x1 + corner_x @@ -107,7 +121,7 @@ local function get_place_rank(pos) local p1 = {x = x1 + air_offset_x, y = y2, z = z1 + air_offset_z} local p2 = {x = x2 - air_offset_x, y = y2, z = z2 + air_offset_z} local pos_counter_air = #minetest.find_nodes_in_area(p1, p2, {"air", "group:buildable_to", "group:deco_block"}, false) - local pos_counter_air = pos_counter_air - #minetest.find_nodes_in_area(p1, p2, {"group:tree"}, false) + local pos_counter_air = pos_counter_air - 2 * (#minetest.find_nodes_in_area(p1, p2, {"group:tree"}, false)) local p1 = {x = x1 + 1, y = y1, z = z1 + 1} local p2 = {x = x2 - 1, y = y1, z = z2 - 1} From 8caf8c91dd7ed0e21e6fd74d32b1a64904fb963b Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 17 Jan 2022 06:17:52 +0400 Subject: [PATCH 44/61] Add more complex temple spawn conditions --- mods/MAPGEN/mcl_structures/desert_temple.lua | 6 ++++-- mods/MAPGEN/mcl_structures/jungle_temple.lua | 16 +++++++++------- mods/MAPGEN/mcl_structures/noise_indicator.lua | 3 ++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua index 682af9d4d..e4d4c10dc 100644 --- a/mods/MAPGEN/mcl_structures/desert_temple.lua +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -121,8 +121,7 @@ mcl_structures.register_structure({ deco_type = "simple", place_on = node_list, flags = "all_floors", - --fill_ratio = 0.00003, - fill_ratio = 0.003, + fill_ratio = 0.00003, y_min = 3, y_max = mcl_mapgen.overworld.max, height = 1, @@ -149,6 +148,9 @@ mcl_structures.register_structure({ local b = (math.floor(seed / 39) + 4) % 12 minetest.chat_send_all("seed=" .. tostring(seed) .. ", a=" .. tostring(a) .. ", b=" ..tostring(b)) if a ~= b then return end + mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100) + local current_noise_level = mcl_structures.perlin_noise:get_3d(minp) + if current_noise_level > -0.3 then return end local pos = pos_list[1] if #pos_list > 1 then local count = get_place_rank(pos) diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua index 2fe1fdd2b..210889e02 100644 --- a/mods/MAPGEN/mcl_structures/jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -135,9 +135,8 @@ mcl_structures.register_structure({ deco_type = "simple", place_on = node_list, flags = "all_floors", - --fill_ratio = 0.00003, - fill_ratio = 0.003, - y_min = 3, + fill_ratio = 0.0003, + y_min = -13, y_max = mcl_mapgen.overworld.max, height = 1, biomes = @@ -157,10 +156,13 @@ mcl_structures.register_structure({ }, }, on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) --- local a = seed % 14 --- local b = (math.floor(seed / 39) + 4) % 12 --- minetest.chat_send_all("seed=" .. tostring(seed) .. ", a=" .. tostring(a) .. ", b=" ..tostring(b)) --- if a ~= b then return end + local a = seed % 17 + local b = (math.ceil(seed / 123) - 4) % 17 + minetest.chat_send_all("seed=" .. tostring(seed) .. ", a=" .. tostring(a) .. ", b=" ..tostring(b)) + if a ~= b then return end + mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100) + local current_noise_level = mcl_structures.perlin_noise:get_3d(maxp) + if current_noise_level < 0.8 then return end local pos local count = -1 for i = 1, #pos_list do diff --git a/mods/MAPGEN/mcl_structures/noise_indicator.lua b/mods/MAPGEN/mcl_structures/noise_indicator.lua index 3f45040c0..19007ed16 100644 --- a/mods/MAPGEN/mcl_structures/noise_indicator.lua +++ b/mods/MAPGEN/mcl_structures/noise_indicator.lua @@ -26,9 +26,10 @@ local math_floor, math_ceil = math.floor, math.ceil mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100) local perlin_noise = mcl_structures.perlin_noise + local y0 = minp.y for x0 = minp.x, maxp.x do for z0 = minp.z, maxp.z do - local current_noise_level = perlin_noise:get_2d({x=x0, y=z0}) + local current_noise_level = perlin_noise:get_3d({x=x0, y=y0, z=z0}) local amount if current_noise_level < 0 then amount = math_max(math_ceil(current_noise_level * 9), -9) From 0e70e386ea7fa808745b4e9da7e0b5d15315be3d Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 17 Jan 2022 06:37:15 +0400 Subject: [PATCH 45/61] Add loot into jungle temple trapped chests --- mods/MAPGEN/mcl_structures/jungle_temple.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua index 210889e02..02b5f2361 100644 --- a/mods/MAPGEN/mcl_structures/jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -45,7 +45,7 @@ local function on_placed(p1, rotation, pr, size) end -- Find chests. - local chests = minetest.find_nodes_in_area(p1, {x = p2.x, y = p1.y + 5, z = p2.z}, "mcl_chests:chest") + local chests = minetest.find_nodes_in_area(p1, {x = p2.x, y = p1.y + 5, z = p2.z}, "mcl_chests:trapped_chest_small") -- Add desert temple loot into chests for c=1, #chests do From 6eb126da40fd9594276af536a3f31aff0a05782c Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 17 Jan 2022 06:48:59 +0400 Subject: [PATCH 46/61] Disable debugging tools --- mods/MAPGEN/mcl_structures/desert_temple.lua | 1 - mods/MAPGEN/mcl_structures/init.lua | 2 +- mods/MAPGEN/mcl_structures/jungle_temple.lua | 1 - .../MAPGEN/mcl_structures/noise_indicator.lua | 19 +++++++++++++++++-- mods/MAPGEN/mcl_structures/structures.lua | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua index e4d4c10dc..fbaa1fe20 100644 --- a/mods/MAPGEN/mcl_structures/desert_temple.lua +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -146,7 +146,6 @@ mcl_structures.register_structure({ on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) local a = seed % 14 local b = (math.floor(seed / 39) + 4) % 12 - minetest.chat_send_all("seed=" .. tostring(seed) .. ", a=" .. tostring(a) .. ", b=" ..tostring(b)) if a ~= b then return end mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100) local current_noise_level = mcl_structures.perlin_noise:get_3d(minp) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 65e538024..4d2eacf66 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -72,7 +72,7 @@ function mcl_structures.register_structure(def) local decoration_id if decoration then minetest.register_node(':' .. name, { - -- drawtype = "airlike", + drawtype = "airlike", sunlight_propagates = true, pointable = false, walkable = false, diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua index 02b5f2361..438eb1e7a 100644 --- a/mods/MAPGEN/mcl_structures/jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -158,7 +158,6 @@ mcl_structures.register_structure({ on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) local a = seed % 17 local b = (math.ceil(seed / 123) - 4) % 17 - minetest.chat_send_all("seed=" .. tostring(seed) .. ", a=" .. tostring(a) .. ", b=" ..tostring(b)) if a ~= b then return end mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100) local current_noise_level = mcl_structures.perlin_noise:get_3d(maxp) diff --git a/mods/MAPGEN/mcl_structures/noise_indicator.lua b/mods/MAPGEN/mcl_structures/noise_indicator.lua index 19007ed16..f48e4d9b2 100644 --- a/mods/MAPGEN/mcl_structures/noise_indicator.lua +++ b/mods/MAPGEN/mcl_structures/noise_indicator.lua @@ -1,3 +1,6 @@ +local step = 1 +local chunk_borders = true + local levels = { [-9] = "black", [-8] = "brown", @@ -27,8 +30,8 @@ mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100) local perlin_noise = mcl_structures.perlin_noise local y0 = minp.y - for x0 = minp.x, maxp.x do - for z0 = minp.z, maxp.z do + for x0 = minp.x, maxp.x, step do + for z0 = minp.z, maxp.z, step do local current_noise_level = perlin_noise:get_3d({x=x0, y=y0, z=z0}) local amount if current_noise_level < 0 then @@ -40,4 +43,16 @@ mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) minetest.set_node({x=x0, y=y0, z=z0}, {name = "mcl_core:glass_"..levels[amount]}) end end + if chunk_borders then + for x0 = minp.x, maxp.x, step do + for y0 = minp.y, maxp.y, step do + minetest.set_node({x=x0, y=y0, z=maxp.z}, {name = "mcl_core:glass"}) + end + end + for z0 = minp.z, maxp.z, step do + for y0 = minp.y, maxp.y, step do + minetest.set_node({x=maxp.x, y=y0, z=z0}, {name = "mcl_core:glass"}) + end + end + end end, -1) diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index 5bbc18774..5b7a65a7d 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -6,5 +6,5 @@ if not mcl_mapgen.singlenode then dofile(modpath .. "/jungle_temple.lua") dofile(modpath .. "/stronghold.lua") - dofile(modpath .. "/noise_indicator.lua") + -- dofile(modpath .. "/noise_indicator.lua") end From 30a0eb1d4aeac89e028df49b4e66478667511b46 Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 17 Jan 2022 20:03:46 +0400 Subject: [PATCH 47/61] Restore nether_portal in spawnstruct list --- mods/ITEMS/mcl_portals/mod.conf | 2 +- mods/ITEMS/mcl_portals/portal_nether.lua | 8 +- mods/MAPGEN/mcl_structures/init.lua | 134 ++++++++++--------- mods/MAPGEN/mcl_structures/jungle_temple.lua | 7 +- 4 files changed, 87 insertions(+), 64 deletions(-) diff --git a/mods/ITEMS/mcl_portals/mod.conf b/mods/ITEMS/mcl_portals/mod.conf index 5ea4a0498..d4b82cc58 100644 --- a/mods/ITEMS/mcl_portals/mod.conf +++ b/mods/ITEMS/mcl_portals/mod.conf @@ -1,4 +1,4 @@ name = mcl_portals description = Adds buildable portals to the Nether and End dimensions. -depends = mcl_mapgen, mcl_nether, mcl_end, mcl_particles, mcl_spawn, mcl_credits +depends = mcl_mapgen, mcl_nether, mcl_end, mcl_particles, mcl_spawn, mcl_credits, mcl_structures optional_depends = awards, doc diff --git a/mods/ITEMS/mcl_portals/portal_nether.lua b/mods/ITEMS/mcl_portals/portal_nether.lua index 5342d3dab..405e275d4 100644 --- a/mods/ITEMS/mcl_portals/portal_nether.lua +++ b/mods/ITEMS/mcl_portals/portal_nether.lua @@ -355,7 +355,7 @@ function build_nether_portal(pos, width, height, orientation, name, clear_before return pos end -function mcl_portals.spawn_nether_portal(pos, rot, pr, name) +function mcl_portals.spawn_nether_portal(pos, rot, pr, placer) if not pos then return end local o = 0 if rot then @@ -365,6 +365,10 @@ function mcl_portals.spawn_nether_portal(pos, rot, pr, name) o = random(0,1) end end + local name + if placer and placer:is_player() then + name = placer:get_player_name() + end build_nether_portal(pos, nil, nil, o, name, true) end @@ -753,6 +757,8 @@ local function teleport(obj, portal_pos) minetest.after(DELAY, teleport_no_delay, obj, portal_pos) end +mcl_structures.register_structure({name = "nether_portal", place_function = mcl_portals.spawn_nether_portal}) + minetest.register_abm({ label = "Nether portal teleportation and particles", nodenames = {PORTAL}, diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 4d2eacf66..ecb2b591e 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -19,6 +19,74 @@ local on_finished_chunk_callbacks = {} mcl_structures.perlin_noise = minetest.get_perlin(329, 3, 0.6, 100) +local spawnstruct_hint = S("Use /help spawnstruct to see a list of avaiable types.") + +local function dir_to_rotation(dir) + local ax, az = math.abs(dir.x), math.abs(dir.z) + if ax > az then + if dir.x < 0 then + return "270" + end + return "90" + end + if dir.z < 0 then + return "180" + end + return "0" +end + +local function spawnstruct_function(name, param) + local player = minetest.get_player_by_name(name) + if not player then return end + if param == "" then + minetest.chat_send_player(name, S("Error: No structure type given. Please use “/spawnstruct ”.")) + minetest.chat_send_player(name, spawnstruct_hint) + return + end + local struct = registered_structures[param] + if not struct then + struct = registered_structures[name_prefix .. param] + end + if not struct then + minetest.chat_send_player(name, S("Error: Unknown structure type. Please use “/spawnstruct ”.")) + minetest.chat_send_player(name, spawnstruct_hint) + return + end + local place = struct.place_function + if not place then return end + + local pos = player:get_pos() + if not pos then return end + local pr = PseudoRandom(math.floor(pos.x * 333 + pos.y * 19 - pos.z + 4)) + pos = vector.round(pos) + local dir = minetest.yaw_to_dir(player:get_look_horizontal()) + local rot = dir_to_rotation(dir) + place(pos, rot, pr, player) + minetest.chat_send_player(name, S("Structure placed.")) +end + +local function update_spawnstruct_chatcommand() + local spawnstruct_params = "" + for _, registered_structure in pairs(registered_structures) do + if spawnstruct_params ~= "" then + spawnstruct_params = spawnstruct_params .. " | " + end + spawnstruct_params = spawnstruct_params .. registered_structure.short_name + end + local def = { + params = spawnstruct_params, + description = S("Generate a pre-defined structure near your position."), + privs = {debug = true}, + func = spawnstruct_function, + } + local registered_chatcommands = minetest.registered_chatcommands + if registered_chatcommands["spawnstruct"] then + minetest.override_chatcommand("spawnstruct", def) + else + minetest.register_chatcommand("spawnstruct", def) + end +end + function process_mapgen_block_lvm(vm_context) local nodes = minetest.find_nodes_in_area(vm_context.minp, vm_context.maxp, {"group:struct"}, true) for node_name, pos_list in pairs(nodes) do @@ -54,14 +122,15 @@ end -- decoration - decoration definition, to use as structure seed (thanks cora for the idea) -- on_finished_block - callback, if needed, to use with decorations: funcion(vm_context, pos_list) -- on_finished_chunk - next callback if needed: funcion(minp, maxp, seed, vm_context, pos_list) --- place_function - callback to place schematic by /spawnstruct debug command: function(pos, rotation, pr) +-- place_function - callback to place schematic by /spawnstruct debug command: function(pos, rotation, pr, placer) -- on_placed - useful when you want to process the area after placement: function(pos, rotation, pr, size) function mcl_structures.register_structure(def) local short_name = def.name local name = "mcl_structures:" .. short_name local decoration = def.decoration - local on_finished_block = def.on_finished_block + local on_finished_block = def.on_finished_block local on_finished_chunk = def.on_finished_chunk + local place_function = def.place_function if not name then minetest.log('warning', 'Structure name is not passed for registration - ignoring') return @@ -108,12 +177,13 @@ function mcl_structures.register_structure(def) }) end registered_structures[name] = { - place_function = def.place_function, + place_function = place_function, on_finished_block = on_finished_block, on_finished_chunk = on_finished_chunk, decoration_id = decoration_id, short_name = short_name, } + update_spawnstruct_chatcommand() if on_finished_block then on_finished_block_callbacks[name] = on_finished_block if not use_process_mapgen_block_lvm then @@ -535,62 +605,4 @@ function mcl_structures.generate_end_gateway_portal(pos, rot) return mcl_structures.place_schematic(pos, path, rot or "0", nil, true) end -local function dir_to_rotation(dir) - local ax, az = math.abs(dir.x), math.abs(dir.z) - if ax > az then - if dir.x < 0 then - return "270" - end - return "90" - end - if dir.z < 0 then - return "180" - end - return "0" -end - dofile(modpath .. "/structures.lua") - --- Debug command -local spawnstruct_params = "" -for _, registered_structure in pairs(registered_structures) do - if spawnstruct_params ~= "" then - spawnstruct_params = spawnstruct_params .. " | " - end - spawnstruct_params = spawnstruct_params .. registered_structure.short_name -end -local spawnstruct_hint = S("Use /help spawnstruct to see a list of avaiable types.") -minetest.register_chatcommand("spawnstruct", { - params = spawnstruct_params, - description = S("Generate a pre-defined structure near your position."), - privs = {debug = true}, - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player then return end - if param == "" then - minetest.chat_send_player(name, S("Error: No structure type given. Please use “/spawnstruct ”.")) - minetest.chat_send_player(name, spawnstruct_hint) - return - end - local struct = registered_structures[param] - if not struct then - struct = registered_structures[name_prefix .. param] - end - if not struct then - minetest.chat_send_player(name, S("Error: Unknown structure type. Please use “/spawnstruct ”.")) - minetest.chat_send_player(name, spawnstruct_hint) - return - end - local place = struct.place_function - if not place then return end - - local pos = player:get_pos() - if not pos then return end - local pr = PseudoRandom(math.floor(pos.x * 333 + pos.y * 19 - pos.z + 4)) - pos = vector.round(pos) - local dir = minetest.yaw_to_dir(player:get_look_horizontal()) - local rot = dir_to_rotation(dir) - place(pos, rot, pr) - minetest.chat_send_player(name, S("Structure placed.")) - end -}) diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua index 438eb1e7a..1176b7be8 100644 --- a/mods/MAPGEN/mcl_structures/jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -29,7 +29,12 @@ end local stair_support_node = {name = "mcl_core:cobble"} local function on_placed(p1, rotation, pr, size) - local p2 = {x = p1.x + sx - 1, y = p1.y + sy - 1, z = p1.z + sz - 1} + local p2 + if rotation == "90" or rotation == "270" then + p2 = {x = p1.x + sz - 1, y = p1.y + sy - 1, z = p1.z + sx - 1} + else + p2 = {x = p1.x + sx - 1, y = p1.y + sy - 1, z = p1.z + sz - 1} + end -- Support stairs local y = p1.y + 5 From 4e832ba323e349ba4d13a5fa1f9fa8b217de488f Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 17 Jan 2022 20:43:30 +0400 Subject: [PATCH 48/61] Use per-chunk probability and 1-octave Perlin noise to simplify spawning temples --- mods/MAPGEN/mcl_structures/desert_temple.lua | 13 ++++++------ mods/MAPGEN/mcl_structures/init.lua | 20 ++++++++++++++++++- mods/MAPGEN/mcl_structures/jungle_temple.lua | 13 ++++++------ .../MAPGEN/mcl_structures/noise_indicator.lua | 10 ++++++---- mods/MAPGEN/mcl_structures/structures.lua | 2 +- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua index fbaa1fe20..ec06d5b81 100644 --- a/mods/MAPGEN/mcl_structures/desert_temple.lua +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -1,6 +1,9 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) +local per_chunk_probability = 11 +local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level + local node_list = {"mcl_core:sand", "mcl_core:sandstone", "mcl_core:redsand", "mcl_colorblocks:hardened_clay_orange"} local schematic_file = modpath .. "/schematics/mcl_structures_desert_temple.mts" @@ -144,12 +147,10 @@ mcl_structures.register_structure({ }, }, on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) - local a = seed % 14 - local b = (math.floor(seed / 39) + 4) % 12 - if a ~= b then return end - mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100) - local current_noise_level = mcl_structures.perlin_noise:get_3d(minp) - if current_noise_level > -0.3 then return end + local pr = PseudoRandom(seed + 999) + local random_number = pr:next(1, per_chunk_probability) + local noise = mcl_structures_get_perlin_noise_level(minp) + if (random_number + noise) < (per_chunk_probability - 1) then return end local pos = pos_list[1] if #pos_list > 1 then local count = get_place_rank(pos) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index ecb2b591e..35aca9346 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -17,7 +17,25 @@ local use_process_mapgen_chunk = false local on_finished_block_callbacks = {} local on_finished_chunk_callbacks = {} -mcl_structures.perlin_noise = minetest.get_perlin(329, 3, 0.6, 100) +local noise_params = { + offset = 0, + scale = 1, + spread = { + x = mcl_mapgen.CS_NODES, + y = mcl_mapgen.CS_NODES, + z = mcl_mapgen.CS_NODES, + }, + seed = 329, + octaves = 1, + persistence = 0.6, +} + +local perlin_noise +local get_perlin_noise_level = function(minp) + perlin_noise = perlin_noise or minetest.get_perlin(noise_params) + return perlin_noise:get_3d(minp) +end +mcl_structures.get_perlin_noise_level = get_perlin_noise_level local spawnstruct_hint = S("Use /help spawnstruct to see a list of avaiable types.") diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua index 1176b7be8..e25aab948 100644 --- a/mods/MAPGEN/mcl_structures/jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -1,6 +1,9 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) +local per_chunk_probability = 8 +local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level + local node_list = {"mcl_core:dirt_with_grass", "mcl_core:dirt", "mcl_core:stone", "mcl_core:granite", "mcl_core:gravel", "mcl_core:diorite"} local schematic_file = modpath .. "/schematics/mcl_structures_jungle_temple.mts" @@ -161,12 +164,10 @@ mcl_structures.register_structure({ }, }, on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) - local a = seed % 17 - local b = (math.ceil(seed / 123) - 4) % 17 - if a ~= b then return end - mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100) - local current_noise_level = mcl_structures.perlin_noise:get_3d(maxp) - if current_noise_level < 0.8 then return end + local pr = PseudoRandom(seed + 132) + local random_number = pr:next(1, per_chunk_probability) + local noise = mcl_structures_get_perlin_noise_level(minp) + if (random_number + noise) < (per_chunk_probability - 1) then return end local pos local count = -1 for i = 1, #pos_list do diff --git a/mods/MAPGEN/mcl_structures/noise_indicator.lua b/mods/MAPGEN/mcl_structures/noise_indicator.lua index f48e4d9b2..7cc130358 100644 --- a/mods/MAPGEN/mcl_structures/noise_indicator.lua +++ b/mods/MAPGEN/mcl_structures/noise_indicator.lua @@ -1,5 +1,5 @@ local step = 1 -local chunk_borders = true +local chunk_borders = false local levels = { [-9] = "black", @@ -26,13 +26,15 @@ local levels = { local math_min, math_max = math.min, math.max local math_floor, math_ceil = math.floor, math.ceil +local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level + +local noise_offset_x_and_z = math_floor(mcl_mapgen.CS_NODES/2) + mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) - mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100) - local perlin_noise = mcl_structures.perlin_noise local y0 = minp.y for x0 = minp.x, maxp.x, step do for z0 = minp.z, maxp.z, step do - local current_noise_level = perlin_noise:get_3d({x=x0, y=y0, z=z0}) + local current_noise_level = mcl_structures_get_perlin_noise_level({x = x0 - noise_offset_x_and_z, y = y0, z = z0 - noise_offset_x_and_z}) local amount if current_noise_level < 0 then amount = math_max(math_ceil(current_noise_level * 9), -9) diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index 5b7a65a7d..5bbc18774 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -6,5 +6,5 @@ if not mcl_mapgen.singlenode then dofile(modpath .. "/jungle_temple.lua") dofile(modpath .. "/stronghold.lua") - -- dofile(modpath .. "/noise_indicator.lua") + dofile(modpath .. "/noise_indicator.lua") end From a25770ecae6f3e75b7396139ca2218c74f0c545a Mon Sep 17 00:00:00 2001 From: kay27 Date: Tue, 18 Jan 2022 12:28:08 +0400 Subject: [PATCH 49/61] Spawn Nice Jungle Temple by cora --- mods/MAPGEN/mcl_structures/desert_temple.lua | 14 +- mods/MAPGEN/mcl_structures/jungle_temple.lua | 25 ++- .../mcl_structures/nice_jungle_temple.lua | 201 ++++++++++++++++++ .../mcl_structures_nice_jungle_temple.mts | Bin 0 -> 3997 bytes mods/MAPGEN/mcl_structures/structures.lua | 1 + 5 files changed, 228 insertions(+), 13 deletions(-) create mode 100644 mods/MAPGEN/mcl_structures/nice_jungle_temple.lua create mode 100644 mods/MAPGEN/mcl_structures/schematics/mcl_structures_nice_jungle_temple.mts diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua index ec06d5b81..e36484ae5 100644 --- a/mods/MAPGEN/mcl_structures/desert_temple.lua +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -1,7 +1,11 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) -local per_chunk_probability = 11 +local chance_per_chunk = 11 +local noise_multiplier = 1 +local random_offset = 999 +local struct_threshold = chance_per_chunk - 1 + local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level local node_list = {"mcl_core:sand", "mcl_core:sandstone", "mcl_core:redsand", "mcl_colorblocks:hardened_clay_orange"} @@ -147,10 +151,10 @@ mcl_structures.register_structure({ }, }, on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) - local pr = PseudoRandom(seed + 999) - local random_number = pr:next(1, per_chunk_probability) - local noise = mcl_structures_get_perlin_noise_level(minp) - if (random_number + noise) < (per_chunk_probability - 1) then return end + local pr = PseudoRandom(seed + random_offset) + local random_number = pr:next(1, chance_per_chunk) + local noise = mcl_structures_get_perlin_noise_level(minp) * noise_multiplier + if (random_number + noise) < struct_threshold then return end local pos = pos_list[1] if #pos_list > 1 then local count = get_place_rank(pos) diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua index e25aab948..90afc6085 100644 --- a/mods/MAPGEN/mcl_structures/jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -1,7 +1,10 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) -local per_chunk_probability = 8 +local chance_per_chunk = 9 +local noise_multiplier = 1.3 +local random_offset = 132 +local struct_threshold = chance_per_chunk - 1 local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level local node_list = {"mcl_core:dirt_with_grass", "mcl_core:dirt", "mcl_core:stone", "mcl_core:granite", "mcl_core:gravel", "mcl_core:diorite"} @@ -30,7 +33,14 @@ local function is_air(pos) return node.name == "air" end -local stair_support_node = {name = "mcl_core:cobble"} +local stair_support_node = { + {name = "mcl_core:cobble"}, + {name = "mcl_core:mossycobble"}, + {name = "mcl_core:stonebrick"}, + {name = "mcl_core:stonebrickmossy"}, + {name = "mcl_core:stonebrickcracked"}, +} + local function on_placed(p1, rotation, pr, size) local p2 if rotation == "90" or rotation == "270" then @@ -47,7 +57,7 @@ local function on_placed(p1, rotation, pr, size) local pos = stair_list[i] pos.y = y - 1 while is_air(pos) and pos.y > bottom do - minetest.swap_node(pos, stair_support_node) + minetest.swap_node(pos, stair_support_node[pr:next(1, #stair_support_node)]) pos.y = pos.y - 1 end end @@ -106,7 +116,6 @@ end local mcl_mapgen_clamp_to_chunk = mcl_mapgen.clamp_to_chunk local function process_pos(pos) - minetest.log('warning', minetest.pos_to_string(pos)) return { x = mcl_mapgen_clamp_to_chunk(pos.x - ox, sx), y = mcl_mapgen_clamp_to_chunk(pos.y - oy, sy), @@ -164,10 +173,10 @@ mcl_structures.register_structure({ }, }, on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) - local pr = PseudoRandom(seed + 132) - local random_number = pr:next(1, per_chunk_probability) - local noise = mcl_structures_get_perlin_noise_level(minp) - if (random_number + noise) < (per_chunk_probability - 1) then return end + local pr = PseudoRandom(seed + random_offset) + local random_number = pr:next(1, chance_per_chunk) + local noise = mcl_structures_get_perlin_noise_level(minp) * noise_multiplier + if (random_number + noise) < struct_threshold then return end local pos local count = -1 for i = 1, #pos_list do diff --git a/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua b/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua new file mode 100644 index 000000000..67fe97154 --- /dev/null +++ b/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua @@ -0,0 +1,201 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +local chance_per_chunk = 15 +local noise_multiplier = 1 +local random_offset = 133 +local struct_threshold = chance_per_chunk - 1 +local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level + +local node_list = {"mcl_core:dirt_with_grass", "mcl_core:dirt", "mcl_core:stone", "mcl_core:granite", "mcl_core:gravel", "mcl_core:diorite"} + +local schematic_file = modpath .. "/schematics/mcl_structures_nice_jungle_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 size = temple_schematic.size +local sx = size.x +local sy = size.y +local sz = size.z +local offset = vector.round(vector.divide(size, 2)) +offset.y = 5 + +local ox = offset.x +local oy = offset.y +local oz = offset.z +local corner_x = sx - 3 +local corner_z = sz - 3 +local air_offset_x = ox - 6 +local air_offset_z = oz - 6 + +local function is_air(pos) + local node = minetest.get_node(pos) + return node.name == "air" +end + +local stair_support_node = { + {name = "mcl_core:cobble"}, + {name = "mcl_core:mossycobble"}, + {name = "mcl_core:stonebrick"}, + {name = "mcl_core:stonebrickmossy"}, + {name = "mcl_core:stonebrickcracked"}, +} + +local nodes_to_be_supported = { + "mcl_stairs:stair_cobble", + "mcl_stairs:stair_stonebrickmossy", + "mcl_stairs:stair_stonebrickcracked", +} + +local function on_placed(p1, rotation, pr, size) + local p2 + if rotation == "90" or rotation == "270" then + p2 = {x = p1.x + sz - 1, y = p1.y + sy - 1, z = p1.z + sx - 1} + else + p2 = {x = p1.x + sx - 1, y = p1.y + sy - 1, z = p1.z + sz - 1} + end + + -- Support stairs + local y = p1.y + 5 + local bottom = mcl_mapgen.get_chunk_beginning(y) + local stair_list = minetest.find_nodes_in_area({x = p1.x, y = y, z = p1.z}, {x = p2.x, y = y, z = p2.z}, nodes_to_be_supported, false) + for i = 1, #stair_list do + local pos = stair_list[i] + pos.y = y - 1 + while is_air(pos) and pos.y > bottom do + minetest.swap_node(pos, stair_support_node[pr:next(1, #stair_support_node)]) + pos.y = pos.y - 1 + end + end + + -- Find chests. + local chests = minetest.find_nodes_in_area(p1, {x = p2.x, y = p1.y + 5, z = p2.z}, "mcl_chests:trapped_chest_small") + + -- Add desert temple loot into chests + for c=1, #chests do + local lootitems = mcl_loot.get_multi_loot({ + { + stacks_min = 2, + stacks_max = 4, + items = { + { itemstring = "mcl_mobitems:bone", weight = 25, amount_min = 4, amount_max=6 }, + { itemstring = "mcl_mobitems:rotten_flesh", weight = 25, amount_min = 3, amount_max=7 }, + { itemstring = "mcl_mobitems:spider_eye", weight = 25, amount_min = 1, amount_max=3 }, + { itemstring = "mcl_books:book", weight = 20, func = function(stack, pr) + mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) + end }, + { itemstring = "mcl_mobitems:saddle", weight = 20, }, + { itemstring = "mcl_core:apple_gold", weight = 20, }, + { itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 }, + { itemstring = "mcl_core:iron_ingot", weight = 15, amount_min = 1, amount_max = 5 }, + { itemstring = "mcl_core:emerald", weight = 15, amount_min = 1, amount_max = 3 }, + { itemstring = "", weight = 15, }, + { itemstring = "mobs_mc:iron_horse_armor", weight = 15, }, + { itemstring = "mobs_mc:gold_horse_armor", weight = 10, }, + { itemstring = "mobs_mc:diamond_horse_armor", weight = 5, }, + { itemstring = "mcl_core:diamond", weight = 5, amount_min = 1, amount_max = 3 }, + { itemstring = "mcl_core:apple_gold_enchanted", weight = 2, }, + } + }, + { + stacks_min = 4, + stacks_max = 4, + items = { + { itemstring = "mcl_mobitems:bone", weight = 10, amount_min = 1, amount_max = 8 }, + { itemstring = "mcl_mobitems:rotten_flesh", weight = 10, amount_min = 1, amount_max = 8 }, + { itemstring = "mcl_mobitems:gunpowder", weight = 10, amount_min = 1, amount_max = 8 }, + { itemstring = "mcl_core:sand", weight = 10, amount_min = 1, amount_max = 8 }, + { itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 }, + } + }}, pr) + mcl_structures.init_node_construct(chests[c]) + local meta = minetest.get_meta(chests[c]) + local inv = meta:get_inventory() + mcl_loot.fill_inventory(inv, "main", lootitems, pr) + end + +end + +local function place(pos, rotation, pr) + mcl_structures.place_schematic({pos = pos, schematic = temple_schematic, pr = pr, on_placed = on_placed}) +end + +local mcl_mapgen_clamp_to_chunk = mcl_mapgen.clamp_to_chunk +local function process_pos(pos) + return { + x = mcl_mapgen_clamp_to_chunk(pos.x - ox, sx), + y = mcl_mapgen_clamp_to_chunk(pos.y - oy, sy), + z = mcl_mapgen_clamp_to_chunk(pos.z - oz, sz), + } +end + +local function get_place_rank(pos) + local x1 = pos.x + 1 + local x2 = x1 + corner_x + local z1 = pos.z + 1 + local z2 = z1 + corner_z + local y2 = pos.y + 1 + local y1 = y2 - 2 + if is_air({x = x1, y = y1, z = z1}) then return -1 end + if is_air({x = x2, y = y1, z = z1}) then return -1 end + if is_air({x = x1, y = y1, z = z2}) then return -1 end + if is_air({x = x2, y = y1, z = z2}) then return -1 end + + local p1 = {x = x1 + air_offset_x, y = y2, z = z1 + air_offset_z} + local p2 = {x = x2 - air_offset_x, y = y2, z = z2 + air_offset_z} + local pos_counter_air = #minetest.find_nodes_in_area(p1, p2, {"air", "group:buildable_to", "group:deco_block"}, false) + local pos_counter_air = pos_counter_air - 2 * (#minetest.find_nodes_in_area(p1, p2, {"group:tree"}, false)) + + local p1 = {x = x1 + 1, y = y1, z = z1 + 1} + local p2 = {x = x2 - 1, y = y1, z = z2 - 1} + local pos_counter_ground = #minetest.find_nodes_in_area(p1, p2, node_list, false) + return pos_counter_ground + pos_counter_air +end + +mcl_structures.register_structure({ + name = "nice_jungle_temple", + decoration = { + deco_type = "simple", + place_on = node_list, + flags = "all_floors", + fill_ratio = 0.00021, + y_min = -20, + y_max = mcl_mapgen.overworld.max, + height = 1, + biomes = + mcl_mapgen.v6 and { + "Jungle" + } or { + "Jungle", + "JungleEdge", + "JungleEdgeM", + "JungleEdgeM_ocean", + "JungleEdge_ocean", + "JungleM", + "JungleM_ocean", + "JungleM_shore", + "Jungle_ocean", + "Jungle_shore", + }, + }, + on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) + local pr = PseudoRandom(seed + random_offset) + local random_number = pr:next(1, chance_per_chunk) + local noise = mcl_structures_get_perlin_noise_level(minp) * noise_multiplier + if (random_number + noise) < struct_threshold then return end + local pos + local count = -1 + for i = 1, #pos_list do + local pos_i = process_pos(pos_list[i]) + local count_i = get_place_rank(pos_i) + if count_i > count then + count = count_i + pos = pos_i + end + end + if count < 0 then return end + local pr = PseudoRandom(vm_context.chunkseed) + place(pos, nil, pr) + end, + place_function = place, +}) diff --git a/mods/MAPGEN/mcl_structures/schematics/mcl_structures_nice_jungle_temple.mts b/mods/MAPGEN/mcl_structures/schematics/mcl_structures_nice_jungle_temple.mts new file mode 100644 index 0000000000000000000000000000000000000000..8a9babb9bfc2206450f07356bc2166847c6a2e99 GIT binary patch literal 3997 zcmaJ@30zX?+CMBJASxg#sDmKnlA5?=qq%^Rf-P=TE|nl+N?3&JSQ-*4E+vUMwwalf znHH8AHuv6eU$WiOx;dGelVyEQla5m}_F3Od_kMTg`_B2D-}Aoj|M@@9`9JS-mi3&- z^#Bww1B?OFegFFa%mD~5Spwiv_@X%eE{VW9WmjtIH~d}k@gf0W{AKm`1>)z0BtdFg zs&|@%Cl(75;`pDYaj7XhkqE$lA*815+9`;aB=dKC4hWckLQ>O~a;18IHcQz)=dkz- z3SYwG?+_#agulXgl8hyYoFYgS@OSM@jmun0ED~f0B;KD!ai52AyAl%t;un_$fr$6b zlEd%z6B_3VSp0!|XC_MoaWopub?Ksg=Kd%48TlQv`GXfHPW~h_)%$2xKrg6u70xjGJGi1O}Pgn_F;P(T`Qv%w)gjCT@iR<(0(qS-V zHX6}<46$SHtUJw(dnSF$?%rNtZDF6&4CZFx&=d}MY0`CUfbNAI_xIH784))W^!?V`3Jm`N6;pW(#Bb$qrX(LmbH3Hf2j6 zblq-k#4>A0LkYuY%N3_VQ_Uu0`{!`pdR0JFPQmDwdqW*hfRO8@cP?3Eo~J7qsF(gh zq!RHV1iK9kiD<3;Rz>nNfxLN(nq))k@zwPOuihBDDi_ zGR#lB4W^D$hLFL@>*2&bUDS}M4|y>Nd>fJ3av!c{%U^46_zg;oGLH=ON$u6V#0f_` z0s-yoq%;vfH~L$T=gqwxKytTk9a!y= z3(Gy;6zT_?+@wWA7C8vvG<_hBY;zp><7&(BYFSm`Q%+P#DaN6KKoDQCJA$tw;PGM4 zo6qN;BX4jviFj(g?^vZ?wFQ|6JJ)|GQV#63!s6c6w;AAeYG$SNf%QF`HU!8Br-GCq zH!zfaNbv+RKvp)dpL}doXAyhdXs8<3^};SNM)3k;u-wjdt$)}*m4?fR^cCE8FR-Id z*CDl{{F=3AS~k{f$ofv6KUTjY2@1Zqk8(zhMCJr|f$!P`q@3klEW@PhIhl?*+VQ+h zYAg5Wod9LN7sx9qjdx-oo2^fr1Z}F7ZRvyF{H^|*io+nULh=V_Ipm0Pz-j5JI6zBP zKCsEoX=HUYq7)B}BuC|?+*89((GOnm5R$JPD}h9T?&1D~?(jv88|i8XL-fSg$`2-A zOXrc+)vV*^e~XcGWI=EQslKt3He=Mo$iJ zCHmC8Q1nPK(Cz9EX?{+HKu%q=Y!kp7_s>4)t?`huwu?{;kE@@sE@^MDZDA{5lO719 z;g+d@0g7#Xo5n}}_m%oDZ%X%ez*n6>1Sie9>V|CYxtJW>O;N_M48RYILHQQ*;kL>c zk-)kYn_pHJUvLtH#VS1dp~TZ&0=N2MS-lD3=iO0w(r@JW$0{W@uVS8>d);PO(wDMU zlnYUBOB9dhJC&S&-H+gO<%iF6-OVc-$hPf+ovRWL!nd-F@v%ptYW=@g!3@Z#m;rjk=+kR7ebgEuXp0YHoapACzN7d&%|fdj}rdZ= z1$o+P^9Pm^wCObIY{<;SjlLW@(@@%UoJl-M^(li0LjyVx_g+f1_^0@*=oXwQm(+Av zN6*ytNx#A#vnA}VV~dvAI0$#o6{3@|ZHqmlm3c#B$|!mw|EH61?O8}UsJjVXt%W@3 z`}K}hdk^sJS+O_kg0$r}DTO|xzGko4+J0M#Psv}vJ@xTUT8V7@9(ptPvMb6Ma7;(1 zuvuI9p{jNE&iJZrTZDv~2C^ElGxdmO(qQSWb;T^n5N(;}i}ue;XDBP|q1B;Kb+Dgo z8I+}8S8BtlgiG(cu$&XRuyI0QZXb7IU~kqitw<&ytNmE|iyYX1m%@wAC2#-kt3+2iM7||CntGz5*R+vexP@27}?7 z?}XrzAWxET{+-NbWG&3NNOIWg-bi=qAGQzYQP9JKa3m3+X*y1E`q(vg_ z*IwLjWiIRQ`A}cACzp>X<$DOujp8~^e5d&?)?%>n<&Pgel;@Cr3P@%if?+sjnEh z=L*e|!ZL^UADbq<8f&v$0r3QgMsrGK{l#E*j%Ms!?@`Itr($I=YYP*^|nsBEZmL8#UzpfaAm6&Kb{R`xp8+fCXgA-s&*5- zkOl03GyGMbp*yTmdV!3%5X<#+Bkdt%9s^cxbXOj=Z61M@d<`29D9>Zje^xg3T9jw$ zy$U}{8$15iTCKTYceX6>b^AdErW`ewRldPjcz0Xb8t05q8mcmP)tMh=<=&j)Fv7;N zm3??_ZcoI+;o*q}N;qzUW`5ro6==kT0#EekqSTt=_%7p1WF^f1%UN?MgB0|J6_R=<#X=_VfR zk!nUkb1iNuT4S);5oPeol@(4=nXwu!jLMQvwXa5#`xO9-+;0zl>`(2m4~Q6YrEn-s z9Yh6(eO1Y0^2&#fUMX!-V55L<=1 zL+3N+4I{$%bCiH;1l#h+Iv7l-Pwk{1Rw>hpX1>aLYqAF0z0?_Ci|RWH*10|bVhH;V zSmrO)Z|nhi9Xa$80oiwO&8_b>N@gmU;&dIY`k8P@<@q|W9O2MRlOb2v%|hB@t+aOL z)KZp;9;(=HoQo0A*{X4+lFN*)b~Z8~R*>=v36caJf(3&$=G$dIGw`&$%!IYNqg%_Z z%d4h~ii)_*c(!~H6@_$8s&eJt>>KGswM|m25;bVs6@&DKBZ#bn@08FZ3PR!_iYd?^ z^5|EvRHdaO_o$TaCGHQdHYuM6Hw5R>|OE*h%T>2Q#CxqI&lf2AFpVx3?gvH4-Xkn#_ zT1Y$Cl|Smjs_je1hgSwj%!=Ez;8MhJK_pCAp(;gj^u!aawW^U(AXKFs%dZSlR3KX+ z@fhJ-0W_arn&U}&&F&k~dk-(bQ^a!k*FRi!wAOQP<{{js=%Fhd~ zQE)5fb+dwaY&(9C86p%%imiUo^9xrL Date: Tue, 18 Jan 2022 12:34:50 +0400 Subject: [PATCH 50/61] Remove duplicated setting --- minetest.conf | 2 -- 1 file changed, 2 deletions(-) diff --git a/minetest.conf b/minetest.conf index f6524c88d..97d1f5cd6 100644 --- a/minetest.conf +++ b/minetest.conf @@ -27,8 +27,6 @@ movement_gravity = 10.4 # Mapgen stuff -max_block_generate_distance = 13 - # altitude_chill and altitude_dry doesn't go well together with MCL2 biomes # which already include "snowed" variants as you go higher. # humid_rivers would cause the MushroomIsland biome to appear frequently around rivers. From da606acfd1da4644a3b91fe57c136c0b8b628d4d Mon Sep 17 00:00:00 2001 From: kay27 Date: Tue, 18 Jan 2022 19:17:20 +0400 Subject: [PATCH 51/61] Add old structures to new mod --- mods/MAPGEN/mcl_mapgen_core/clay.lua | 73 +++++++------- mods/MAPGEN/mcl_mapgen_core/structures.lua | 36 ------- mods/MAPGEN/mcl_structures/desert_temple.lua | 3 +- mods/MAPGEN/mcl_structures/desert_well.lua | 94 +++++++++++++++++++ mods/MAPGEN/mcl_structures/fossil.lua | 53 +++++++++++ mods/MAPGEN/mcl_structures/init.lua | 46 +++------ mods/MAPGEN/mcl_structures/jungle_temple.lua | 19 +++- mods/MAPGEN/mcl_structures/mod.conf | 2 +- .../mcl_structures/nice_jungle_temple.lua | 17 +++- mods/MAPGEN/mcl_structures/structures.lua | 5 +- 10 files changed, 228 insertions(+), 120 deletions(-) create mode 100644 mods/MAPGEN/mcl_structures/desert_well.lua create mode 100644 mods/MAPGEN/mcl_structures/fossil.lua diff --git a/mods/MAPGEN/mcl_mapgen_core/clay.lua b/mods/MAPGEN/mcl_mapgen_core/clay.lua index cad6c7d85..56e0e023f 100644 --- a/mods/MAPGEN/mcl_mapgen_core/clay.lua +++ b/mods/MAPGEN/mcl_mapgen_core/clay.lua @@ -4,15 +4,22 @@ local c_clay = minetest.get_content_id("mcl_core:clay") local perlin_clay -mcl_mapgen.register_mapgen_lvm(function(c) - local minp, maxp, blockseed, voxelmanip_data, voxelmanip_area, lvm_used = c.minp, c.maxp, c.chunkseed, c.data, c.area, c.write or false - -- TODO: Make clay generation reproducible for same seed. - if maxp.y < -5 or minp.y > 0 then - return c - end - c.vm = c.vm or mcl_mapgen.get_voxel_manip(c) +local math_max = math.max +local math_min = math.min +local math_floor = math.floor +local math_abs = math.abs +local offset = math_floor(mcl_mapgen.BS / 2) +local minetest_get_item_group = minetest.get_item_group +local minetest_get_name_from_content_id = minetest.get_name_from_content_id - minetest.log("warning", "CLAY!") +mcl_mapgen.register_mapgen_block_lvm(function(c) + local minp, maxp, blockseed, voxelmanip_data, voxelmanip_area = c.minp, c.maxp, c.blockseed, c.data, c.area + local max_y = maxp.y + if max_y < -7 then return end + local min_y = minp.y + if min_y > 0 then return end + + c.vm = c.vm or mcl_mapgen.get_voxel_manip(c) local pr = PseudoRandom(blockseed) @@ -25,40 +32,32 @@ mcl_mapgen.register_mapgen_lvm(function(c) persist = 0.0 }) - for y=math.max(minp.y, 0), math.min(maxp.y, -8), -1 do + for y = math_max(min_y, -8), math_min(max_y, 0) do -- Assume X and Z lengths are equal - local divlen = 4 - local divs = (maxp.x-minp.x)/divlen+1; - for divx=0+1,divs-2 do - for divz=0+1,divs-2 do + local x = minp.x + offset + pr:next(-2, 2) + local z = minp.z + offset + pr:next(-2, 2) + if perlin_clay:get_3d({x = x, y = y, z = z}) + pr:next(1, 20) > 19 then -- Get position and shift it a bit randomly so the clay do not obviously appear in a grid - local cx = minp.x + math.floor((divx+0.5)*divlen) + pr:next(-1,1) - local cz = minp.z + math.floor((divz+0.5)*divlen) + pr:next(-1,1) - - local water_pos = voxelmanip_area:index(cx, y+1, cz) - local waternode = voxelmanip_data[water_pos] - local surface_pos = voxelmanip_area:index(cx, y, cz) - local surfacenode = voxelmanip_data[surface_pos] - - local genrnd = pr:next(1, 20) - if genrnd == 1 and perlin_clay:get_3d({x=cx,y=y,z=cz}) > 0 and waternode == c_water and - (surfacenode == c_dirt or minetest.get_item_group(minetest.get_name_from_content_id(surfacenode), "sand") == 1) then - local diamondsize = pr:next(1, 3) - for x1 = -diamondsize, diamondsize do - for z1 = -(diamondsize - math.abs(x1)), diamondsize - math.abs(x1) do - local ccpos = voxelmanip_area:index(cx+x1, y, cz+z1) - local claycandidate = voxelmanip_data[ccpos] - if voxelmanip_data[ccpos] == c_dirt or minetest.get_item_group(minetest.get_name_from_content_id(claycandidate), "sand") == 1 then - voxelmanip_data[ccpos] = c_clay - minetest.log("warning", "CLAY! "..minetest.pos_to_string({x=cx+x1,y=y,z=cz+z1})) - lvm_used = true + local water_pos = voxelmanip_area:index(x, y + 1, z) + local water_node = voxelmanip_data[water_pos] + if water_node == c_water or water_node == c_clay then + local surface_pos = voxelmanip_area:index(x, y, z) + local surface_node = voxelmanip_data[surface_pos] + if (surface_node == c_dirt or surface_node == c_clay or minetest_get_item_group(minetest_get_name_from_content_id(surface_node), "sand") == 1) then + local diamondsize = pr:next(1, 3) + for x1 = -diamondsize, diamondsize do + local abs_x1 = math_abs(x1) + for z1 = -(diamondsize - abs_x1), diamondsize - abs_x1 do + local ccpos = voxelmanip_area:index(x + x1, y, z + z1) + local claycandidate = voxelmanip_data[ccpos] + if voxelmanip_data[ccpos] == c_dirt or minetest_get_item_group(minetest_get_name_from_content_id(claycandidate), "sand") == 1 then + voxelmanip_data[ccpos] = c_clay + c.write = true + end + end end end - end end end - end end - c.write = lvm_used - return c end) diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua index 5c0632c98..ed9752db8 100644 --- a/mods/MAPGEN/mcl_mapgen_core/structures.lua +++ b/mods/MAPGEN/mcl_mapgen_core/structures.lua @@ -81,25 +81,6 @@ end max_noise = max_noise * octaves max_noise = offset + scale * max_noise -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 - -- if pr:next(1,12000) ~= 1 then return end - mcl_structures.call_struct(p, "desert_temple", nil, pr) - return true -end - -local function spawn_desert_well(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 - local desert_well_prob = minecraft_chunk_probability(1000, vm_context.minp, vm_context.maxp) - -- if pr:next(1, desert_well_prob) ~= 1 then return end - local surface = minetest_find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, {x=p.x+5, y=p.y-1, z=p.z+5}, "mcl_core:sand") - if #surface < 25 then return end - mcl_structures.call_struct(p, "desert_well", nil, pr) - return true -end - local function spawn_igloo(p, nn, pr, vm_context) if nn ~= "mcl_core:snowblock" and nn ~= "mcl_core:snow" and minetest_get_item_group(nn, "grass_block_snow") ~= 1 then return end -- if pr:next(1, 4400) ~= 1 then return end @@ -112,23 +93,6 @@ local function spawn_igloo(p, nn, pr, vm_context) return true end -local function spawn_fossil(p, nn, pr, vm_context) - -- if chunk_has_desert_temple or p.y < 4 then return end - if p.y < 4 then return end - if nn ~= "mcl_core:sandstone" and nn ~= "mcl_core:sand" then return end - local fossil_prob = minecraft_chunk_probability(64, vm_context.minp, vm_context.maxp) - if pr:next(1, fossil_prob) ~= 1 then return end - -- Spawn fossil below desert surface between layers 40 and 49 - local p1 = {x=p.x, y=pr:next(mcl_worlds.layer_to_y(40), mcl_worlds.layer_to_y(49)), z=p.z} - -- Very rough check of the environment (we expect to have enough stonelike nodes). - -- Fossils may still appear partially exposed in caves, but this is O.K. - local p2 = vector.add(p1, 4) - local nodes = minetest_find_nodes_in_area(p1, p2, {"mcl_core:sandstone", "mcl_core:stone", "mcl_core:diorite", "mcl_core:andesite", "mcl_core:granite", "mcl_core:stone_with_coal", "mcl_core:dirt", "mcl_core:gravel"}) - if #nodes < 100 then return end - -- >= 80% - mcl_structures.call_struct(p1, "fossil", nil, pr) -end - local witch_hut_offsets = { ["0"] = { {x=1, y=0, z=1}, {x=1, y=0, z=5}, {x=6, y=0, z=1}, {x=6, y=0, z=5}, diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua index e36484ae5..53b86acbc 100644 --- a/mods/MAPGEN/mcl_structures/desert_temple.lua +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -4,6 +4,7 @@ local modpath = minetest.get_modpath(modname) local chance_per_chunk = 11 local noise_multiplier = 1 local random_offset = 999 +local scanning_ratio = 0.00003 local struct_threshold = chance_per_chunk - 1 local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level @@ -128,7 +129,7 @@ mcl_structures.register_structure({ deco_type = "simple", place_on = node_list, flags = "all_floors", - fill_ratio = 0.00003, + fill_ratio = scanning_ratio, y_min = 3, y_max = mcl_mapgen.overworld.max, height = 1, diff --git a/mods/MAPGEN/mcl_structures/desert_well.lua b/mods/MAPGEN/mcl_structures/desert_well.lua new file mode 100644 index 000000000..93769f458 --- /dev/null +++ b/mods/MAPGEN/mcl_structures/desert_well.lua @@ -0,0 +1,94 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +local chance_per_chunk = 60 +local noise_multiplier = 1 +local random_offset = 999 +local scanning_ratio = 0.00001 +local struct_threshold = chance_per_chunk - 1 + +local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level + +local node_list = {"mcl_core:sand", "mcl_core:sandstone", "mcl_core:redsand", "mcl_colorblocks:hardened_clay_orange"} + +local schematic_file = modpath .. "/schematics/mcl_structures_desert_well.mts" + +local well_schematic_lua = minetest.serialize_schematic(schematic_file, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic" +local well_schematic = loadstring(well_schematic_lua)() + +local red_well_schematic_lua = minetest.serialize_schematic(schematic_file, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic" +red_well_schematic_lua = red_well_schematic_lua:gsub("mcl_core:sand", "mcl_core:redsand") +red_well_schematic_lua = red_well_schematic_lua:gsub("mcl_stairs:slab_sandstone", "mcl_stairs:slab_redsandstone") +local red_well_schematic = loadstring(red_well_schematic_lua)() + +local function place(pos, rotation, pr) + local pos_below = {x = pos.x, y = pos.y - 1, z = pos.z} + local pos_well = {x = pos.x, y = pos.y - 2, 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_well, rotaton = rotation, schematic = red_well_schematic, pr = pr}) + else + mcl_structures.place_schematic({pos = pos_well, rotaton = rotation, schematic = well_schematic, pr = pr}) + end +end + +local function get_place_rank(pos) + local x, y, z = pos.x, pos.y - 1, pos.z + local p1 = {x = x , y = y, z = z } + local p2 = {x = x + 5, y = y, z = z + 5} + local post_pos_list_surface = #minetest.find_nodes_in_area(p1, p2, node_list, false) + local other_pos_list_surface = #minetest.find_nodes_in_area(p1, p2, "group:opaque", false) + return post_pos_list_surface * 5 + other_pos_list_surface +end + +mcl_structures.register_structure({ + name = "desert_well", + decoration = { + deco_type = "simple", + place_on = node_list, + flags = "all_floors", + fill_ratio = scanning_ratio, + y_min = -5, + y_max = mcl_mapgen.overworld.max, + height = 1, + biomes = not mcl_mapgen.v6 and { + "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_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) + local pr = PseudoRandom(seed + random_offset) + local random_number = pr:next(1, chance_per_chunk) + local noise = mcl_structures_get_perlin_noise_level(minp) * noise_multiplier + if (random_number + noise) < struct_threshold then return end + local pos = pos_list[1] + if #pos_list > 1 then + local count = get_place_rank(pos) + for i = 2, #pos_list do + local pos_i = pos_list[i] + local count_i = get_place_rank(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, + place_function = place, +}) diff --git a/mods/MAPGEN/mcl_structures/fossil.lua b/mods/MAPGEN/mcl_structures/fossil.lua new file mode 100644 index 000000000..b26b7320a --- /dev/null +++ b/mods/MAPGEN/mcl_structures/fossil.lua @@ -0,0 +1,53 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +local chance_per_block = mcl_structures.from_16x16_to_block_inverted_chance(64) +local noise_multiplier = 2 +local random_offset = 5 +local struct_threshold = chance_per_block - 1 +local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level +local minetest_find_nodes_in_area = minetest.find_nodes_in_area +local min_y = mcl_worlds.layer_to_y(40) +local max_y = mcl_worlds.layer_to_y(49) +local fossils = { + "mcl_structures_fossil_skull_1.mts", -- 4×5×5 + "mcl_structures_fossil_skull_2.mts", -- 5×5×5 + "mcl_structures_fossil_skull_3.mts", -- 5×5×7 + "mcl_structures_fossil_skull_4.mts", -- 7×5×5 + "mcl_structures_fossil_spine_1.mts", -- 3×3×13 + "mcl_structures_fossil_spine_2.mts", -- 5×4×13 + "mcl_structures_fossil_spine_3.mts", -- 7×4×13 + "mcl_structures_fossil_spine_4.mts", -- 8×5×13 +} +local nodes_for_fossil = {"mcl_core:sandstone", "mcl_core:stone", "mcl_core:diorite", "mcl_core:andesite", "mcl_core:granite", "mcl_core:stone_with_coal", "mcl_core:dirt", "mcl_core:gravel"} + +function spawn_fossil(pos, rotation, pr, placer) + -- Generates one out of 8 possible fossil pieces + local def = { + pos = {x = pos.x, y = pos.y - 1, z = pos.z}, + schematic = modpath .. "/schematics/" .. fossils[pr:next(1, #fossils)], + rotation = rotation, + pr = pr, + } + mcl_structures.place_schematic(def) +end + +mcl_mapgen.register_mapgen_block(function(minp, maxp, seed) + local p1 = table.copy(minp) + local y1 = p1.y + if y1 > max_y then return end + local p2 = table.copy(maxp) + local y2 = p2.y + if y2 < min_y then return end + local pr = PseudoRandom(seed + random_offset) + local random_number = pr:next(1, chance_per_block) + p1.y = math.max(y1, min_y) + local noise = mcl_structures_get_perlin_noise_level(p1) * noise_multiplier + if (random_number + noise) < struct_threshold then return end + p2.y = math.min(y2, max_y) + local nodes = minetest_find_nodes_in_area(p1, p2, nodes_for_fossil, false) + if #nodes < 100 then return end + spawn_fossil(p1, nil, pr) +end, 1000) + +mcl_structures.register_structure({name = 'fossil', place_function = spawn_fossil}) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 35aca9346..c8de04a64 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -337,9 +337,7 @@ function mcl_structures.call_struct(pos, struct_style, rotation, pr, callback) if not rotation then rotation = "random" end - if struct_style == "desert_well" then - return mcl_structures.generate_desert_well(pos, rotation) - elseif struct_style == "igloo" then + if struct_style == "igloo" then return mcl_structures.generate_igloo(pos, rotation, pr) elseif struct_style == "witch_hut" then return mcl_structures.generate_witch_hut(pos, rotation) @@ -349,8 +347,6 @@ function mcl_structures.call_struct(pos, struct_style, rotation, pr, callback) return mcl_structures.generate_ice_spike_large(pos, rotation) elseif struct_style == "boulder" then return mcl_structures.generate_boulder(pos, rotation, pr) - elseif struct_style == "fossil" then - return mcl_structures.generate_fossil(pos, rotation, pr) elseif struct_style == "end_exit_portal" then return mcl_structures.generate_end_exit_portal(pos, rotation, pr, callback) elseif struct_style == "end_exit_portal_open" then @@ -380,17 +376,6 @@ function mcl_structures.generate_end_portal(pos, rotation, pr) end end -function mcl_structures.generate_desert_well(pos, rot) - local newpos = {x=pos.x,y=pos.y-2,z=pos.z} - local path = modpath.."/schematics/mcl_structures_desert_well.mts" - return mcl_structures.place_schematic({ - pos = newpos, - schematic = path, - rotation = rot or "0", - force_placement = true - }) -end - function mcl_structures.generate_igloo(pos, rotation, pr) -- Place igloo local success, rotation = mcl_structures.generate_igloo_top(pos, pr) @@ -590,24 +575,6 @@ function mcl_structures.generate_ice_spike_large(pos, rotation) return minetest.place_schematic(pos, path, rotation or "random", nil, false) -- don't serialize schematics for registered biome decorations, for MT 5.4.0 end -function mcl_structures.generate_fossil(pos, rotation, pr) - -- Generates one out of 8 possible fossil pieces - local newpos = {x=pos.x,y=pos.y-1,z=pos.z} - local fossils = { - "mcl_structures_fossil_skull_1.mts", -- 4×5×5 - "mcl_structures_fossil_skull_2.mts", -- 5×5×5 - "mcl_structures_fossil_skull_3.mts", -- 5×5×7 - "mcl_structures_fossil_skull_4.mts", -- 7×5×5 - "mcl_structures_fossil_spine_1.mts", -- 3×3×13 - "mcl_structures_fossil_spine_2.mts", -- 5×4×13 - "mcl_structures_fossil_spine_3.mts", -- 7×4×13 - "mcl_structures_fossil_spine_4.mts", -- 8×5×13 - } - local r = pr:next(1, #fossils) - local path = modpath.."/schematics/"..fossils[r] - return mcl_structures.place_schematic(newpos, path, rotation or "random", nil, true) -end - function mcl_structures.generate_end_exit_portal(pos, rot, pr, callback) local path = modpath.."/schematics/mcl_structures_end_exit_portal.mts" return mcl_structures.place_schematic(pos, path, rot or "0", {["mcl_portals:portal_end"] = "air"}, true, nil, callback) @@ -623,4 +590,15 @@ function mcl_structures.generate_end_gateway_portal(pos, rot) return mcl_structures.place_schematic(pos, path, rot or "0", nil, true) end +local chunk_square = mcl_mapgen.CS_NODES * mcl_mapgen.CS_NODES +local block_square = mcl_mapgen.BS * mcl_mapgen.BS + +function mcl_structures.from_16x16_to_chunk_inverted_chance(x) + return math.floor(x * chunk_square / 256 + 0.5) +end + +function mcl_structures.from_16x16_to_block_inverted_chance(x) + return math.floor(x * block_square / 256 + 0.5) +end + dofile(modpath .. "/structures.lua") diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua index 90afc6085..daedcb16f 100644 --- a/mods/MAPGEN/mcl_structures/jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -5,6 +5,8 @@ local chance_per_chunk = 9 local noise_multiplier = 1.3 local random_offset = 132 local struct_threshold = chance_per_chunk - 1 +local scanning_ratio = 0.0003 + local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level local node_list = {"mcl_core:dirt_with_grass", "mcl_core:dirt", "mcl_core:stone", "mcl_core:granite", "mcl_core:gravel", "mcl_core:diorite"} @@ -62,10 +64,18 @@ local function on_placed(p1, rotation, pr, size) end end - -- Find chests. - local chests = minetest.find_nodes_in_area(p1, {x = p2.x, y = p1.y + 5, z = p2.z}, "mcl_chests:trapped_chest_small") + -- Initialize some nodes + local chest_node = "mcl_chests:trapped_chest_small" + local lever_node = "mesecons_walllever:wall_lever_off" + local nodes = minetest.find_nodes_in_area(p1, {x = p2.x, y = p1.y + 5, z = p2.z}, {chest_node, lever_node}, true) - -- Add desert temple loot into chests + local levers = nodes[lever_node] + for _, pos in pairs(levers) do + mcl_structures.init_node_construct(pos) + end + + -- Add loot into chests TODO: fix items + local chests = nodes[chest_node] for c=1, #chests do local lootitems = mcl_loot.get_multi_loot({ { @@ -107,7 +117,6 @@ local function on_placed(p1, rotation, pr, size) local inv = meta:get_inventory() mcl_loot.fill_inventory(inv, "main", lootitems, pr) end - end local function place(pos, rotation, pr) @@ -152,7 +161,7 @@ mcl_structures.register_structure({ deco_type = "simple", place_on = node_list, flags = "all_floors", - fill_ratio = 0.0003, + fill_ratio = scanning_ratio, y_min = -13, y_max = mcl_mapgen.overworld.max, height = 1, diff --git a/mods/MAPGEN/mcl_structures/mod.conf b/mods/MAPGEN/mcl_structures/mod.conf index 4a04c65cd..1e34960a8 100644 --- a/mods/MAPGEN/mcl_structures/mod.conf +++ b/mods/MAPGEN/mcl_structures/mod.conf @@ -1,4 +1,4 @@ name = mcl_structures author = Wuzzy, kay27, cora description = Structures for MineClone 2/5 -depends = mcl_loot, mcl_mapgen +depends = mcl_loot, mcl_mapgen, mcl_worlds diff --git a/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua b/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua index 67fe97154..019224815 100644 --- a/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua @@ -5,6 +5,7 @@ local chance_per_chunk = 15 local noise_multiplier = 1 local random_offset = 133 local struct_threshold = chance_per_chunk - 1 +local scanning_ratio = 0.00021 local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level local node_list = {"mcl_core:dirt_with_grass", "mcl_core:dirt", "mcl_core:stone", "mcl_core:granite", "mcl_core:gravel", "mcl_core:diorite"} @@ -68,10 +69,18 @@ local function on_placed(p1, rotation, pr, size) end end - -- Find chests. - local chests = minetest.find_nodes_in_area(p1, {x = p2.x, y = p1.y + 5, z = p2.z}, "mcl_chests:trapped_chest_small") + -- Initialize some nodes + local chest_node = "mcl_chests:trapped_chest_small" + local lever_node = "mesecons_walllever:wall_lever_off" + local nodes = minetest.find_nodes_in_area(p1, {x = p2.x, y = p1.y + 5, z = p2.z}, {chest_node, lever_node}, true) - -- Add desert temple loot into chests + local levers = nodes[lever_node] + for _, pos in pairs(levers) do + mcl_structures.init_node_construct(pos) + end + + -- Add loot into chests TODO: fix items + local chests = nodes[chest_node] for c=1, #chests do local lootitems = mcl_loot.get_multi_loot({ { @@ -158,7 +167,7 @@ mcl_structures.register_structure({ deco_type = "simple", place_on = node_list, flags = "all_floors", - fill_ratio = 0.00021, + fill_ratio = scanning_ratio, y_min = -20, y_max = mcl_mapgen.overworld.max, height = 1, diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index 055b9d247..381dde72a 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -3,9 +3,10 @@ local modpath = minetest.get_modpath(modname) if not mcl_mapgen.singlenode then dofile(modpath .. "/desert_temple.lua") + dofile(modpath .. "/desert_well.lua") + dofile(modpath .. "/fossil.lua") dofile(modpath .. "/jungle_temple.lua") dofile(modpath .. "/nice_jungle_temple.lua") - dofile(modpath .. "/stronghold.lua") - dofile(modpath .. "/noise_indicator.lua") + dofile(modpath .. "/stronghold.lua") end From 34c6bf3446946695de5744948d5731fb6a1340e8 Mon Sep 17 00:00:00 2001 From: kay27 Date: Tue, 18 Jan 2022 21:41:09 +0400 Subject: [PATCH 52/61] Restore igloos --- mods/CORE/mcl_mapgen/init.lua | 1 + mods/MAPGEN/mcl_mapgen_core/structures.lua | 15 -- mods/MAPGEN/mcl_structures/igloo.lua | 196 +++++++++++++++++++++ mods/MAPGEN/mcl_structures/init.lua | 166 +---------------- mods/MAPGEN/mcl_structures/structures.lua | 1 + 5 files changed, 201 insertions(+), 178 deletions(-) create mode 100644 mods/MAPGEN/mcl_structures/igloo.lua diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 2d7e0eba7..e20583312 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -450,6 +450,7 @@ mcl_mapgen.dungeons = normal mcl_mapgen.overworld = overworld mcl_mapgen.end_ = end_ +mcl_mapgen["end"] = mcl_mapgen.end_ mcl_mapgen.nether = nether mcl_mapgen.order = order diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua index ed9752db8..da317d9d7 100644 --- a/mods/MAPGEN/mcl_mapgen_core/structures.lua +++ b/mods/MAPGEN/mcl_mapgen_core/structures.lua @@ -67,7 +67,6 @@ end --local chunk_has_desert_struct --local chunk_has_desert_temple ---local chunk_has_igloo local octaves = 3 local persistence = 0.6 @@ -81,18 +80,6 @@ end max_noise = max_noise * octaves max_noise = offset + scale * max_noise -local function spawn_igloo(p, nn, pr, vm_context) - if nn ~= "mcl_core:snowblock" and nn ~= "mcl_core:snow" and minetest_get_item_group(nn, "grass_block_snow") ~= 1 then return end - -- if pr:next(1, 4400) ~= 1 then return end - -- Check surface - local floor = {x=p.x+9, y=p.y-1, z=p.z+9} - local surface = minetest_find_nodes_in_area({x=p.x,y=p.y-1,z=p.z}, floor, {"mcl_core:snowblock", "mcl_core:dirt_with_grass_snow"}) - if #surface < 63 then return end - mcl_structures.call_struct(p, "igloo", nil, pr) - -- chunk_has_igloo = true - return true -end - local witch_hut_offsets = { ["0"] = { {x=1, y=0, z=1}, {x=1, y=0, z=5}, {x=6, y=0, z=1}, {x=6, y=0, z=5}, @@ -228,7 +215,6 @@ local function generate_structures(vm_context) local pr = PcgRandom(vm_context.chunkseed) -- chunk_has_desert_struct = false -- chunk_has_desert_temple = false - -- chunk_has_igloo = false local minp, maxp = vm_context.minp, vm_context.maxp perlin_structures = perlin_structures or minetest.get_perlin(329, 3, 0.6, 100) @@ -251,7 +237,6 @@ local function generate_structures(vm_context) if minetest.registered_nodes[nn0] and minetest.registered_nodes[nn0].buildable_to then --spawn_desert_temple(p, nn, pr, vm_context) --spawn_desert_well(p, nn, pr, vm_context) - --spawn_igloo(p, nn, pr, vm_context) --spawn_fossil(p, nn, pr, vm_context) --spawn_witch_hut(p, nn, pr, vm_context) if V6 then diff --git a/mods/MAPGEN/mcl_structures/igloo.lua b/mods/MAPGEN/mcl_structures/igloo.lua new file mode 100644 index 000000000..d0088a204 --- /dev/null +++ b/mods/MAPGEN/mcl_structures/igloo.lua @@ -0,0 +1,196 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +-- local chance_per_chunk = mcl_structures.from_16x16_to_chunk_inverted_chance(4400) +local chance_per_chunk = 1 +local noise_multiplier = 0 --1.3 +local random_offset = 132 +local struct_threshold = 0 --chance_per_chunk - 1 +local scanning_ratio = 0.0003 + +local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level + +local node_list = {"mcl_core:snowblock", "mcl_core:snow", "group:grass_block_snow"} + +local schematic_top = modpath.."/schematics/mcl_structures_igloo_top.mts" +local schematic_basement = modpath.."/schematics/mcl_structures_igloo_basement.mts" + +local brick = { + -- monster egg: + [false] = { + -- cracked: + [false] = "mcl_core:stonebrick", + [true ] = "mcl_core:stonebrickcracked", + }, + [true] = { + [false] = "mcl_monster_eggs:monster_egg_stonebrick", + [true ] = "mcl_monster_eggs:monster_egg_stonebrickcracked", + }, +} +local dirs = { + ["0"] = {x=-1, y=0, z= 0}, + ["90"] = {x= 0, y=0, z=-1}, + ["180"] = {x= 1, y=0, z= 0}, + ["270"] = {x= 0, y=0, z= 1}, +} +local tdirs = { + ["0"] = {x= 1, y=0, z= 0}, + ["90"] = {x= 0, y=0, z=-1}, + ["180"] = {x=-1, y=0, z= 0}, + ["270"] = {x= 0, y=0, z= 1} +} +local tposes = { + ["0"] = {x=7, y=-1, z=3}, + ["90"] = {x=3, y=-1, z=1}, + ["180"] = {x=1, y=-1, z=3}, + ["270"] = {x=3, y=-1, z=7}, +} +local chest_offsets = { + ["0"] = {x=5, y=1, z=5}, + ["90"] = {x=5, y=1, z=3}, + ["180"] = {x=3, y=1, z=1}, + ["270"] = {x=1, y=1, z=5}, +} + +local function on_placed(pos, rotation, pr, size) + local chest_offset = chest_offsets[rotation] + if not chest_offset then return end + local lootitems = mcl_loot.get_multi_loot({ + { + stacks_min = 1, + stacks_max = 1, + items = { + { itemstring = "mcl_core:apple_gold", weight = 1 }, + } + }, + { + stacks_min = 2, + stacks_max = 8, + items = { + { itemstring = "mcl_core:coal_lump", weight = 15, amount_min = 1, amount_max = 4 }, + { itemstring = "mcl_core:apple", weight = 15, amount_min = 1, amount_max = 3 }, + { itemstring = "mcl_farming:wheat_item", weight = 10, amount_min = 2, amount_max = 3 }, + { itemstring = "mcl_core:gold_nugget", weight = 10, amount_min = 1, amount_max = 3 }, + { itemstring = "mcl_mobitems:rotten_flesh", weight = 10 }, + { itemstring = "mcl_tools:axe_stone", weight = 2 }, + { itemstring = "mcl_core:emerald", weight = 1 }, + } + }}, pr) + + local chest_pos = vector.add(pos, chest_offset) + mcl_structures.init_node_construct(chest_pos) + local meta = minetest.get_meta(chest_pos) + local inv = meta:get_inventory() + mcl_loot.fill_inventory(inv, "main", lootitems, pr) +end + +local function on_placed_top(p1, rotation, pr, size) + local y = p1.y + 1 + local pos = {x = p1.x, y = y, z = p1.z} + local dim = mcl_mapgen[mcl_worlds.pos_to_dimension(pos)] + local bottom_of_dimension = (dim and dim.min or mcl_mapgen.EDGE_MIN) + 10 + local bottom_of_chunk = mcl_mapgen.get_chunk_beginning(y) + local buffer = y - math.max(bottom_of_chunk, bottom_of_dimension) + if buffer < 20 then return end + + local depth = pr:next(19, buffer) + local bpos = {x=pos.x, y=pos.y-depth, z=pos.z} + local dir = dirs[rotation] + if not dir then return end + local tdir = tdirs[rotation] + + -- Trapdoor position + local tpos = vector.add(pos, tposes[rotation]) + local ladder_param2 = minetest.dir_to_wallmounted(tdir) + + -- Check how deep we can actuall dig + local real_depth = 0 + for y = 1, depth - 5 do + local node = minetest.get_node({x=tpos.x,y=tpos.y-y,z=tpos.z}) + local def = minetest.registered_nodes[node.name] + if (not def) or (not def.walkable) or (def.liquidtype ~= "none") then + bpos.y = tpos.y-y+1 + break + end + real_depth = real_depth + 1 + end + if real_depth < 6 then return end + + -- Generate ladder to basement + for y=1, real_depth-1 do + minetest.set_node({x=tpos.x-1,y=tpos.y-y,z=tpos.z }, {name = brick[pr:next(1, 10) == 1][pr:next(1, 3) == 1]}) + minetest.set_node({x=tpos.x+1,y=tpos.y-y,z=tpos.z }, {name = brick[pr:next(1, 10) == 1][pr:next(1, 3) == 1]}) + minetest.set_node({x=tpos.x ,y=tpos.y-y,z=tpos.z-1}, {name = brick[pr:next(1, 10) == 1][pr:next(1, 3) == 1]}) + minetest.set_node({x=tpos.x ,y=tpos.y-y,z=tpos.z+1}, {name = brick[pr:next(1, 10) == 1][pr:next(1, 3) == 1]}) + minetest.set_node({x=tpos.x ,y=tpos.y-y,z=tpos.z }, {name="mcl_core:ladder", param2=ladder_param2}) + end + + -- Place basement + local def = { + pos = bpos, + schematic = schematic_basement, + rotation = rotation, + pr = pr, + on_placed = on_placed, + } + mcl_structures.place_schematic(def) + + minetest.after(5, function(tpos, dir) + minetest.swap_node(tpos, {name="mcl_doors:trapdoor", param2=20+minetest.dir_to_facedir(dir)}) -- TODO: more reliable param2 + end, tpos, dir) +end + +local function place(pos, rotation, pr) + local def = { + pos = {x = pos.x, y = pos.y - 1, z = pos.z}, + schematic = schematic_top, + rotation = rotation or tostring(pr:next(0,3)*90), + pr = pr, + on_placed = on_placed_top, + } + -- FIXME: This spawns bookshelf instead of furnace. Fix this! + -- Furnace does not work atm because apparently meta is not set. :-( + mcl_structures.place_schematic(def) +end + +local function get_place_rank(pos) + local x, y, z = pos.x, pos.y, pos.z + local p1 = {x = x , y = y, z = z } + local p2 = {x = x + 9, y = y, z = z + 9} + local best_pos_list_surface = #minetest.find_nodes_in_area(p1, p2, node_list, false) + local other_pos_list_surface = #minetest.find_nodes_in_area(p1, p2, "group:opaque", false) + return 10 * (best_pos_list_surface) + other_pos_list_surface - 640 +end + +mcl_structures.register_structure({ + name = "igloo", + decoration = { + deco_type = "simple", + place_on = node_list, + flags = "all_floors", + fill_ratio = scanning_ratio, + y_min = -33, + y_max = mcl_mapgen.overworld.max, + height = 1, + }, + on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) + local pr = PseudoRandom(seed + random_offset) + local random_number = pr:next(1, chance_per_chunk) + local noise = mcl_structures_get_perlin_noise_level(minp) * noise_multiplier + if (random_number + noise) < struct_threshold then return end + local pos + local count = -1 + for i = 1, #pos_list do + local pos_i = vector.subtract(pos_list[i], {x = 4, y = 1, z = 4}) + local count_i = get_place_rank(pos_i) + if count_i > count then + count = count_i + pos = pos_i + end + end + if count < 0 then return end + local pr = PseudoRandom(vm_context.chunkseed) + place(pos, nil, pr) + end, + place_function = place, +}) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index c8de04a64..296b6815c 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -337,9 +337,7 @@ function mcl_structures.call_struct(pos, struct_style, rotation, pr, callback) if not rotation then rotation = "random" end - if struct_style == "igloo" then - return mcl_structures.generate_igloo(pos, rotation, pr) - elseif struct_style == "witch_hut" then + if struct_style == "witch_hut" then return mcl_structures.generate_witch_hut(pos, rotation) elseif struct_style == "ice_spike_small" then return mcl_structures.generate_ice_spike_small(pos, rotation) @@ -376,164 +374,6 @@ function mcl_structures.generate_end_portal(pos, rotation, pr) end end -function mcl_structures.generate_igloo(pos, rotation, pr) - -- Place igloo - local success, rotation = mcl_structures.generate_igloo_top(pos, pr) - -- Place igloo basement with 50% chance - local r = pr:next(1,2) - if r == 1 then - -- Select basement depth - local dim = mcl_worlds.pos_to_dimension(pos) - --local buffer = pos.y - (mcl_mapgen.overworld.lava_max + 10) - local buffer - if dim == "nether" then - buffer = pos.y - (mcl_vars.mg_lava_nether_max + 10) - elseif dim == "end" then - buffer = pos.y - (mcl_vars.mg_end_min + 1) - elseif dim == "overworld" then - buffer = pos.y - (mcl_mapgen.overworld.lava_max + 10) - else - return success - end - if buffer <= 19 then - return success - end - local depth = pr:next(19, buffer) - local bpos = {x=pos.x, y=pos.y-depth, z=pos.z} - -- trapdoor position - local tpos - local dir, tdir - if rotation == "0" then - dir = {x=-1, y=0, z=0} - tdir = {x=1, y=0, z=0} - tpos = {x=pos.x+7, y=pos.y-1, z=pos.z+3} - elseif rotation == "90" then - dir = {x=0, y=0, z=-1} - tdir = {x=0, y=0, z=-1} - tpos = {x=pos.x+3, y=pos.y-1, z=pos.z+1} - elseif rotation == "180" then - dir = {x=1, y=0, z=0} - tdir = {x=-1, y=0, z=0} - tpos = {x=pos.x+1, y=pos.y-1, z=pos.z+3} - elseif rotation == "270" then - dir = {x=0, y=0, z=1} - tdir = {x=0, y=0, z=1} - tpos = {x=pos.x+3, y=pos.y-1, z=pos.z+7} - else - return success - end - local function set_brick(pos) - local c = pr:next(1, 3) -- cracked chance - local m = pr:next(1, 10) -- chance for monster egg - local brick - if m == 1 then - if c == 1 then - brick = "mcl_monster_eggs:monster_egg_stonebrickcracked" - else - brick = "mcl_monster_eggs:monster_egg_stonebrick" - end - else - if c == 1 then - brick = "mcl_core:stonebrickcracked" - else - brick = "mcl_core:stonebrick" - end - end - minetest.set_node(pos, {name=brick}) - end - local ladder_param2 = minetest.dir_to_wallmounted(tdir) - local real_depth = 0 - -- Check how deep we can actuall dig - for y=1, depth-5 do - real_depth = real_depth + 1 - local node = minetest.get_node({x=tpos.x,y=tpos.y-y,z=tpos.z}) - local def = minetest.registered_nodes[node.name] - if (not def) or (not def.walkable) or (def.liquidtype ~= "none") or (not def.is_ground_content) then - bpos.y = tpos.y-y+1 - break - end - end - if real_depth <= 6 then - return success - end - -- Generate ladder to basement - for y=1, real_depth-1 do - set_brick({x=tpos.x-1,y=tpos.y-y,z=tpos.z }) - set_brick({x=tpos.x+1,y=tpos.y-y,z=tpos.z }) - set_brick({x=tpos.x ,y=tpos.y-y,z=tpos.z-1}) - set_brick({x=tpos.x ,y=tpos.y-y,z=tpos.z+1}) - minetest.set_node({x=tpos.x,y=tpos.y-y,z=tpos.z}, {name="mcl_core:ladder", param2=ladder_param2}) - end - -- Place basement - mcl_structures.generate_igloo_basement(bpos, rotation, pr) - -- Place hidden trapdoor - minetest.after(5, function(tpos, dir) - minetest.set_node(tpos, {name="mcl_doors:trapdoor", param2=20+minetest.dir_to_facedir(dir)}) -- TODO: more reliable param2 - end, tpos, dir) - end - return success -end - -function mcl_structures.generate_igloo_top(pos, pr) - -- FIXME: This spawns bookshelf instead of furnace. Fix this! - -- Furnace does not work atm because apparently meta is not set. :-( - local newpos = {x=pos.x,y=pos.y-1,z=pos.z} - local path = modpath.."/schematics/mcl_structures_igloo_top.mts" - local rotation = tostring(pr:next(0,3)*90) - return mcl_structures.place_schematic(newpos, path, rotation, nil, true), rotation -end - -local function igloo_placement_callback(p1, p2, size, orientation, pr) - local chest_offset - if orientation == "0" then - chest_offset = {x=5, y=1, z=5} - elseif orientation == "90" then - chest_offset = {x=5, y=1, z=3} - elseif orientation == "180" then - chest_offset = {x=3, y=1, z=1} - elseif orientation == "270" then - chest_offset = {x=1, y=1, z=5} - else - return - end - --local size = {x=9,y=5,z=7} - local lootitems = mcl_loot.get_multi_loot({ - { - stacks_min = 1, - stacks_max = 1, - items = { - { itemstring = "mcl_core:apple_gold", weight = 1 }, - } - }, - { - stacks_min = 2, - stacks_max = 8, - items = { - { itemstring = "mcl_core:coal_lump", weight = 15, amount_min = 1, amount_max = 4 }, - { itemstring = "mcl_core:apple", weight = 15, amount_min = 1, amount_max = 3 }, - { itemstring = "mcl_farming:wheat_item", weight = 10, amount_min = 2, amount_max = 3 }, - { itemstring = "mcl_core:gold_nugget", weight = 10, amount_min = 1, amount_max = 3 }, - { itemstring = "mcl_mobitems:rotten_flesh", weight = 10 }, - { itemstring = "mcl_tools:axe_stone", weight = 2 }, - { itemstring = "mcl_core:emerald", weight = 1 }, - } - }}, pr) - - local chest_pos = vector.add(p1, chest_offset) - mcl_structures.init_node_construct(chest_pos) - local meta = minetest.get_meta(chest_pos) - local inv = meta:get_inventory() - mcl_loot.fill_inventory(inv, "main", lootitems, pr) -end - -function mcl_structures.generate_igloo_basement(pos, orientation, pr) - -- TODO: Add brewing stand - -- TODO: Add monster eggs - -- TODO: Spawn villager and zombie villager - local path = modpath.."/schematics/mcl_structures_igloo_basement.mts" - mcl_structures.place_schematic(pos, path, orientation, nil, true, nil, igloo_placement_callback, pr) -end - function mcl_structures.generate_boulder(pos, rotation, pr) -- Choose between 2 boulder sizes (2×2×2 or 3×3×3) local r = pr:next(1, 10) @@ -594,11 +434,11 @@ local chunk_square = mcl_mapgen.CS_NODES * mcl_mapgen.CS_NODES local block_square = mcl_mapgen.BS * mcl_mapgen.BS function mcl_structures.from_16x16_to_chunk_inverted_chance(x) - return math.floor(x * chunk_square / 256 + 0.5) + return math.floor(x * 256 / chunk_square + 0.5) end function mcl_structures.from_16x16_to_block_inverted_chance(x) - return math.floor(x * block_square / 256 + 0.5) + return math.floor(x * 256 / block_square + 0.5) end dofile(modpath .. "/structures.lua") diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index 381dde72a..a3fca2d32 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -5,6 +5,7 @@ if not mcl_mapgen.singlenode then dofile(modpath .. "/desert_temple.lua") dofile(modpath .. "/desert_well.lua") dofile(modpath .. "/fossil.lua") + dofile(modpath .. "/igloo.lua") dofile(modpath .. "/jungle_temple.lua") dofile(modpath .. "/nice_jungle_temple.lua") dofile(modpath .. "/noise_indicator.lua") From 75a7f5a3ae153db222ea073ef39c89bafe8960ee Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 19 Jan 2022 01:49:28 +0400 Subject: [PATCH 53/61] Restore Witch Hut --- mods/MAPGEN/mcl_mapgen_core/structures.lua | 93 --------------- mods/MAPGEN/mcl_structures/igloo.lua | 8 +- mods/MAPGEN/mcl_structures/structures.lua | 1 + mods/MAPGEN/mcl_structures/witch_hut.lua | 132 +++++++++++++++++++++ 4 files changed, 137 insertions(+), 97 deletions(-) create mode 100644 mods/MAPGEN/mcl_structures/witch_hut.lua diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua index da317d9d7..c4ab09d97 100644 --- a/mods/MAPGEN/mcl_mapgen_core/structures.lua +++ b/mods/MAPGEN/mcl_mapgen_core/structures.lua @@ -1,6 +1,4 @@ - local END_EXIT_PORTAL_POS = vector.new(-3, -27003, -3) -- End exit portal position -local WITCH_HUT_HEIGHT = 3 -- Exact Y level to spawn witch huts at. This height refers to the height of the floor local OVERWORLD_STRUCT_MIN, OVERWORLD_STRUCT_MAX = mcl_mapgen.overworld.min, mcl_mapgen.overworld.max local END_STRUCT_MIN, END_STRUCT_MAX = mcl_mapgen.end_.min, mcl_mapgen.end_.max local DIVLEN = 5 @@ -80,93 +78,6 @@ end max_noise = max_noise * octaves max_noise = offset + scale * max_noise -local witch_hut_offsets = { - ["0"] = { - {x=1, y=0, z=1}, {x=1, y=0, z=5}, {x=6, y=0, z=1}, {x=6, y=0, z=5}, - }, - ["180"] = { - {x=2, y=0, z=1}, {x=2, y=0, z=5}, {x=7, y=0, z=1}, {x=7, y=0, z=5}, - }, - ["270"] = { - {x=1, y=0, z=1}, {x=5, y=0, z=1}, {x=1, y=0, z=6}, {x=5, y=0, z=6}, - }, - ["90"] = { - {x=1, y=0, z=2}, {x=5, y=0, z=2}, {x=1, y=0, z=7}, {x=5, y=0, z=7}, - }, -} - -local function spawn_witch_hut(p, nn, pr, vm_context) - minetest.log("warning", "p="..minetest.pos_to_string(p)..", nn="..nn) - -- if p.y > 1 or minetest_get_item_group(nn, "dirt") == 0 then return end - local minp, maxp = vm_context.minp, vm_context.maxp - local prob = minecraft_chunk_probability(48, minp, maxp) - minetest.log("warning", "prob="..tostring(prob)) - -- if pr:next(1, prob) ~= 1 then return end - - -- Where do witches live? - if V6 then - -- v6: In Normal biome - if biomeinfo.get_v6_biome(p) ~= "Normal" then return end - else - -- Other mapgens: In swampland biome - local biomemap = vm_context.biomemap - if not biomemap then - vm_context.biomemap = minetest_get_mapgen_object('biomemap') - biomemap = vm_context.biomemap - end - local swampland = minetest.get_biome_id("Swampland") - local swampland_shore = minetest.get_biome_id("Swampland_shore") - local bi = xz_to_biomemap_index(p.x, p.z, vm_context.minp, vm_context.maxp) - -- if biomemap[bi] ~= swampland and biomemap[bi] ~= swampland_shore then return end - end - - local r = tostring(pr:next(0, 3) * 90) -- "0", "90", "180" or 270" - local p1 = {x=p.x-1, y=WITCH_HUT_HEIGHT+2, z=p.z-1} - local size - if r == "0" or r == "180" then - size = {x=10, y=4, z=8} - else - size = {x=8, y=4, z=10} - end - local p2 = vector.add(p1, size) - - -- This checks free space at the “body” of the hut and a bit around. - -- ALL nodes must be free for the placement to succeed. - local free_nodes = minetest_find_nodes_in_area(p1, p2, {"air", "mcl_core:water_source", "mcl_flowers:waterlily"}) - if #free_nodes < ((size.x+1)*(size.y+1)*(size.z+1)) then return end - - local place = {x=p.x, y=WITCH_HUT_HEIGHT-1, z=p.z} - - -- FIXME: For some mysterious reason (black magic?) this - -- function does sometimes NOT spawn the witch hut. One can only see the - -- oak wood nodes in the water, but no hut. :-/ - mcl_structures.call_struct(place, "witch_hut", r, pr) - - -- TODO: Spawn witch in or around hut when the mob sucks less. - - local function place_tree_if_free(pos, prev_result) - local nn = minetest.get_node(pos).name - if nn == "mcl_flowers:waterlily" or nn == "mcl_core:water_source" or nn == "mcl_core:water_flowing" or nn == "air" then - minetest.set_node(pos, {name="mcl_core:tree", param2=0}) - return prev_result - else - return false - end - end - - local offsets = witch_hut_offsets[r] - for o=1, #offsets do - local ok = true - for y=place.y-1, place.y-64, -1 do - local tpos = vector.add(place, offsets[o]) - tpos.y = y - ok = place_tree_if_free(tpos, ok) - if not ok then - break - end - end - end -end -- TODO: Check spikes sizes, it looks like we have to swap them: @@ -235,10 +146,6 @@ local function generate_structures(vm_context) local nn0 = minetest.get_node(p).name -- Check if the node can be replaced if minetest.registered_nodes[nn0] and minetest.registered_nodes[nn0].buildable_to then - --spawn_desert_temple(p, nn, pr, vm_context) - --spawn_desert_well(p, nn, pr, vm_context) - --spawn_fossil(p, nn, pr, vm_context) - --spawn_witch_hut(p, nn, pr, vm_context) if V6 then spawn_spikes_in_v6(p, nn, pr, vm_context) end diff --git a/mods/MAPGEN/mcl_structures/igloo.lua b/mods/MAPGEN/mcl_structures/igloo.lua index d0088a204..9f2b26672 100644 --- a/mods/MAPGEN/mcl_structures/igloo.lua +++ b/mods/MAPGEN/mcl_structures/igloo.lua @@ -2,10 +2,10 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) -- local chance_per_chunk = mcl_structures.from_16x16_to_chunk_inverted_chance(4400) -local chance_per_chunk = 1 -local noise_multiplier = 0 --1.3 -local random_offset = 132 -local struct_threshold = 0 --chance_per_chunk - 1 +local chance_per_chunk = 100 +local noise_multiplier = 1.4 +local random_offset = 555 +local struct_threshold = chance_per_chunk - 1 local scanning_ratio = 0.0003 local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index a3fca2d32..2bccd3923 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -10,4 +10,5 @@ if not mcl_mapgen.singlenode then dofile(modpath .. "/nice_jungle_temple.lua") dofile(modpath .. "/noise_indicator.lua") dofile(modpath .. "/stronghold.lua") + dofile(modpath .. "/witch_hut.lua") end diff --git a/mods/MAPGEN/mcl_structures/witch_hut.lua b/mods/MAPGEN/mcl_structures/witch_hut.lua new file mode 100644 index 000000000..f823387f8 --- /dev/null +++ b/mods/MAPGEN/mcl_structures/witch_hut.lua @@ -0,0 +1,132 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +local chance_per_chunk = 3 +local noise_multiplier = -0.9 +local random_offset = 8 +local scanning_ratio = 0.0001 +local struct_threshold = chance_per_chunk - 1 + +local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level + +local schematic_file = modpath .. "/schematics/mcl_structures_witch_hut.mts" + +local witch_hut_schematic_lua = minetest.serialize_schematic(schematic_file, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic" +local witch_hut_schematic = loadstring(witch_hut_schematic_lua)() + +local node_list = {"mcl_core:dirt_with_grass", "mcl_core:dirt"} + +local WITCH_HUT_HEIGHT = 2 -- Exact Y level to spawn witch huts at. This height refers to the height of the floor + +local witch_hut_offsets = { + ["0"] = { + {x=1, y=0, z=1}, {x=1, y=0, z=5}, {x=6, y=0, z=1}, {x=6, y=0, z=5}, + }, + ["180"] = { + {x=2, y=0, z=1}, {x=2, y=0, z=5}, {x=7, y=0, z=1}, {x=7, y=0, z=5}, + }, + ["270"] = { + {x=1, y=0, z=1}, {x=5, y=0, z=1}, {x=1, y=0, z=6}, {x=5, y=0, z=6}, + }, + ["90"] = { + {x=1, y=0, z=2}, {x=5, y=0, z=2}, {x=1, y=0, z=7}, {x=5, y=0, z=7}, + }, +} + +local function on_placed(place, rotation, pr, size) + local offsets = witch_hut_offsets[rotation] + if not offsets then return end + for _, offset in pairs(offsets) do + local tpos = vector.add(place, offset) + for y = place.y - 1, mcl_mapgen.get_chunk_beginning(place.y - 1), -1 do + tpos.y = y + local nn = minetest.get_node(tpos).name + if not nn then break end + local node = minetest.registered_nodes[nn] + local groups = node.groups + if nn == "mcl_flowers:waterlily" or nn == "mcl_core:water_source" or nn == "mcl_core:water_flowing" or nn == "air" or groups.deco_block then + minetest.swap_node(tpos, {name="mcl_core:tree"}) + else + break + end + end + end +end + + +local function place(pos, rotation, pr) + mcl_structures.place_schematic({pos = pos, rotaton = rotation, schematic = witch_hut_schematic, pr = pr, on_placed = on_placed}) +end + +local function get_place_rank(pos) + local x, y, z = pos.x, pos.y, pos.z + local p1 = {x = x + 1, y = y + 1, z = z + 1} + local p2 = {x = x + 4, y = y + 4, z = z + 4} + local counter = #minetest.find_nodes_in_area(p1, p2, {"air", "group:buildable_to", "group:deco_block"}, false) + return counter +end + +local function tune_pos(pos) + local y = pos.y - 1 + if y >= WITCH_HUT_HEIGHT - 5 and y <= WITCH_HUT_HEIGHT + 5 then + pos.y = WITCH_HUT_HEIGHT + return pos + end + local water_list = minetest.find_nodes_in_area(p1, p2, {"group:water"}, false) + if not water_list or #water_list < 1 then + pos.y = pos.y - 1 + return pos + end + local top = -1 + for _, pos in pairs(water_list) do + if pos.y > top then + top = pos.y + end + end + pos.y = top - 1 + return pos +end + +mcl_structures.register_structure({ + name = "witch_hut", + decoration = { + deco_type = "simple", + place_on = node_list, + spawn_by = {"mcl_core:water_source", "group:frosted_ice"}, + num_spawn_by = 1, + flags = "all_floors", + fill_ratio = scanning_ratio, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, + height = 1, + biomes = mcl_mapgen.v6 and { + "Normal", + } or { + "Swampland", + "Swampland_shore", + "Swampland_ocean", + "Swampland_deep_ocean", + }, + }, + on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) + local pr = PseudoRandom(seed + random_offset) + local random_number = pr:next(1, chance_per_chunk) + local noise = mcl_structures_get_perlin_noise_level(minp) * noise_multiplier + if (random_number + noise) < struct_threshold then return end + local pos = tune_pos(pos_list[1]) + if #pos_list > 1 then + local count = get_place_rank(pos) + for i = 2, #pos_list do + local pos_i = pos_list[i] + local count_i = get_place_rank(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, + place_function = place, +}) From 6ac682fdcf134dca804d94e217e7bb4b03da2dac Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 19 Jan 2022 02:25:23 +0400 Subject: [PATCH 54/61] Fix huts --- mods/MAPGEN/mcl_structures/init.lua | 2 +- mods/MAPGEN/mcl_structures/witch_hut.lua | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 296b6815c..27c38df0a 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -159,7 +159,7 @@ function mcl_structures.register_structure(def) local decoration_id if decoration then minetest.register_node(':' .. name, { - drawtype = "airlike", + -- drawtype = "airlike", sunlight_propagates = true, pointable = false, walkable = false, diff --git a/mods/MAPGEN/mcl_structures/witch_hut.lua b/mods/MAPGEN/mcl_structures/witch_hut.lua index f823387f8..e4287e652 100644 --- a/mods/MAPGEN/mcl_structures/witch_hut.lua +++ b/mods/MAPGEN/mcl_structures/witch_hut.lua @@ -4,7 +4,7 @@ local modpath = minetest.get_modpath(modname) local chance_per_chunk = 3 local noise_multiplier = -0.9 local random_offset = 8 -local scanning_ratio = 0.0001 +local scanning_ratio = 0.01 local struct_threshold = chance_per_chunk - 1 local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level @@ -67,14 +67,19 @@ local function get_place_rank(pos) end local function tune_pos(pos) + local pos = table.copy(pos) local y = pos.y - 1 if y >= WITCH_HUT_HEIGHT - 5 and y <= WITCH_HUT_HEIGHT + 5 then pos.y = WITCH_HUT_HEIGHT return pos end + local x = pos.x + local z = pos.z + local p1 = {x = x - 3, y = y , z = z - 3} + local p2 = {x = x + 3, y = y + 2, z = z + 3} local water_list = minetest.find_nodes_in_area(p1, p2, {"group:water"}, false) if not water_list or #water_list < 1 then - pos.y = pos.y - 1 + pos.y = y return pos end local top = -1 @@ -83,7 +88,7 @@ local function tune_pos(pos) top = pos.y end end - pos.y = top - 1 + pos.y = top return pos end @@ -94,7 +99,7 @@ mcl_structures.register_structure({ place_on = node_list, spawn_by = {"mcl_core:water_source", "group:frosted_ice"}, num_spawn_by = 1, - flags = "all_floors", + -- flags = "all_floors", fill_ratio = scanning_ratio, y_min = mcl_mapgen.overworld.min, y_max = mcl_mapgen.overworld.max, From 4a3f1032cacf9476c643e2f6e6acf380600578c4 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 19 Jan 2022 03:41:22 +0400 Subject: [PATCH 55/61] Add ice spikes for v6 --- mods/MAPGEN/mcl_structures/desert_temple.lua | 1 - mods/MAPGEN/mcl_structures/desert_well.lua | 1 - .../MAPGEN/mcl_structures/ice_spike_large.lua | 66 +++++++++++++++++++ .../MAPGEN/mcl_structures/ice_spike_small.lua | 65 ++++++++++++++++++ mods/MAPGEN/mcl_structures/igloo.lua | 1 - mods/MAPGEN/mcl_structures/init.lua | 9 --- mods/MAPGEN/mcl_structures/jungle_temple.lua | 1 - .../mcl_structures/nice_jungle_temple.lua | 1 - mods/MAPGEN/mcl_structures/structures.lua | 2 + mods/MAPGEN/mcl_structures/witch_hut.lua | 1 - 10 files changed, 133 insertions(+), 15 deletions(-) create mode 100644 mods/MAPGEN/mcl_structures/ice_spike_large.lua create mode 100644 mods/MAPGEN/mcl_structures/ice_spike_small.lua diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua index 53b86acbc..bb4c08b3a 100644 --- a/mods/MAPGEN/mcl_structures/desert_temple.lua +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -168,7 +168,6 @@ mcl_structures.register_structure({ end end end - local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, place_function = place, diff --git a/mods/MAPGEN/mcl_structures/desert_well.lua b/mods/MAPGEN/mcl_structures/desert_well.lua index 93769f458..af57c8183 100644 --- a/mods/MAPGEN/mcl_structures/desert_well.lua +++ b/mods/MAPGEN/mcl_structures/desert_well.lua @@ -87,7 +87,6 @@ mcl_structures.register_structure({ end end end - local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, place_function = place, diff --git a/mods/MAPGEN/mcl_structures/ice_spike_large.lua b/mods/MAPGEN/mcl_structures/ice_spike_large.lua new file mode 100644 index 000000000..b46f09465 --- /dev/null +++ b/mods/MAPGEN/mcl_structures/ice_spike_large.lua @@ -0,0 +1,66 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +local chance_per_chunk = 5 +local random_offset = 24435 +local struct_threshold = chance_per_chunk - 1 +local noise_params = { + offset = 0, + scale = 1, + spread = { + x = 1000, + y = 1000, + z = 1000, + }, + scale = 0.01, + seed = 29313, + octaves = 2, + persistence = 0.7, +} + +local node_list = {"mcl_core:snowblock", "mcl_core:dirt_with_grass_snow"} +local schematic = modpath.."/schematics/mcl_structures_ice_spike_large.mts" + +minetest_find_nodes_in_area = minetest.find_nodes_in_area + +local function place(pos, rotation, pr) + mcl_structures.place_schematic({pos = pos, schematic = schematic, rotation = rotation, pr = pr}) +end + +local function is_place_ok(p) + -- Check surface + local floor = {x=p.x+4, y=p.y-1, z=p.z+4} + local surface = #minetest_find_nodes_in_area({x=p.x+1,y=p.y-1,z=p.z+1}, floor, node_list, false) + if surface < 9 then return end + + -- Check for collision with spruce + local spruce_collisions = #minetest_find_nodes_in_area({x=p.x+1,y=p.y+2,z=p.z+1}, {x=p.x+4, y=p.y+6, z=p.z+4}, {"group:tree"}, false) + if spruce_collisions > 0 then return end + + return true +end + +local def = mcl_mapgen.v6 and { + decoration = { + deco_type = "simple", + place_on = node_list, + noise_params = noise_params, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, + height = 1, + }, + on_finished_chunk = mcl_mapgen.v6 and function(minp, maxp, seed, vm_context, pos_list) + local pr = PseudoRandom(seed + random_offset) + local random_number = pr:next(1, chance_per_chunk) + if random_number < struct_threshold then return end + for i = 1, #pos_list do + local pos = pos_list[i] + if is_place_ok(pos) then + place(pos, nil, pr) + end + end + end, +} or {} +def.name = "ice_spike_large" +def.place_function = place +mcl_structures.register_structure(def) diff --git a/mods/MAPGEN/mcl_structures/ice_spike_small.lua b/mods/MAPGEN/mcl_structures/ice_spike_small.lua new file mode 100644 index 000000000..801c5f66e --- /dev/null +++ b/mods/MAPGEN/mcl_structures/ice_spike_small.lua @@ -0,0 +1,65 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +local chance_per_chunk = 3 +local random_offset = 1264 +local struct_threshold = chance_per_chunk - 1 +local noise_params = { + offset = 0, + scale = 1, + spread = { + x = mcl_mapgen.CS, + y = mcl_mapgen.CS, + z = mcl_mapgen.CS, + }, + scale = 0.3, + seed = 32931, + octaves = 2, + persistence = 0.7, +} + +local node_list = {"mcl_core:snowblock", "mcl_core:dirt_with_grass_snow"} +local schematic = modpath.."/schematics/mcl_structures_ice_spike_small.mts" + +minetest_find_nodes_in_area = minetest.find_nodes_in_area + +local function place(pos, rotation, pr) + mcl_structures.place_schematic({pos = pos, schematic = schematic, rotation = rotation, pr = pr}) +end + +local function is_place_ok(p) + local floor = {x=p.x+6, y=p.y-1, z=p.z+6} + local surface = #minetest_find_nodes_in_area({x=p.x+1,y=p.y-1,z=p.z+1}, floor, node_list, false) + if surface < 25 then return end + + -- Check for collision with spruce + local spruce_collisions = #minetest_find_nodes_in_area({x=p.x+1,y=p.y+1,z=p.z+1}, {x=p.x+6, y=p.y+6, z=p.z+6}, {"group:tree"}, false) + if spruce_collisions > 0 then return end + + return true +end + +local def = mcl_mapgen.v6 and { + decoration = { + deco_type = "simple", + place_on = node_list, + noise_params = noise_params, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, + height = 1, + }, + on_finished_chunk = mcl_mapgen.v6 and function(minp, maxp, seed, vm_context, pos_list) + local pr = PseudoRandom(seed + random_offset) + local random_number = pr:next(1, chance_per_chunk) + if random_number < struct_threshold then return end + for i = 1, #pos_list do + local pos = pos_list[i] + if is_place_ok(pos) then + place(pos, nil, pr) + end + end + end, +} or {} +def.name = "ice_spike_small" +def.place_function = place +mcl_structures.register_structure(def) diff --git a/mods/MAPGEN/mcl_structures/igloo.lua b/mods/MAPGEN/mcl_structures/igloo.lua index 9f2b26672..4f6c9574f 100644 --- a/mods/MAPGEN/mcl_structures/igloo.lua +++ b/mods/MAPGEN/mcl_structures/igloo.lua @@ -189,7 +189,6 @@ mcl_structures.register_structure({ end end if count < 0 then return end - local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, place_function = place, diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 27c38df0a..c43640fd1 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -339,10 +339,6 @@ function mcl_structures.call_struct(pos, struct_style, rotation, pr, callback) end if struct_style == "witch_hut" then return mcl_structures.generate_witch_hut(pos, rotation) - elseif struct_style == "ice_spike_small" then - return mcl_structures.generate_ice_spike_small(pos, rotation) - elseif struct_style == "ice_spike_large" then - return mcl_structures.generate_ice_spike_large(pos, rotation) elseif struct_style == "boulder" then return mcl_structures.generate_boulder(pos, rotation, pr) elseif struct_style == "end_exit_portal" then @@ -405,11 +401,6 @@ function mcl_structures.generate_witch_hut(pos, rotation, pr) mcl_structures.place_schematic(pos, path, rotation, nil, true, nil, hut_placement_callback, pr) end -function mcl_structures.generate_ice_spike_small(pos, rotation) - local path = modpath.."/schematics/mcl_structures_ice_spike_small.mts" - return minetest.place_schematic(pos, path, rotation or "random", nil, false) -- don't serialize schematics for registered biome decorations, for MT 5.4.0 -end - function mcl_structures.generate_ice_spike_large(pos, rotation) local path = modpath.."/schematics/mcl_structures_ice_spike_large.mts" return minetest.place_schematic(pos, path, rotation or "random", nil, false) -- don't serialize schematics for registered biome decorations, for MT 5.4.0 diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua index daedcb16f..635f35670 100644 --- a/mods/MAPGEN/mcl_structures/jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -197,7 +197,6 @@ mcl_structures.register_structure({ end end if count < 0 then return end - local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, place_function = place, diff --git a/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua b/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua index 019224815..dd8df05d3 100644 --- a/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua @@ -203,7 +203,6 @@ mcl_structures.register_structure({ end end if count < 0 then return end - local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, place_function = place, diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index 2bccd3923..94fad4230 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -6,6 +6,8 @@ if not mcl_mapgen.singlenode then dofile(modpath .. "/desert_well.lua") dofile(modpath .. "/fossil.lua") dofile(modpath .. "/igloo.lua") + dofile(modpath .. "/ice_spike_small.lua") + dofile(modpath .. "/ice_spike_large.lua") dofile(modpath .. "/jungle_temple.lua") dofile(modpath .. "/nice_jungle_temple.lua") dofile(modpath .. "/noise_indicator.lua") diff --git a/mods/MAPGEN/mcl_structures/witch_hut.lua b/mods/MAPGEN/mcl_structures/witch_hut.lua index e4287e652..f6dc6ec9b 100644 --- a/mods/MAPGEN/mcl_structures/witch_hut.lua +++ b/mods/MAPGEN/mcl_structures/witch_hut.lua @@ -130,7 +130,6 @@ mcl_structures.register_structure({ end end end - local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, place_function = place, From bc4cb14a7623ef663afeb55af59470997a7e7a32 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 19 Jan 2022 03:59:22 +0400 Subject: [PATCH 56/61] Clean up the code --- mods/MAPGEN/mcl_mapgen_core/init.lua | 3 - mods/MAPGEN/mcl_mapgen_core/structures.lua | 192 ------------------ .../MAPGEN/mcl_structures/end_exit_portal.lua | 40 ++++ mods/MAPGEN/mcl_structures/structures.lua | 1 + 4 files changed, 41 insertions(+), 195 deletions(-) delete mode 100644 mods/MAPGEN/mcl_mapgen_core/structures.lua create mode 100644 mods/MAPGEN/mcl_structures/end_exit_portal.lua diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 5a9d3582e..3cedac4c0 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1602,9 +1602,6 @@ mcl_mapgen.register_mapgen_block_lvm(basic_safe, 1) local modpath = minetest.get_modpath(minetest.get_current_modname()) dofile(modpath .. "/clay.lua") dofile(modpath .. "/tree_decoration.lua") -if minetest.get_modpath("mcl_structures") then - dofile(modpath .. "/structures.lua") -end mcl_mapgen.register_mapgen_block_lvm(function(vm_context) local minp = vm_context.minp diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua deleted file mode 100644 index c4ab09d97..000000000 --- a/mods/MAPGEN/mcl_mapgen_core/structures.lua +++ /dev/null @@ -1,192 +0,0 @@ -local END_EXIT_PORTAL_POS = vector.new(-3, -27003, -3) -- End exit portal position -local OVERWORLD_STRUCT_MIN, OVERWORLD_STRUCT_MAX = mcl_mapgen.overworld.min, mcl_mapgen.overworld.max -local END_STRUCT_MIN, END_STRUCT_MAX = mcl_mapgen.end_.min, mcl_mapgen.end_.max -local DIVLEN = 5 -local V6 = mcl_mapgen.v6 - -local math_min, math_max = math.min, math.max -local math_floor, math_ceil = math.floor, math.ceil -local minetest_get_node = minetest.get_node -local minetest_get_mapgen_object = minetest.get_mapgen_object -local minetest_find_nodes_in_area = minetest.find_nodes_in_area -local minetest_get_item_group = minetest.get_item_group - -local perlin_structures - -local schematic_path = minetest.get_modpath('mcl_structures') - -local function determine_ground_level(p, vm_context) - local maxp = vm_context.maxp - local maxp_y = maxp.y - local y = math_min(OVERWORLD_STRUCT_MAX, maxp_y) - if y < maxp_y then - y = y + 1 - end - p.y = y - - local checknode = minetest_get_node(p) - local nn = checknode.name - if nn ~= "air" and minetest_get_item_group(nn, "attached_node") == 0 and minetest_get_item_group(nn, "deco_block") == 0 then return end - - for y = y - 1, math_max(OVERWORLD_STRUCT_MIN, vm_context.minp.y), -1 do - p.y = y - local checknode = minetest_get_node(p) - if checknode then - local nn = checknode.name - local def = minetest.registered_nodes[nn] - if def and def.walkable then - return p, y, nn - end - end - end -end - --- Helper function for converting a MC probability to MT, with --- regards to MapBlocks. --- Some MC generated structures are generated on per-chunk --- probability. --- The MC probability is 1/x per Minecraft chunk (16×16). - --- x: The MC probability is 1/x. --- minp, maxp: MapBlock limits --- returns: Probability (1/return_value) for a single MT mapblock -local function minecraft_chunk_probability(x, minp, maxp) - -- 256 is the MC chunk height - return x * (((maxp.x-minp.x+1)*(maxp.z-minp.z+1)) / 256) -end - --- Takes x and z coordinates and minp and maxp of a generated chunk --- (in on_generated callback) and returns a biomemap index) --- Inverse function of biomemap_to_xz -local function xz_to_biomemap_index(x, z, minp, maxp) - local zstride = maxp.z - minp.z + 1 - return (z - minp.z) * zstride + (x - minp.x) + 1 -end - ---local chunk_has_desert_struct ---local chunk_has_desert_temple - -local octaves = 3 -local persistence = 0.6 -local offset = 0 -local scale = 1 -local max_noise = 0 -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 - - --- TODO: Check spikes sizes, it looks like we have to swap them: - -local function spawn_ice_spike_large(p, pr) - -- Check surface - local floor = {x=p.x+4, y=p.y-1, z=p.z+4} - local surface = minetest_find_nodes_in_area({x=p.x+1,y=p.y-1,z=p.z+1}, floor, {"mcl_core:snowblock"}) - if #surface < 9 then return end - - -- Check for collision with spruce - local spruce_collisions = minetest_find_nodes_in_area({x=p.x+1,y=p.y+2,z=p.z+1}, {x=p.x+4, y=p.y+6, z=p.z+4}, {"mcl_core:sprucetree", "mcl_core:spruceleaves"}) - if #spruce_collisions > 0 then return end - - mcl_structures.call_struct(p, "ice_spike_large", nil, pr) - return true -end - -local function spawn_ice_spike_small(p, pr) - -- Check surface - local floor = {x=p.x+6, y=p.y-1, z=p.z+6} - local surface = minetest_find_nodes_in_area({x=p.x+1,y=p.y-1,z=p.z+1}, floor, {"mcl_core:snowblock", "mcl_core:dirt_with_grass_snow"}) - if #surface < 25 then return end - - -- Check for collision with spruce - local spruce_collisions = minetest_find_nodes_in_area({x=p.x+1,y=p.y+1,z=p.z+1}, {x=p.x+6, y=p.y+6, z=p.z+6}, {"mcl_core:sprucetree", "mcl_core:spruceleaves"}) - - if #spruce_collisions > 0 then return end - - mcl_structures.call_struct(p, "ice_spike_small", nil, pr) - return true -end - -local function spawn_spikes_in_v6(p, nn, pr) - -- In other mapgens, ice spikes are generated as decorations. - -- if chunk_has_igloo or nn ~= "mcl_core:snowblock" then return end - if nn ~= "mcl_core:snowblock" then return end - local spike = pr:next(1,58000) - if spike < 3 then - return spawn_ice_spike_large(p, pr) - elseif spike < 100 then - return spawn_ice_spike_small(p, pr) - end -end - -local function generate_structures(vm_context) - local pr = PcgRandom(vm_context.chunkseed) - -- chunk_has_desert_struct = false - -- chunk_has_desert_temple = false - local minp, maxp = vm_context.minp, vm_context.maxp - - perlin_structures = perlin_structures or minetest.get_perlin(329, 3, 0.6, 100) - - -- Assume X and Z lengths are equal - local DIVLEN = 5 - for x0 = minp.x, maxp.x, DIVLEN do for z0 = minp.z, maxp.z, DIVLEN do - -- Determine amount from perlin noise - -- Find random positions based on this random - local p, ground_y, nn - for i = 0, 24 do - --for i=0, amount do - -- p = {x = pr:next(x0, x0 + DIVLEN - 1), y = 0, z = pr:next(z0, z0 + DIVLEN - 1)} - p = {x = x0 + i % 5, z = z0 + math_floor(i/5)} - p, ground_y, nn = determine_ground_level(p, vm_context) - if ground_y then - p.y = ground_y + 1 - local nn0 = minetest.get_node(p).name - -- Check if the node can be replaced - if minetest.registered_nodes[nn0] and minetest.registered_nodes[nn0].buildable_to then - if V6 then - spawn_spikes_in_v6(p, nn, pr, vm_context) - end - end - end - end - end end - return vm_context -end - -local function generate_end_structures(vm_context) - local minp, maxp = vm_context.minp, vm_context.maxp - if minp.y <= END_EXIT_PORTAL_POS.y and maxp.y >= END_EXIT_PORTAL_POS.y - and minp.x <= END_EXIT_PORTAL_POS.x and maxp.x >= END_EXIT_PORTAL_POS.x - and minp.z <= END_EXIT_PORTAL_POS.z and maxp.z >= END_EXIT_PORTAL_POS.z - then - local p = {x=END_EXIT_PORTAL_POS.x, z=END_EXIT_PORTAL_POS.z} - for y = maxp.y, minp.y, -1 do - p.y = y - if minetest.get_node(p).name == "mcl_end:end_stone" then - mcl_mapgen_core.generate_end_exit_portal(p) - break - end - end - end - return vm_context -end - -if not mcl_mapgen.singlenode then - mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) - -- mcl_mapgen.register_on_generated(function(vm_context) - -- local minp, maxp = vm_context.minp, vm_context.maxp - local minp, maxp = minp, maxp - local minp_y, maxp_y = minp.y, maxp.y - generate_structures(vm_context) --- if maxp_y >= OVERWORLD_STRUCT_MIN and minp_y <= OVERWORLD_STRUCT_MAX then --- return generate_structures(vm_context) - -- End exit portal --- elseif maxp_y >= END_STRUCT_MIN and minp_y <= END_STRUCT_MAX then --- return generate_end_structures(vm_context) --- end --- return vm_context - end) -end diff --git a/mods/MAPGEN/mcl_structures/end_exit_portal.lua b/mods/MAPGEN/mcl_structures/end_exit_portal.lua new file mode 100644 index 000000000..e5d8dc380 --- /dev/null +++ b/mods/MAPGEN/mcl_structures/end_exit_portal.lua @@ -0,0 +1,40 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +local END_EXIT_PORTAL_POS_X = -3 +local END_EXIT_PORTAL_POS_Y = -27003 +local END_EXIT_PORTAL_POS_Z = -3 +local p = { + x = END_EXIT_PORTAL_POS_X, + y = END_EXIT_PORTAL_POS_Y, + z = END_EXIT_PORTAL_POS_Z, +} + +local schematic = modpath .. "/schematics/mcl_structures_end_exit_portal.mts" + +local function place(pos, rotation, pr) + mcl_structures.place_schematic({pos = pos, schematic = schematic, rotation = rotation, pr = pr}) +end + +mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) + local minp = minp + local y1 = minp.y + if y1 < END_EXIT_PORTAL_POS_Y then return end + local maxp = maxp + local y2 = maxp.y + if y2 > END_EXIT_PORTAL_POS_Y then return end + if minp.x < END_EXIT_PORTAL_POS_X then return end + if maxp.x > END_EXIT_PORTAL_POS_X then return end + if minp.z < END_EXIT_PORTAL_POS_Z then return end + if maxp.z > END_EXIT_PORTAL_POS_Z then return end + + for y = y2, y1, -1 do + p.y = y + if minetest.get_node(p).name == "mcl_end:end_stone" then + place(p, "0", PseudoRandom(vm_content.chunkseed)) + return + end + end +end) + +mcl_structures.register_structure({name = "end_exit_portal", place_function = place}) diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index 94fad4230..b18904d9a 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -4,6 +4,7 @@ local modpath = minetest.get_modpath(modname) if not mcl_mapgen.singlenode then dofile(modpath .. "/desert_temple.lua") dofile(modpath .. "/desert_well.lua") + dofile(modpath .. "/end_exit_portal.lua") dofile(modpath .. "/fossil.lua") dofile(modpath .. "/igloo.lua") dofile(modpath .. "/ice_spike_small.lua") From a36f3ba7d094b6fc2b423aff1a9620d308db092d Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 19 Jan 2022 04:09:19 +0400 Subject: [PATCH 57/61] Cleanup again --- mods/CORE/mcl_worlds/init.lua | 2 +- mods/ITEMS/mcl_deepslate/init.lua | 42 +++++++++++++++---------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/mods/CORE/mcl_worlds/init.lua b/mods/CORE/mcl_worlds/init.lua index a5d247465..eb366013e 100644 --- a/mods/CORE/mcl_worlds/init.lua +++ b/mods/CORE/mcl_worlds/init.lua @@ -61,7 +61,7 @@ local pos_to_dimension = mcl_worlds.pos_to_dimension -- MineClone 2. -- mc_dimension is one of "overworld", "nether", "end" (default: "overworld"). function mcl_worlds.layer_to_y(layer, mc_dimension) - if mc_dimension == "overworld" or mc_dimension == nil then + if not mc_dimension or mc_dimension == "overworld" then return layer + min1 elseif mc_dimension == "nether" then return layer + min3 diff --git a/mods/ITEMS/mcl_deepslate/init.lua b/mods/ITEMS/mcl_deepslate/init.lua index 55b8a5a79..7984ba89a 100644 --- a/mods/ITEMS/mcl_deepslate/init.lua +++ b/mods/ITEMS/mcl_deepslate/init.lua @@ -249,30 +249,30 @@ if minetest.settings:get_bool("mcl_generate_ores", true) then clust_size = size, y_min = y_min, y_max = y_max, - biomes = biomes, + biomes = biomes, }) end local ore_mapgen = { - { "coal", 1575, 5, 3, layer_min, layer_max }, - { "coal", 1530, 8, 3, layer_min, layer_max }, - { "coal", 1500, 12, 3, layer_min, layer_max }, - { "iron", 830, 5, 3, layer_min, layer_max }, - { "gold", 4775, 5, 3, layer_min, layer_max }, - { "gold", 6560, 7, 3, layer_min, layer_max }, - { "diamond", 10000, 4, 3, layer_min, mcl_worlds.layer_to_y(12) }, - { "diamond", 5000, 2, 3, layer_min, mcl_worlds.layer_to_y(12) }, - { "diamond", 10000, 8, 3, layer_min, mcl_worlds.layer_to_y(12) }, - { "diamond", 20000, 1, 1, mcl_worlds.layer_to_y(13), mcl_worlds.layer_to_y(15) }, - { "diamond", 20000, 2, 2, mcl_worlds.layer_to_y(13), mcl_worlds.layer_to_y(15) }, - { "redstone", 500, 4, 3, layer_min, mcl_worlds.layer_to_y(13) }, - { "redstone", 800, 7, 4, layer_min, mcl_worlds.layer_to_y(13) }, - { "redstone", 1000, 4, 3, mcl_worlds.layer_to_y(13), mcl_worlds.layer_to_y(15) }, - { "redstone", 1600, 7, 4, mcl_worlds.layer_to_y(13), mcl_worlds.layer_to_y(15) }, - { "lapis", 10000, 7, 4, mcl_worlds.layer_to_y(14), layer_max }, - { "lapis", 12000, 6, 3, mcl_worlds.layer_to_y(10), mcl_worlds.layer_to_y(13) }, - { "lapis", 14000, 5, 3, mcl_worlds.layer_to_y(6), mcl_worlds.layer_to_y(9) }, - { "lapis", 16000, 4, 3, mcl_worlds.layer_to_y(2), mcl_worlds.layer_to_y(5) }, - { "lapis", 18000, 3, 2, mcl_worlds.layer_to_y(0), mcl_worlds.layer_to_y(2) }, + { "coal" , 1575, 5, 3, layer_min , layer_max }, + { "coal" , 1530, 8, 3, layer_min , layer_max }, + { "coal" , 1500, 12, 3, layer_min , layer_max }, + { "iron" , 830, 5, 3, layer_min , layer_max }, + { "gold" , 4775, 5, 3, layer_min , layer_max }, + { "gold" , 6560, 7, 3, layer_min , layer_max }, + { "diamond" , 10000, 4, 3, layer_min , mcl_worlds.layer_to_y(12) }, + { "diamond" , 5000, 2, 3, layer_min , mcl_worlds.layer_to_y(12) }, + { "diamond" , 10000, 8, 3, layer_min , mcl_worlds.layer_to_y(12) }, + { "diamond" , 20000, 1, 1, mcl_worlds.layer_to_y(13), mcl_worlds.layer_to_y(15) }, + { "diamond" , 20000, 2, 2, mcl_worlds.layer_to_y(13), mcl_worlds.layer_to_y(15) }, + { "redstone", 500, 4, 3, layer_min , mcl_worlds.layer_to_y(13) }, + { "redstone", 800, 7, 4, layer_min , mcl_worlds.layer_to_y(13) }, + { "redstone", 1000, 4, 3, mcl_worlds.layer_to_y(13), mcl_worlds.layer_to_y(15) }, + { "redstone", 1600, 7, 4, mcl_worlds.layer_to_y(13), mcl_worlds.layer_to_y(15) }, + { "lapis" , 10000, 7, 4, mcl_worlds.layer_to_y(14), layer_max }, + { "lapis" , 12000, 6, 3, mcl_worlds.layer_to_y(10), mcl_worlds.layer_to_y(13) }, + { "lapis" , 14000, 5, 3, mcl_worlds.layer_to_y(6) , mcl_worlds.layer_to_y(9) }, + { "lapis" , 16000, 4, 3, mcl_worlds.layer_to_y(2) , mcl_worlds.layer_to_y(5) }, + { "lapis" , 18000, 3, 2, mcl_worlds.layer_to_y(0) , mcl_worlds.layer_to_y(2) }, } for _, o in pairs(ore_mapgen) do register_ore_mg("mcl_deepslate:deepslate_with_"..o[1], o[2], o[3], o[4], o[5], o[6]) From 89769b8168479b8a79133e1d245a5774ef45f208 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 19 Jan 2022 04:11:29 +0400 Subject: [PATCH 58/61] Fix Nether portal in End --- mods/ITEMS/mcl_portals/portal_nether.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/ITEMS/mcl_portals/portal_nether.lua b/mods/ITEMS/mcl_portals/portal_nether.lua index 405e275d4..e6dd255f0 100644 --- a/mods/ITEMS/mcl_portals/portal_nether.lua +++ b/mods/ITEMS/mcl_portals/portal_nether.lua @@ -696,6 +696,7 @@ local function teleport_no_delay(obj, pos) finalize_teleport(obj, exit) else dim = dimension_to_teleport[dim] + if not dim then return end -- need to create arrival portal create_portal(target, limits[dim].pmin, limits[dim].pmax, name, obj) end From 2a26adac0f39bacf7630ac8520eca1a2c6ce4b08 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 19 Jan 2022 04:53:55 +0400 Subject: [PATCH 59/61] Fix End --- mods/CORE/mcl_mapgen/init.lua | 6 +++- mods/MAPGEN/mcl_mapgen_core/init.lua | 29 ++++++++++--------- .../MAPGEN/mcl_structures/end_exit_portal.lua | 28 +++++++++++++----- mods/MAPGEN/mcl_structures/init.lua | 2 +- mods/MAPGEN/mcl_structures/structures.lua | 2 +- 5 files changed, 43 insertions(+), 24 deletions(-) diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index e20583312..aa2630411 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -276,9 +276,11 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) vm:set_light_data(light) end if vm_context.write or vm_context.write_param2 or vm_context.write_light then - vm:calc_lighting(minp, maxp, vm_context.shadow or true) -- TODO: check boundaries + vm:calc_lighting(minp, maxp, (vm_context.shadow ~= nil) or true) -- TODO: check boundaries vm:write_to_map() vm:update_liquids() + elseif vm_context.calc_lighting then + vm:calc_lighting(minp, maxp, (vm_context.shadow ~= nil) or true) end end @@ -323,6 +325,8 @@ minetest.register_on_generated(function(minp, maxp, chunkseed) -- vm:calc_lighting(minp, maxp, vm_context.shadow or true) vm:write_to_map() vm:update_liquids() + elseif vm_context.calc_lighting then + vm:calc_lighting(minp, maxp, (vm_context.shadow ~= nil) or true) end current_chunks[i] = nil end diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 3cedac4c0..b259f59f9 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1574,17 +1574,6 @@ local function basic_safe(vm_context) end end - -- Final hackery: Set sun light level in the End. - -- -26912 is at a mapchunk border. - local shadow = true - if minp.y >= -26912 and maxp.y <= mcl_mapgen.end_.max then - vm:set_lighting({day=15, night=15}) - lvm_used = true - end - if minp.y >= mcl_mapgen.end_.min and maxp.y <= -26911 then - shadow = false - lvm_used = true - end if not singlenode then -- Generate special decorations @@ -1593,8 +1582,6 @@ local function basic_safe(vm_context) end vm_context.write = vm_context.write or lvm_used - - return vm_context --, lvm_used, shadow end mcl_mapgen.register_mapgen_block_lvm(basic_safe, 1) @@ -1603,6 +1590,7 @@ local modpath = minetest.get_modpath(minetest.get_current_modname()) dofile(modpath .. "/clay.lua") dofile(modpath .. "/tree_decoration.lua") +-- Nether Roof Light: mcl_mapgen.register_mapgen_block_lvm(function(vm_context) local minp = vm_context.minp local miny = minp.y @@ -1613,4 +1601,19 @@ mcl_mapgen.register_mapgen_block_lvm(function(vm_context) local p1 = {x = minp.x, y = math.max(miny, mcl_mapgen.nether.max + 1), z = minp.z} local p2 = {x = maxp.x, y = math.min(maxy, mcl_mapgen.nether.max + 127), z = maxp.z} vm_context.vm:set_lighting({day=15, night=15}, p1, p2) + vm_context.write = true end, 999999999) + +-- End Light: +mcl_mapgen.register_mapgen_block_lvm(function(vm_context) + local minp = vm_context.minp + local miny = minp.y + if miny > mcl_mapgen.end_.max then return end + local maxp = vm_context.maxp + local maxy = maxp.y + if maxy <= mcl_mapgen.end_.min then return end + local p1 = {x = minp.x, y = math.max(miny, mcl_mapgen.end_.min), z = maxp.z} + local p2 = {x = maxp.x, y = math.min(maxy, mcl_mapgen.end_.max), z = maxp.z} + vm_context.vm:set_lighting({day=15, night=15}, p1, p2) + vm_context.write = true +end, 9999999999) diff --git a/mods/MAPGEN/mcl_structures/end_exit_portal.lua b/mods/MAPGEN/mcl_structures/end_exit_portal.lua index e5d8dc380..4deea1bc1 100644 --- a/mods/MAPGEN/mcl_structures/end_exit_portal.lua +++ b/mods/MAPGEN/mcl_structures/end_exit_portal.lua @@ -4,7 +4,7 @@ local modpath = minetest.get_modpath(modname) local END_EXIT_PORTAL_POS_X = -3 local END_EXIT_PORTAL_POS_Y = -27003 local END_EXIT_PORTAL_POS_Z = -3 -local p = { +local p0 = { x = END_EXIT_PORTAL_POS_X, y = END_EXIT_PORTAL_POS_Y, z = END_EXIT_PORTAL_POS_Z, @@ -19,15 +19,17 @@ end mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) local minp = minp local y1 = minp.y - if y1 < END_EXIT_PORTAL_POS_Y then return end + if y1 > END_EXIT_PORTAL_POS_Y then return end local maxp = maxp local y2 = maxp.y - if y2 > END_EXIT_PORTAL_POS_Y then return end - if minp.x < END_EXIT_PORTAL_POS_X then return end - if maxp.x > END_EXIT_PORTAL_POS_X then return end - if minp.z < END_EXIT_PORTAL_POS_Z then return end - if maxp.z > END_EXIT_PORTAL_POS_Z then return end - + if y2 < END_EXIT_PORTAL_POS_Y then return end + if minp.x > END_EXIT_PORTAL_POS_X then return end + if maxp.x < END_EXIT_PORTAL_POS_X then return end + if minp.z > END_EXIT_PORTAL_POS_Z then return end + if maxp.z < END_EXIT_PORTAL_POS_Z then return end + + local p = table.copy(p0) + for y = y2, y1, -1 do p.y = y if minetest.get_node(p).name == "mcl_end:end_stone" then @@ -35,6 +37,16 @@ mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) return end end + + for y = y2, y1, -1 do + p.y = y + if minetest.get_node(p).name ~= "air" then + place(p, "0", PseudoRandom(vm_content.chunkseed)) + return + end + end + + place(p0, "0", PseudoRandom(vm_content.chunkseed)) end) mcl_structures.register_structure({name = "end_exit_portal", place_function = place}) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index c43640fd1..64f6db937 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -159,7 +159,7 @@ function mcl_structures.register_structure(def) local decoration_id if decoration then minetest.register_node(':' .. name, { - -- drawtype = "airlike", + drawtype = "airlike", sunlight_propagates = true, pointable = false, walkable = false, diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index b18904d9a..fd6b21b26 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -11,7 +11,7 @@ if not mcl_mapgen.singlenode then dofile(modpath .. "/ice_spike_large.lua") dofile(modpath .. "/jungle_temple.lua") dofile(modpath .. "/nice_jungle_temple.lua") - dofile(modpath .. "/noise_indicator.lua") + -- dofile(modpath .. "/noise_indicator.lua") dofile(modpath .. "/stronghold.lua") dofile(modpath .. "/witch_hut.lua") end From 6c367977a8a81e36066bc89cb8f94e3c07e7af38 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 19 Jan 2022 04:55:15 +0400 Subject: [PATCH 60/61] Fix a bug --- mods/MAPGEN/mcl_structures/end_exit_portal.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/MAPGEN/mcl_structures/end_exit_portal.lua b/mods/MAPGEN/mcl_structures/end_exit_portal.lua index 4deea1bc1..a0a171ee7 100644 --- a/mods/MAPGEN/mcl_structures/end_exit_portal.lua +++ b/mods/MAPGEN/mcl_structures/end_exit_portal.lua @@ -33,7 +33,7 @@ mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) for y = y2, y1, -1 do p.y = y if minetest.get_node(p).name == "mcl_end:end_stone" then - place(p, "0", PseudoRandom(vm_content.chunkseed)) + place(p, "0", PseudoRandom(vm_context.chunkseed)) return end end @@ -41,12 +41,12 @@ mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) for y = y2, y1, -1 do p.y = y if minetest.get_node(p).name ~= "air" then - place(p, "0", PseudoRandom(vm_content.chunkseed)) + place(p, "0", PseudoRandom(vm_context.chunkseed)) return end end - place(p0, "0", PseudoRandom(vm_content.chunkseed)) + place(p0, "0", PseudoRandom(vm_context.chunkseed)) end) mcl_structures.register_structure({name = "end_exit_portal", place_function = place}) From b305eceee9ec470351828c15af104ca201e4a4e5 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 19 Jan 2022 04:57:27 +0400 Subject: [PATCH 61/61] Fix End ligh bug --- mods/MAPGEN/mcl_mapgen_core/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index b259f59f9..8f4278357 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1612,7 +1612,7 @@ mcl_mapgen.register_mapgen_block_lvm(function(vm_context) local maxp = vm_context.maxp local maxy = maxp.y if maxy <= mcl_mapgen.end_.min then return end - local p1 = {x = minp.x, y = math.max(miny, mcl_mapgen.end_.min), z = maxp.z} + local p1 = {x = minp.x, y = math.max(miny, mcl_mapgen.end_.min), z = minp.z} local p2 = {x = maxp.x, y = math.min(maxy, mcl_mapgen.end_.max), z = maxp.z} vm_context.vm:set_lighting({day=15, night=15}, p1, p2) vm_context.write = true