Camas/mods/village/mapgen.lua

135 lines
4.1 KiB
Lua
Raw Normal View History

--
-- Mapgen
--
2019-08-28 17:31:41 +02:00
local S = minetest.get_translator("village")
local spawn_pos = minetest.setting_get_pos("static_spawnpoint") or {x = 0, y = 0, z = 0}
local spawn_radius = minetest.settings:get("static_spawn_radius") or 256
local mapseed = minetest.get_mapgen_setting("seed")
-- Nodes
minetest.register_node(
2015-09-01 17:15:24 +02:00
"village:entity_spawner",
{
2019-08-28 17:31:41 +02:00
description = S("Village Entity Spawner"),
2019-08-29 15:50:58 +02:00
tiles = {
"village_entity.png", "village_entity.png", "village_entity.png",
"village_entity.png", "village_entity.png^[transformFX", "village_entity.png^[transformFX"
},
2015-09-01 17:15:24 +02:00
is_ground_content = false,
2019-08-29 16:22:42 +02:00
drop = "",
groups = {dig_immediate = 2, not_in_creative_inventory = 1},
2019-08-29 15:50:58 +02:00
sounds = default.node_sound_defaults()
2017-05-11 23:10:00 +02:00
})
2015-09-01 17:15:24 +02:00
minetest.register_node(
2015-09-01 17:15:24 +02:00
"village:grassland_village",
{
2019-08-28 17:31:41 +02:00
description = S("Village Spawner"),
2019-08-29 15:50:58 +02:00
tiles = {
"village_gen.png", "village_gen.png", "village_gen.png",
"village_gen.png", "village_gen.png^[transformFX", "village_gen.png^[transformFX",
},
is_ground_content = false,
groups = {dig_immediate = 2},
2019-08-29 14:58:02 +02:00
sounds = default.node_sound_dirt_defaults(),
2019-08-29 16:22:42 +02:00
drop = "",
on_construct = function(pos)
minetest.remove_node(pos)
local pr = PseudoRandom(mapseed
+ pos.x + pos.y + pos.z)
village.spawn_village(pos, pr)
end,
2017-05-11 23:10:00 +02:00
})
2015-09-01 17:15:24 +02:00
2019-09-03 16:13:21 +02:00
-- TODO: Remove
minetest.register_node(
"village:grassland_village_mg",
2015-09-01 17:15:24 +02:00
{
2019-09-03 16:13:21 +02:00
description = S("Legacy Mapgen Village Spawner"),
tiles = {"village_gen_mg.png"},
drawtype = "normal",
2015-09-07 00:09:12 +02:00
paramtype = "light",
sunlight_propagates = true,
walkable = false,
2019-09-03 16:13:21 +02:00
pointable = true,
diggable = true,
2015-09-07 00:09:12 +02:00
buildable_to = false,
is_ground_content = true,
drop = "",
2019-09-03 16:13:21 +02:00
groups = {not_in_craft_guide = 1, not_in_creative_inventory=1, dig_immediate = 2},
2017-05-11 23:10:00 +02:00
})
2015-09-01 17:15:24 +02:00
2019-09-03 16:13:21 +02:00
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 + spos.x + spos.y + spos.z)
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, 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
2019-09-03 16:13:21 +02:00
local village_decoration_id
if not minetest.settings:get_bool("mapgen_disable_villages") then
2019-09-03 16:13:21 +02:00
-- Dummy decoration to find possible village spawn points
-- via gennotify.
minetest.register_decoration(
{
2019-09-03 16:13:21 +02:00
name = "village_grassland",
deco_type = "schematic",
place_on = "default:dirt_with_grass",
sidelen = 16,
fill_ratio = 0.005,
biomes = {
"Grassland",
"Forest"
},
2019-09-03 16:13:21 +02:00
-- empty schematic
schematic = {
size = { x = 1, y = 1, z = 1 },
data = {
{ name = "air", prob = 0 },
},
},
y_min = 1,
y_max = 1000,
})
2019-09-03 16:13:21 +02:00
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
2019-09-03 16:13:21 +02:00