1
0
Fork 0

Spawn villagers on villagegen, stay in village

This spawns a villager per bed on village gen and saves the bed
position in the entity. If it moves too far from the village
it gets teleported (for now) back.
This commit is contained in:
cora 2022-05-08 23:19:37 +02:00 committed by Gitea
parent 7c263c6a18
commit 46dbf8c0ab
2 changed files with 18 additions and 0 deletions

View File

@ -1029,6 +1029,9 @@ mobs:register_mob("mobs_mc:villager", {
_player_scan_timer = 0, _player_scan_timer = 0,
_trading_players = {}, -- list of playernames currently trading with villager (open formspec) _trading_players = {}, -- list of playernames currently trading with villager (open formspec)
do_custom = function(self, dtime) do_custom = function(self, dtime)
if self.bed and vector.distance(self.object:get_pos(),self.bed) > 50 then
self.object:set_pos(self.bed)
end
-- Stand still if player is nearby. -- Stand still if player is nearby.
if not self._player_scan_timer then if not self._player_scan_timer then
self._player_scan_timer = 0 self._player_scan_timer = 0

View File

@ -48,6 +48,17 @@ if minetest.get_modpath("mobs_mc") then
end end
--]] --]]
local function spawn_villagers(minp,maxp)
local beds=minetest.find_nodes_in_area(minp,maxp,{"mcl_beds:bed_red_bottom"})
for _,bed in pairs(beds) do
minetest.get_meta(bed):set_string("villagebed","true")
local v=minetest.add_entity(bed,"mobs_mc:villager")
if v then
v:get_luaentity().bed = bed
end
end
end
-- --
-- on map generation, try to build a settlement -- on map generation, try to build a settlement
-- --
@ -66,6 +77,10 @@ local function build_a_settlement(minp, maxp, blockseed)
-- evaluate settlement_info and place schematics -- evaluate settlement_info and place schematics
settlements.place_schematics(settlement_info, pr) settlements.place_schematics(settlement_info, pr)
minetest.after(20,function()
spawn_villagers(minp,maxp)
end) --give the village some time to fully generate
end end
local function ecb_village(blockpos, action, calls_remaining, param) local function ecb_village(blockpos, action, calls_remaining, param)