Prevent villages from spawning near the static spawnpoint; closes #43
This commit is contained in:
parent
fcee665c27
commit
6693590126
@ -1,13 +1,16 @@
|
|||||||
|
|
||||||
--
|
--
|
||||||
-- Single village generation
|
-- Single village generation
|
||||||
--
|
--
|
||||||
|
|
||||||
local mp = minetest.get_modpath("village")
|
|
||||||
|
|
||||||
village.villages = {}
|
village.villages = {}
|
||||||
|
|
||||||
|
-- Savefile
|
||||||
|
|
||||||
local village_file = minetest.get_worldpath() .. "/villages.dat"
|
local village_file = minetest.get_worldpath() .. "/villages.dat"
|
||||||
|
|
||||||
|
local modpath = minetest.get_modpath("village")
|
||||||
|
|
||||||
function village.get_id(name, pos)
|
function village.get_id(name, pos)
|
||||||
return name .. minetest.hash_node_position(pos)
|
return name .. minetest.hash_node_position(pos)
|
||||||
end
|
end
|
||||||
@ -16,7 +19,8 @@ function village.save_villages()
|
|||||||
local f = io.open(village_file, "w")
|
local f = io.open(village_file, "w")
|
||||||
|
|
||||||
for name, def in pairs(village.villages) do
|
for name, def in pairs(village.villages) do
|
||||||
f:write(name .. " " .. def.name .. " " .. minetest.hash_node_position(def.pos) .. "\n")
|
f:write(name .. " " .. def.name .. " "
|
||||||
|
.. minetest.hash_node_position(def.pos) .. "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
io.close(f)
|
io.close(f)
|
||||||
@ -220,7 +224,7 @@ function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill)
|
|||||||
|
|
||||||
minetest.place_schematic(
|
minetest.place_schematic(
|
||||||
pos,
|
pos,
|
||||||
mp.."/schematics/village_empty.mts",
|
modpath .. "/schematics/village_empty.mts",
|
||||||
"0",
|
"0",
|
||||||
{},
|
{},
|
||||||
true
|
true
|
||||||
@ -228,7 +232,7 @@ function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill)
|
|||||||
|
|
||||||
minetest.place_schematic(
|
minetest.place_schematic(
|
||||||
{x = pos.x-6, y = pos.y-5, z = pos.z-6},
|
{x = pos.x-6, y = pos.y-5, z = pos.z-6},
|
||||||
mp.."/schematics/village_filler.mts",
|
modpath .. "/schematics/village_filler.mts",
|
||||||
"0",
|
"0",
|
||||||
{},
|
{},
|
||||||
false
|
false
|
||||||
@ -237,7 +241,7 @@ function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill)
|
|||||||
|
|
||||||
minetest.place_schematic(
|
minetest.place_schematic(
|
||||||
pos,
|
pos,
|
||||||
mp.."/schematics/village_"..chunktype..".mts",
|
modpath .. "/schematics/village_" .. chunktype .. ".mts",
|
||||||
orient,
|
orient,
|
||||||
replace,
|
replace,
|
||||||
true
|
true
|
||||||
|
@ -5,15 +5,16 @@
|
|||||||
|
|
||||||
village = {}
|
village = {}
|
||||||
|
|
||||||
village.min_size = 2 -- min chunk gen iterations
|
village.min_size = 2 -- Min chunk gen iterations
|
||||||
village.max_size = 6 -- max chunk gen iterations
|
village.max_size = 6 -- Max chunk gen iterations
|
||||||
|
|
||||||
village.min_spawn_dist = 256 -- closest distance a village will spawn from another village
|
-- Closest distance a village will spawn from another village
|
||||||
|
village.min_spawn_dist = 512
|
||||||
|
|
||||||
village.pr = PseudoRandom(minetest.get_mapgen_params().seed)
|
village.pr = PseudoRandom(minetest.get_mapgen_params().seed)
|
||||||
|
|
||||||
dofile(minetest.get_modpath("village").."/names.lua")
|
dofile(minetest.get_modpath("village") .. "/names.lua")
|
||||||
dofile(minetest.get_modpath("village").."/generate.lua")
|
dofile(minetest.get_modpath("village") .. "/generate.lua")
|
||||||
dofile(minetest.get_modpath("village").."/mapgen.lua")
|
dofile(minetest.get_modpath("village") .. "/mapgen.lua")
|
||||||
|
|
||||||
default.log("mod:village", "loaded")
|
default.log("mod:village", "loaded")
|
||||||
|
@ -1,3 +1,13 @@
|
|||||||
|
|
||||||
|
--
|
||||||
|
-- Mapgen
|
||||||
|
--
|
||||||
|
|
||||||
|
local spawn_pos = minetest.setting_get_pos("static_spawnpoint") or {x = 0, y = 0, z = 0}
|
||||||
|
local spawn_radius = minetest.setting_get("static_spawn_radius") or 256
|
||||||
|
|
||||||
|
-- Nodes
|
||||||
|
|
||||||
minetest.register_node(
|
minetest.register_node(
|
||||||
"village:entity_spawner",
|
"village:entity_spawner",
|
||||||
{
|
{
|
||||||
@ -15,7 +25,16 @@ minetest.register_node(
|
|||||||
tiles = {"default_grass.png^default_book.png"},
|
tiles = {"default_grass.png^default_book.png"},
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
groups = {dig_immediate = 2},
|
groups = {dig_immediate = 2},
|
||||||
sounds = default.node_sound_wood_defaults()
|
sounds = default.node_sound_wood_defaults(),
|
||||||
|
|
||||||
|
on_construct = function(pos)
|
||||||
|
minetest.remove_node(pos)
|
||||||
|
|
||||||
|
local pr = PseudoRandom(minetest.get_mapgen_params().seed
|
||||||
|
+ pos.x + pos.y + pos.z)
|
||||||
|
|
||||||
|
village.spawn_village(pos, pr)
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(
|
minetest.register_node(
|
||||||
@ -35,11 +54,18 @@ minetest.register_node(
|
|||||||
groups = {not_in_craftingguide = 1},
|
groups = {not_in_craftingguide = 1},
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_abm(
|
-- Spawning LBM
|
||||||
|
|
||||||
|
minetest.register_lbm(
|
||||||
{
|
{
|
||||||
nodenames = {"village:grassland_village", "village:grassland_village_mg"},
|
name = "village:spawn_village",
|
||||||
interval = 1,
|
label = "Village spawning",
|
||||||
chance = 1,
|
nodenames = {
|
||||||
|
"village:grassland_village_mg",
|
||||||
|
},
|
||||||
|
|
||||||
|
run_at_every_load = true,
|
||||||
|
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
|
|
||||||
@ -47,37 +73,49 @@ minetest.register_abm(
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local pr = PseudoRandom(minetest.get_mapgen_params().seed+pos.x+pos.y+pos.z)
|
local pr = PseudoRandom(minetest.get_mapgen_params().seed
|
||||||
|
+ pos.x + pos.y + pos.z)
|
||||||
|
|
||||||
if node.name == "village:grassland_village_mg" then
|
if ((minetest.get_mapgen_params().seed + pos.x + pos.y + pos.z) % 30) == 1 then
|
||||||
if ((minetest.get_mapgen_params().seed+pos.x+pos.y+pos.z) % 30) == 1 then
|
local nearest = village.get_nearest_village(pos)
|
||||||
local nearest = village.get_nearest_village(pos)
|
|
||||||
|
|
||||||
if nearest.dist > village.min_spawn_dist then
|
if nearest.dist > village.min_spawn_dist then
|
||||||
minetest.log("Spawning a (Mapgen)Grassland village at "..dump(pos))
|
if vector.distance(spawn_pos, pos) > spawn_radius then
|
||||||
|
minetest.log("Spawning a Grassland village at " .. "(" .. pos.x
|
||||||
|
.. ", " .. pos.y .. ", " .. pos.z .. ")")
|
||||||
|
|
||||||
-- a short delay to (hopefully) ensure that the surrounding terrain is generated
|
minetest.after(
|
||||||
minetest.after(3.0, function() village.spawn_village(pos, pr) end)
|
2.0,
|
||||||
|
function()
|
||||||
|
village.spawn_village(pos, pr)
|
||||||
|
end)
|
||||||
else
|
else
|
||||||
minetest.log("Cannot spawn village, too near another village")
|
minetest.log("Cannot spawn village, too near the static spawnpoint")
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
minetest.log("Cannot spawn village, too near another village")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
minetest.log("Spawning a Grassland village at "..dump(pos))
|
|
||||||
|
|
||||||
village.spawn_village(pos, pr)
|
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_decoration(
|
-- Spawn decoration
|
||||||
{
|
|
||||||
deco_type = "simple",
|
if not minetest.setting_getbool("mapgen_disable_villages") then
|
||||||
place_on = "default:dirt_with_grass",
|
minetest.register_decoration(
|
||||||
sidelen = 16,
|
{
|
||||||
fill_ratio = 0.005,
|
deco_type = "simple",
|
||||||
biomes = {"Grassland", "Forest"},
|
place_on = "default:dirt_with_grass",
|
||||||
decoration = {"village:grassland_village_mg"},
|
sidelen = 16,
|
||||||
y_min = 1,
|
fill_ratio = 0.005,
|
||||||
y_max = 1000,
|
biomes = {
|
||||||
})
|
"Grassland",
|
||||||
|
"Forest"
|
||||||
|
},
|
||||||
|
decoration = {
|
||||||
|
"village:grassland_village_mg"
|
||||||
|
},
|
||||||
|
y_min = 1,
|
||||||
|
y_max = 1000,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
@ -28,7 +28,9 @@ tnt_radius (TNT radius) int 3
|
|||||||
mobs_peaceful (Peaceful mobs) bool false
|
mobs_peaceful (Peaceful mobs) bool false
|
||||||
mobs_safe_spawn (Safe spawn from mobs) bool true
|
mobs_safe_spawn (Safe spawn from mobs) bool true
|
||||||
|
|
||||||
static_spawn_radius (Safe spawn radius) int 256
|
## Spawning
|
||||||
|
|
||||||
|
static_spawn_radius (Spawnpoint safety radius) int 256
|
||||||
|
|
||||||
## Beds
|
## Beds
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user