Village spawning: Use gennotify
This commit is contained in:
parent
77a46578da
commit
c9f9596325
@ -47,60 +47,41 @@ 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
|
||||
|
||||
minetest.register_lbm(
|
||||
{
|
||||
name = "village:spawn_village",
|
||||
label = "Village spawning",
|
||||
nodenames = {
|
||||
"village:grassland_village_mg",
|
||||
},
|
||||
|
||||
run_at_every_load = true,
|
||||
|
||||
action = function(pos, node)
|
||||
minetest.remove_node(pos)
|
||||
|
||||
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
|
||||
|
||||
local pr = PseudoRandom(mapseed
|
||||
+ pos.x + pos.y + pos.z)
|
||||
local pr = PseudoRandom(mapseed + spos.x + spos.y + spos.z)
|
||||
|
||||
if ((mapseed + pos.x + pos.y + pos.z) % 30) == 1 then
|
||||
local nearest = village.get_nearest_village(pos)
|
||||
if ((mapseed + spos.x + spos.y + spos.z) % 30) == 1 then
|
||||
local nearest = village.get_nearest_village(spos)
|
||||
|
||||
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)
|
||||
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
|
||||
@ -108,15 +89,16 @@ minetest.register_lbm(
|
||||
minetest.log("action", "[village] Cannot spawn village, too near another village")
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Spawn decoration
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user