From abc3a1f13928c75864afc5b3d4e033e20333fe44 Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 26 Apr 2021 03:35:54 +0400 Subject: [PATCH] [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