Village spawning: Use gennotify

This commit is contained in:
Wuzzy 2019-09-03 16:13:21 +02:00
parent 77a46578da
commit c9f9596325

View File

@ -47,76 +47,58 @@ minetest.register_node(
end, end,
}) })
-- TODO: Remove
minetest.register_node( minetest.register_node(
"village:grassland_village_mg", "village:grassland_village_mg",
{ {
description = S("Mapgen Village Spawner").."\n"..S("(Has chance of not spawning village)"), description = S("Legacy Mapgen Village Spawner"),
inventory_image = "village_gen_mg.png", tiles = {"village_gen_mg.png"},
wield_image = "village_gen_mg.png", drawtype = "normal",
drawtype = "airlike",
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
walkable = false, walkable = false,
pointable = false, pointable = true,
diggable = false, diggable = true,
buildable_to = false, buildable_to = false,
is_ground_content = true, is_ground_content = true,
air_equivalent = true,
drop = "", 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( local pr = PseudoRandom(mapseed + spos.x + spos.y + spos.z)
{
name = "village:spawn_village",
label = "Village spawning",
nodenames = {
"village:grassland_village_mg",
},
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) if nearest.dist > village.min_spawn_dist then
minetest.remove_node(pos) if vector.distance(spawn_pos, spos) > spawn_radius then
minetest.log("action", "[village] Spawning a grassland village at " .. "(" .. spos.x
if minetest.settings:get_bool("mapgen_disable_villages") == true then .. ", " .. spos.y .. ", " .. spos.z .. ")")
return village.spawn_village(spos, pr)
end else
minetest.log("action", "[village] Cannot spawn village, too near the static spawnpoint")
local pr = PseudoRandom(mapseed end
+ pos.x + pos.y + pos.z) else
minetest.log("action", "[village] Cannot spawn village, too near another village")
if ((mapseed + pos.x + pos.y + pos.z) % 30) == 1 then end
local nearest = village.get_nearest_village(pos) end
end
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
local village_decoration_id
if not minetest.settings:get_bool("mapgen_disable_villages") then if not minetest.settings:get_bool("mapgen_disable_villages") then
-- Dummy decoration to find possible village spawn points
-- via gennotify.
minetest.register_decoration( minetest.register_decoration(
{ {
deco_type = "simple", name = "village_grassland",
deco_type = "schematic",
place_on = "default:dirt_with_grass", place_on = "default:dirt_with_grass",
sidelen = 16, sidelen = 16,
fill_ratio = 0.005, fill_ratio = 0.005,
@ -124,10 +106,29 @@ if not minetest.settings:get_bool("mapgen_disable_villages") then
"Grassland", "Grassland",
"Forest" "Forest"
}, },
decoration = { -- empty schematic
"village:grassland_village_mg" schematic = {
size = { x = 1, y = 1, z = 1 },
data = {
{ name = "air", prob = 0 },
},
}, },
y_min = 1, y_min = 1,
y_max = 1000, 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 end