Minor changes to villages backend

This commit is contained in:
KaadmY 2017-05-11 14:10:00 -07:00
parent 583925d611
commit abb1c196da
3 changed files with 42 additions and 32 deletions

View File

@ -62,7 +62,7 @@ end
function village.get_nearest_village(pos)
local nearest = 100000 -- big number
local name = nil
for name, def in pairs(village.villages) do
local dist = vector.distance(pos, def.pos)
if dist < nearest then
@ -208,7 +208,7 @@ end
function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill)
util.getvoxelmanip(pos, {x = pos.x+12, y = pos.y+12, z = pos.z+12})
if nofill ~= true then
util.nodefunc(
{x = pos.x-6, y = pos.y-7, z = pos.z-6},
@ -245,6 +245,7 @@ function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill)
util.reconstruct(pos, {x = pos.x+12, y = pos.y+12, z = pos.z+12})
util.fixlight(pos, {x = pos.x+12, y = pos.y+12, z = pos.z+12})
util.nodefunc(
pos,
{x = pos.x+12, y = pos.y+12, z = pos.z+12},
@ -252,6 +253,7 @@ function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill)
function(pos)
goodies.fill(pos, chunktype, pr, "main", 3)
end, true)
util.nodefunc(
pos,
{x = pos.x+12, y = pos.y+12, z = pos.z+12},
@ -272,10 +274,10 @@ function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill)
"village:entity_spawner",
function(pos)
minetest.remove_node(pos)
end)
end)
return
end
local ent_spawns = {}
util.nodefunc(
@ -339,7 +341,7 @@ function village.spawn_road(pos, houses, built, roads, depth, pr)
built[hnp] = true
if depth <= 0 or pr:next(1, 8) < 6 then
houses[hnp] = {pos = nextpos, front = pos}
local structure = util.choice_element(village.chunktypes, pr)
village.spawn_chunk(nextpos, orient, {}, pr, structure)
else
@ -354,7 +356,7 @@ function village.spawn_village(pos, pr)
local name = village.name.generate(pr)
local depth = pr:next(village.min_size, village.max_size)
village.villages[village.get_id(name, pos)] = {
name = name,
pos = pos,
@ -444,7 +446,7 @@ function village.spawn_village(pos, pr)
pr,
"lamppost",
true
)
)
end
end
end
@ -452,5 +454,5 @@ end
minetest.after(
0,
function()
village.load_villages()
end)
village.load_villages()
end)

View File

@ -6,7 +6,7 @@ minetest.register_node(
is_ground_content = false,
groups = {dig_immediate = 2},
sounds = default.node_sound_wood_defaults()
})
})
minetest.register_node(
"village:grassland_village",
@ -16,7 +16,7 @@ minetest.register_node(
is_ground_content = false,
groups = {dig_immediate = 2},
sounds = default.node_sound_wood_defaults()
})
})
minetest.register_node(
"village:grassland_village_mg",
@ -33,7 +33,7 @@ minetest.register_node(
air_equivalent = true,
drop = "",
groups = {not_in_craftingguide = 1},
})
})
minetest.register_abm(
{
@ -41,24 +41,32 @@ minetest.register_abm(
interval = 1,
chance = 1,
action = function(pos, node)
minetest.remove_node(pos)
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
local nearest = village.get_nearest_village(pos)
if nearest.dist > village.min_spawn_dist then
print("Spawning a (Mapgen)Grassland village at "..dump(pos))
minetest.after(3.0, function() village.spawn_village(pos, pr) end) -- a short delay to (hopefully)ensure that the surrounding terrain is generated
else
print("Cannot spawn village, too near another village")
end
end
else
print("Spawning a Grassland village at "..dump(pos))
village.spawn_village(pos, pr)
end
end
})
minetest.remove_node(pos)
if minetest.setting_get_bool("mapgen_disable_villages")
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
local nearest = village.get_nearest_village(pos)
if nearest.dist > village.min_spawn_dist then
minetest.log("Spawning a (Mapgen)Grassland village at "..dump(pos))
-- a short delay to (hopefully) ensure that the surrounding terrain is generated
minetest.after(3.0, function() village.spawn_village(pos, pr) 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
})
minetest.register_decoration(
{
@ -70,4 +78,4 @@ minetest.register_decoration(
decoration = {"village:grassland_village_mg"},
y_min = 1,
y_max = 1000,
})
})

View File

@ -38,4 +38,4 @@ function village.name.generate(pr)
village.name.used[name] = true
return name
end
end