Texture now changes when villager loses job.

This commit is contained in:
ancientmarinerdev 2022-10-23 01:12:19 +01:00
parent a8b336381d
commit e1b685429d
2 changed files with 56 additions and 22 deletions

View File

@ -3128,7 +3128,10 @@ local gopath_last = os.time()
function mcl_mobs:gopath(self,target,callback_arrived) function mcl_mobs:gopath(self,target,callback_arrived)
if self.state == "gowp" then mcl_log("Already set as gowp, don't set another path until done.") return end if self.state == "gowp" then mcl_log("Already set as gowp, don't set another path until done.") return end
if os.time() - gopath_last < 15 then return end if os.time() - gopath_last < 15 then
mcl_log("Not ready to path yet")
return
end
gopath_last = os.time() gopath_last = os.time()
self.order = nil self.order = nil
@ -3143,14 +3146,26 @@ function mcl_mobs:gopath(self,target,callback_arrived)
--mcl_log("gowp. no wp. Look for door") --mcl_log("gowp. no wp. Look for door")
local d = minetest.find_node_near(target,16,{"group:door"}) local d = minetest.find_node_near(target,16,{"group:door"})
if d then if d then
--mcl_log("Found a door near")
for _,v in pairs(plane_adjacents) do for _,v in pairs(plane_adjacents) do
local pos = vector.add(d,v) local pos = vector.add(d,v)
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
if n.name == "air" then if n.name == "air" then
wp = minetest.find_path(p,pos,150,1,4) wp = minetest.find_path(p,pos,150,1,4)
if wp then break end if wp then
--mcl_log("Found a path to next to door".. minetest.pos_to_string(pos))
break
else
--mcl_log("This block next to door doesn't work.")
end
else
--mcl_log("Block is not air, it is: ".. n.name)
end end
end end
else
mcl_log("No door found")
end end
end end
if wp and #wp > 0 then if wp and #wp > 0 then

View File

