write villager id into bed nodemeta

This commit is contained in:
cora 2022-05-19 21:36:11 +02:00
parent 3ff4ea576d
commit b58422a584
2 changed files with 16 additions and 9 deletions

View File

@ -573,7 +573,7 @@ end
local function go_home(entity)
entity.state = "go_home"
local b=entity.bed
local b=entity._bed
if not b then return end
mobs:gopath(entity,b,function(entity,b)
if vector.distance(entity.object:get_pos(),b) < 2 then
@ -582,7 +582,7 @@ local function go_home(entity)
entity.object:set_pos(b)
local n=minetest.get_node(b)
if n and n.name ~= "mcl_beds:bed_red_bottom" then
entity.bed=nil --the stormtroopers have killed uncle owen
entity._bed=nil --the stormtroopers have killed uncle owen
return false
end
return true
@ -1239,7 +1239,7 @@ mobs:register_mob("mobs_mc:villager", {
fear_height = 4,
jump = true,
walk_chance = DEFAULT_WALK_CHANCE,
bed = nil,
_bed = nil,
_id = nil,
_profession = "unemployed",
look_at_player = true,
@ -1331,7 +1331,7 @@ mobs:register_mob("mobs_mc:villager", {
self.walk_chance = DEFAULT_WALK_CHANCE
self.jump = true
end
if self.bed and ( self.state ~= "go_home" and vector.distance(self.object:get_pos(),self.bed) > 50 ) then
if self._bed and ( self.state ~= "go_home" and vector.distance(self.object:get_pos(),self._bed) > 50 ) then
go_home(self)
end
if self._profession == "unemployed" then

View File

@ -53,14 +53,21 @@ 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
local m = minetest.get_meta(bed)
if m:get_string("villager") == "" then
local v=minetest.add_entity(bed,"mobs_mc:villager")
if v then
local l=v:get_luaentity()
l._bed = bed
m:set_string("villager",l._id)
end
end
end
local p = minetest.find_node_near(minp,50,"mcl_core:grass_path")
minetest.add_entity(p,"mobs_mc:iron_golem")
if p then
minetest.add_entity(p,"mobs_mc:iron_golem")
end
end
--