From b58422a584d18689fad289bd4721cb8823645dee Mon Sep 17 00:00:00 2001 From: cora Date: Thu, 19 May 2022 21:36:11 +0200 Subject: [PATCH] write villager id into bed nodemeta --- mods/ENTITIES/mobs_mc/villager.lua | 8 ++++---- mods/MAPGEN/mcl_villages/init.lua | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 492e558dd..72dc8ad7e 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -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 diff --git a/mods/MAPGEN/mcl_villages/init.lua b/mods/MAPGEN/mcl_villages/init.lua index 34a355f55..4bea6ab3c 100644 --- a/mods/MAPGEN/mcl_villages/init.lua +++ b/mods/MAPGEN/mcl_villages/init.lua @@ -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 --