@ -550,6 +550,11 @@ end
local function get_badge_textures(self) local function get_badge_textures(self)
local t = professions[self._profession].texture local t = professions[self._profession].texture
if self._profession == "unemployed" then
t = professions[self._profession].textures -- ideally both scenarios should be textures with a list containing 1 or multiple
--mcl_log("t: " .. tostring(t))
end
if self._profession == "unemployed" or self._profession == "nitwit" then return t end if self._profession == "unemployed" or self._profession == "nitwit" then return t end
local tier = self._max_trade_tier or 1 local tier = self._max_trade_tier or 1
return { return {
@ -670,8 +675,8 @@ local function take_bed (entity)
for _,n in pairs(nn) do for _,n in pairs(nn) do
local m=minetest.get_meta(n) local m=minetest.get_meta(n)
mcl_log("Bed owner: ".. m:get_string("villager")) --mcl_log("Bed owner: ".. m:get_string("villager"))
if m:get_string("villager") == "" and not entity.state == "gowp" then if m:get_string("villager") == "" and not (entity.state == "gowp") then
mcl_log("Can we path to bed: "..minetest.pos_to_string(n) ) mcl_log("Can we path to bed: "..minetest.pos_to_string(n) )
local gp = mcl_mobs:gopath(entity,n,function(self) local gp = mcl_mobs:gopath(entity,n,function(self)
if self then if self then
@ -690,7 +695,7 @@ local function take_bed (entity)
mcl_log("Awww. I can't find my bed.") mcl_log("Awww. I can't find my bed.")
end end
else else
mcl_log("Currently gowp, or it's taken.") mcl_log("Currently gowp, or it's taken: ".. m:get_string("villager"))
end end
end end
end end
@ -742,6 +747,12 @@ end
local function has_traded (self) local function has_traded (self)
--mcl_log("Checking name: " .. self._trades) --mcl_log("Checking name: " .. self._trades)
if not self._trades then
mcl_log("No trades set. has_traded is false")
return false
end
local cur_trades_tab = minetest.deserialize(self._trades) local cur_trades_tab = minetest.deserialize(self._trades)
if cur_trades_tab and type(cur_trades_tab) == "table" then if cur_trades_tab and type(cur_trades_tab) == "table" then
@ -765,7 +776,7 @@ end
local function unlock_trades (self) local function unlock_trades (self)
if self then if self then
mcl_log("We should now try to unlock trades") --mcl_log("We should now try to unlock trades")
else else
mcl_log("Missing self") mcl_log("Missing self")
end end
@ -788,11 +799,10 @@ local function employ(self,jobsite_pos)
m:set_string("villager",self._id) m:set_string("villager",self._id)
self._jobsite = jobsite_pos self._jobsite = jobsite_pos
if not self.traded then if not has_traded(self) then
self._profession=p self._profession=p
set_textures(self) set_textures(self)
end end
return true return true
else else
mcl_log("I can not steal someone's job!") mcl_log("I can not steal someone's job!")
@ -801,15 +811,19 @@ end
local function look_for_job(self, requested_jobsites) local function look_for_job(self, requested_jobsites)
if self.last_jobhunt and os.time() - self.last_jobhunt < 40 then return end
self.last_jobhunt = os.time() + math.random(0,30) --if self.last_jobhunt and os.time() - self.last_jobhunt < 15 then
-- mcl_log("Is time less than 40?" .. tostring(os.time() - self.last_jobhunt))
-- return
--end
--self.last_jobhunt = os.time() + math.random(0,30)
mcl_log("Looking for jobs") mcl_log("Looking for jobs")
local looking_for_type = jobsites local looking_for_type = jobsites
if requested_jobsites then if requested_jobsites then
mcl_log("Looking for jobs of my type") mcl_log("Looking for jobs of my type: " .. tostring(requested_jobsites))
local looking_for_type = requested_jobsites looking_for_type = requested_jobsites
else else
mcl_log("Looking for any job type") mcl_log("Looking for any job type")
end end
@ -839,7 +853,7 @@ local function look_for_job(self, requested_jobsites)
end end
return n return n
else else
mcl_log("We could not path to block") mcl_log("We could not path to block or it's not ready to path yet.")
end end
end end
end end
@ -899,16 +913,21 @@ local function retrieve_my_jobsite (self)
end end
local function validate_jobsite(self) local function validate_jobsite(self)
if self._profession == "unemployed" then return false end
if not retrieve_my_jobsite (self) then if not retrieve_my_jobsite (self) then
if not self._traded then self._jobsite = nil
if self.order == WORK then
self.order = nil
end
if not has_traded(self) then
mcl_log("Cannot retrieve my jobsite. I am now unemployed.") mcl_log("Cannot retrieve my jobsite. I am now unemployed.")
self._jobsite = nil
self._profession = "unemployed" self._profession = "unemployed"
self._trades = nil self._trades = nil
set_textures(self) set_textures(self)
if self.order == WORK then else
self.order = nil mcl_log("Cannot retrieve my jobsite but I've traded so only remove jobsite.")
end
end end
return false return false
else else
@ -931,12 +950,12 @@ local function do_work (self)
if self and jobsite2 and self._jobsite then if self and jobsite2 and self._jobsite then
mcl_log("Villager: ".. minetest.pos_to_string(self.object:get_pos()) .. ", jobsite: " .. minetest.pos_to_string(self._jobsite)) --mcl_log("Villager: ".. minetest.pos_to_string(self.object:get_pos()) .. ", jobsite: " .. minetest.pos_to_string(self._jobsite))
if vector.distance(self.object:get_pos(),self._jobsite) < 2 then if vector.distance(self.object:get_pos(),self._jobsite) < 2 then
mcl_log("Made it to work ok!") mcl_log("Made it to work ok!")
if not (self.state == "gowp") then if not (self.state == "gowp") then
mcl_log("Setting order to work.") --mcl_log("Setting order to work.")
self.order = WORK self.order = WORK
else else
mcl_log("Not gowp. What is it: " .. self.state) mcl_log("Not gowp. What is it: " .. self.state)
@ -1728,7 +1747,7 @@ mcl_mobs:register_mob("mobs_mc:villager", {
go_home(self, false) go_home(self, false)
return return
elseif mcl_beds.is_night() or (weather_mod and mcl_weather.get_weather() == "thunder") then elseif mcl_beds.is_night() or (weather_mod and mcl_weather.get_weather() == "thunder") then
mcl_log("It's night or thunderstorm. Better get to bed ") mcl_log("It's night or thunderstorm. Better get to bed. Weather is: " .. mcl_weather.get_weather())
go_home(self, true) go_home(self, true)
return return
end end