From c9f95963252fd14b5aa7951c02c290ab83b6990a Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 3 Sep 2019 16:13:21 +0200 Subject: [PATCH] Village spawning: Use gennotify --- mods/village/mapgen.lua | 109 ++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/mods/village/mapgen.lua b/mods/village/mapgen.lua index 99d6aa3..d2139ba 100644 --- a/mods/village/mapgen.lua +++ b/mods/village/mapgen.lua @@ -47,76 +47,58 @@ minetest.register_node( end, }) +-- TODO: Remove minetest.register_node( "village:grassland_village_mg", { - description = S("Mapgen Village Spawner").."\n"..S("(Has chance of not spawning village)"), - inventory_image = "village_gen_mg.png", - wield_image = "village_gen_mg.png", - drawtype = "airlike", + description = S("Legacy Mapgen Village Spawner"), + tiles = {"village_gen_mg.png"}, + drawtype = "normal", paramtype = "light", sunlight_propagates = true, walkable = false, - pointable = false, - diggable = false, + pointable = true, + diggable = true, buildable_to = false, is_ground_content = true, - air_equivalent = true, drop = "", - groups = {not_in_craft_guide = 1, not_in_creative_inventory=1}, + groups = {not_in_craft_guide = 1, not_in_creative_inventory=1, dig_immediate = 2}, }) --- Spawning LBM +local function attempt_village_spawn(pos) + local spos = table.copy(pos) + spos.y = spos.y + 1 + if minetest.settings:get_bool("mapgen_disable_villages") == true then + return + end -minetest.register_lbm( - { - name = "village:spawn_village", - label = "Village spawning", - nodenames = { - "village:grassland_village_mg", - }, + local pr = PseudoRandom(mapseed + spos.x + spos.y + spos.z) - run_at_every_load = true, + if ((mapseed + spos.x + spos.y + spos.z) % 30) == 1 then + local nearest = village.get_nearest_village(spos) - action = function(pos, node) - minetest.remove_node(pos) - - if minetest.settings:get_bool("mapgen_disable_villages") == true then - return - end - - local pr = PseudoRandom(mapseed - + pos.x + pos.y + pos.z) - - if ((mapseed + pos.x + pos.y + pos.z) % 30) == 1 then - local nearest = village.get_nearest_village(pos) - - if nearest.dist > village.min_spawn_dist then - if vector.distance(spawn_pos, pos) > spawn_radius then - minetest.log("action", "[village] Spawning a Grassland village at " .. "(" .. pos.x - .. ", " .. pos.y .. ", " .. pos.z .. ")") - - minetest.after( - 2.0, - function(pos, pr) - village.spawn_village(pos, pr) - end, pos, pr) - else - minetest.log("action", "[village] Cannot spawn village, too near the static spawnpoint") - end - else - minetest.log("action", "[village] Cannot spawn village, too near another village") - end - end - end, -}) - --- Spawn decoration + if nearest.dist > village.min_spawn_dist then + if vector.distance(spawn_pos, spos) > spawn_radius then + minetest.log("action", "[village] Spawning a grassland village at " .. "(" .. spos.x + .. ", " .. spos.y .. ", " .. spos.z .. ")") + village.spawn_village(spos, pr) + else + minetest.log("action", "[village] Cannot spawn village, too near the static spawnpoint") + end + else + minetest.log("action", "[village] Cannot spawn village, too near another village") + end + end +end +local village_decoration_id if not minetest.settings:get_bool("mapgen_disable_villages") then + -- Dummy decoration to find possible village spawn points + -- via gennotify. minetest.register_decoration( { - deco_type = "simple", + name = "village_grassland", + deco_type = "schematic", place_on = "default:dirt_with_grass", sidelen = 16, fill_ratio = 0.005, @@ -124,10 +106,29 @@ if not minetest.settings:get_bool("mapgen_disable_villages") then "Grassland", "Forest" }, - decoration = { - "village:grassland_village_mg" + -- empty schematic + schematic = { + size = { x = 1, y = 1, z = 1 }, + data = { + { name = "air", prob = 0 }, + }, }, y_min = 1, y_max = 1000, }) + village_decoration_id = minetest.get_decoration_id("village_grassland") + + if village_decoration_id then + minetest.set_gen_notify({decoration=true}, {village_decoration_id}) + minetest.register_on_generated(function(minp, maxp, blockseed) + local mgobj = minetest.get_mapgen_object("gennotify") + local deco = mgobj["decoration#"..village_decoration_id] + if deco then + for d=1, #deco do + attempt_village_spawn(deco[d]) + end + end + end) + end end +