From 04cac7156e0e1204cf962fe5b059f729059e3552 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Thu, 27 Oct 2022 22:27:19 +0100 Subject: [PATCH 01/11] Villagers gather at lunch time, reset trade when they get to work. --- mods/ENTITIES/mobs_mc/villager.lua | 281 +++++++++++++++++------------ 1 file changed, 166 insertions(+), 115 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 336221a17..a80c4e78f 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -506,6 +506,7 @@ local professions = { local WORK = "work" local SLEEP = "sleep" +local GATHERING = "gathering" local profession_names = {} for id, _ in pairs(professions) do @@ -583,14 +584,16 @@ function get_activity(tod) local work_start = 8500 local work_end = 16500 - local activity = nil - if (tod > work_start and tod < lunch_start) or (tod > lunch_end and tod < work_end) then + if weather_mod and mcl_weather.get_weather() == "thunder" then + mcl_log("Better get to bed. Weather is: " .. mcl_weather.get_weather()) + activity = SLEEP + elseif (tod > work_start and tod < lunch_start) or (tod > lunch_end and tod < work_end) then activity = WORK elseif mcl_beds.is_night() then activity = SLEEP elseif tod > lunch_start and tod < lunch_end then - activity = "lunch" + activity = GATHERING else activity = "chill" end @@ -599,8 +602,29 @@ function get_activity(tod) end +local function check_bed (entity) + local b = entity._bed + if not b then + --minetest.log("No bed set on villager") + return false + end + + local n = minetest.get_node(b) + if n and n.name ~= "mcl_beds:bed_red_bottom" then + mcl_log("Where did my bed go?!") + entity._bed = nil --the stormtroopers have killed uncle owen + return false + else + return true + end +end local function go_home(entity, sleep) + + if not check_bed (entity) then + mcl_log("Cannot find bed, so cannot go home") + end + local b = entity._bed if not b then return @@ -647,22 +671,7 @@ local function go_home(entity, sleep) end end -local function check_bed (entity) - local b = entity._bed - if not b then - --minetest.log("No bed set on villager") - return false - end - local n = minetest.get_node(b) - if n and n.name ~= "mcl_beds:bed_red_bottom" then - mcl_log("Where did my bed go?!") - entity._bed = nil --the stormtroopers have killed uncle owen - return false - else - return true - end -end local function take_bed (entity) if not entity then return end @@ -742,25 +751,30 @@ local function check_summon(self,dtime) self._summon_timer = self._summon_timer + dtime end -local function has_traded (self) - --mcl_log("Checking name: " .. self._trades) +local function debug_trades(self) + mcl_log("Start debug trades") + if not self or not self._trades then return end + local trades = minetest.deserialize(self._trades) + if trades and type(trades) == "table" then + for trader, trade in pairs(trades) do + --mcl_log("Current record: ".. tostring(trader)) + for tr3, tr4 in pairs (trade) do + mcl_log("Key: ".. tostring(tr3)) + mcl_log("Value: ".. tostring(tr4)) + end + end + end + mcl_log("End debug trades") +end +local function has_traded (self) 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) - if cur_trades_tab and type(cur_trades_tab) == "table" then for trader, trades in pairs(cur_trades_tab) do - --mcl_log("Current record: ".. tostring(trader)) - --for tr3, tr4 in pairs (tab_val) do - --mcl_log("Key: ".. tostring(tr3)) - --mcl_log("Value: ".. tostring(tr4)) - --end - --mcl_log("traded once: ".. tostring(trades.traded_once)) - if trades.traded_once then mcl_log("Villager has traded before. Returning true") return true @@ -772,10 +786,32 @@ local function has_traded (self) end local function unlock_trades (self) - if self then - --mcl_log("We should now try to unlock trades") - else - mcl_log("Missing self") + if not self._trades then + mcl_log("No trades set. has_traded is false") + return false + end + mcl_log("Unlocking trades") + local has_unlocked = false + + local trades = minetest.deserialize(self._trades) + if trades and type(trades) == "table" then + for trader, trade in pairs(trades) do + local trade_tier_too_high = trade.tier > self._max_trade_tier + mcl_log("Max trade tier of villager: ".. tostring(self._max_trade_tier)) + mcl_log("current trade.tier: ".. tostring(trade.tier)) + mcl_log("trade tier too high: ".. tostring(trade_tier_too_high)) + mcl_log("locked: ".. tostring(trade["locked"])) + if not trade_tier_too_high then + if trade["locked"] == true then + trade.locked = false + has_unlocked = true + mcl_log("Villager has a locked trade. Unlocking") + end + end + end + if has_unlocked then + self._trades = minetest.serialize(trades) + end end end @@ -808,13 +844,6 @@ end local function look_for_job(self, requested_jobsites) - - --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") local looking_for_type = jobsites @@ -828,6 +857,7 @@ local function look_for_job(self, requested_jobsites) local p = self.object:get_pos() local nn = minetest.find_nodes_in_area(vector.offset(p,-48,-48,-48),vector.offset(p,48,48,48), looking_for_type) + --Ideally should check for closest available. It'll make pathing easier. for _,n in pairs(nn) do local m = minetest.get_meta(n) --mcl_log("Job owner: ".. m:get_string("villager")) @@ -859,31 +889,21 @@ local function look_for_job(self, requested_jobsites) end + local function get_a_job(self) + if self.order == WORK then self.order = nil end + mcl_log("I'm unemployed or lost my job block and have traded. Can I get a job?") - --self.order = JOB_HUNTING local requested_jobsites = jobsites if has_traded (self) then mcl_log("Has traded so look for job of my type") requested_jobsites = populate_jobsites(self._profession) -- Only pass in my jobsite to two functions here - else - mcl_log("Has not traded") end - local p = self.object:get_pos() - local n = minetest.find_node_near(p,1,requested_jobsites) - - --Ideally should check for closest available. It'll make pathing easier. - --local n = look_for_job(self) - - if not n then - --mcl_log("Job hunt failed. Could not find block I have walked to") - end - if n and employ(self,n) then return true end if self.state ~= PATHFINDING then @@ -894,17 +914,16 @@ end local function retrieve_my_jobsite (self) if not self or not self._jobsite then - --mcl_log("find_jobsite. Invalid params") + mcl_log("find_jobsite. Invalid params. Should not happen") return end - local n = mcl_vars.get_node(self._jobsite) local m = minetest.get_meta(self._jobsite) if m:get_string("villager") == self._id then --mcl_log("find_jobsite. is my job.") return n else - --mcl_log("find_jobsite. Not my job") + mcl_log("This isn't my jobsite") end return end @@ -932,10 +951,12 @@ local function validate_jobsite(self) end end - - local function do_work (self) - if self.child then return end + debug_trades(self) + if self.child or self.order == WORK then + mcl_log("A child or already working so don't send to work") + return + end --mcl_log("Time for work") -- Don't try if looking_for_work, or gowp possibly @@ -946,29 +967,23 @@ local function do_work (self) local jobsite = self._jobsite if self and jobsite2 and self._jobsite then + local distance_to_jobsite = vector.distance(self.object:get_pos(),self._jobsite) + --mcl_log("Villager: ".. minetest.pos_to_string(self.object:get_pos()) .. ", jobsite: " .. minetest.pos_to_string(self._jobsite) .. ", distance to jobsite: ".. distance_to_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 - --mcl_log("Made it to work ok!") - + if distance_to_jobsite < 2 then if not (self.state == PATHFINDING) then - --mcl_log("Setting order to work.") + mcl_log("Setting order to work.") self.order = WORK + unlock_trades(self) else - mcl_log("Not gowp. What is it: " .. self.state) + --mcl_log("Still pathfinding.") end - -- Once we arrive at job block, we should unlock trades - unlock_trades(self) - - --self.state = "stand" - --self.object:set_velocity({x = 0, y = 0, z = 0}) else mcl_log("Not at job block. Need to commute.") if self.order == WORK then self.order = nil return end - --self.state = "go_to_work" mcl_mobs:gopath(self, jobsite, function(self,jobsite) if not self then --mcl_log("missing self. not good") @@ -984,19 +999,90 @@ local function do_work (self) else --mcl_log("Need to walk to work. Not sure we can get here.") end - end) end end - elseif self._profession == "unemployed" then - get_a_job(self) - elseif has_traded(self) then - mcl_log("My job site is invalid or gone. I cannot work.") - if self.order == WORK then self.order = nil end + elseif self._profession == "unemployed" or has_traded(self) then get_a_job(self) end end +local function go_to_town_bell(self) + if self.order == GATHERING then + mcl_log("Already gathering") + return + else + mcl_log("Current order" .. self.order) + end + mcl_log("Go to town bell") + + local looking_for_type={} + table.insert(looking_for_type, "mcl_bells:bell") + + local p = self.object:get_pos() + local nn = minetest.find_nodes_in_area(vector.offset(p,-48,-48,-48),vector.offset(p,48,48,48), looking_for_type) + + --Ideally should check for closest available. It'll make pathing easier. + for _,n in pairs(nn) do + mcl_log("Found bell") + + local gp = mcl_mobs:gopath(self,n,function(self) + if self then + self.order = GATHERING + mcl_log("Callback has a self") + end + mcl_log("Arrived at block callback") + end) + + if gp then + if n then + mcl_log("We can path to this block.. " .. tostring(n)) + end + return n + else + mcl_log("We could not path to block or it's not ready to path yet.") + end + + end + + return nil +end + +local function do_activity (self) + -- Maybe just check we're pathfinding first? + + if not self._bed then + --mcl_log("Villager has no bed. Currently at location: "..minetest.pos_to_string(self.object:get_pos())) + take_bed (self) + end + + -- Only check in day or during thunderstorm but wandered_too_far code won't work + local wandered_too_far = ( self.state ~= PATHFINDING ) and (vector.distance(self.object:get_pos(),self._bed) > 50 ) + + if wandered_too_far then + --mcl_log("Wandered too far! Return home ") + go_home(self, false) + elseif get_activity() == SLEEP then + go_home(self, true) + elseif get_activity() == WORK then + do_work(self) + elseif get_activity() == GATHERING then + go_to_town_bell(self) + else + -- gossip at town bell or stroll around + mcl_log("No order, so remove it.") + self.order = nil + end + + -- Daytime is work and play time + if not mcl_beds.is_night() then + if self.order == SLEEP then self.order = nil end + else + if self.order == WORK then self.order = nil end + end + +end + local function update_max_tradenum(self) if not self._trades then return @@ -1663,9 +1749,9 @@ mcl_mobs:register_mob("mobs_mc:villager", { end -- Don't do at night. Go to bed? Maybe do_activity needs it's own method if validate_jobsite(self) then - mcl_mobs:gopath(self,self._jobsite,function() + -- mcl_mobs:gopath(self,self._jobsite,function() --minetest.log("arrived at jobsite") - end) + -- end) else self.state = "stand" -- cancel gowp in case it has messed up self.order = nil -- cancel work if working @@ -1739,42 +1825,7 @@ mcl_mobs:register_mob("mobs_mc:villager", { self.jump = true end - if not self._bed then - --mcl_log("Villager has no bed. Currently at location: "..minetest.pos_to_string(self.object:get_pos())) - take_bed (self) - end - - -- Only check in day or during thunderstorm but wandered_too_far code won't work - if check_bed (self) then - --self.state ~= "go_home" - local wandered_too_far = ( self.state ~= PATHFINDING ) and (vector.distance(self.object:get_pos(),self._bed) > 50 ) - - --if wandered_too_far then minetest.log("Wandered too far! Return home ") end - if wandered_too_far then - go_home(self, false) - return - 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. Weather is: " .. mcl_weather.get_weather()) - go_home(self, true) - return - end - else - --mcl_log("check bed failed ") - end - - -- Daytime is work and play time - if not mcl_beds.is_night() then - if self.order == SLEEP then self.order = nil end - - if get_activity() == WORK then - do_work(self) - else - -- gossip at town bell or stroll around - self.order = nil - end - else - if self.order == WORK then self.order = nil end - end + do_activity (self) end end, From bf491c35a12f5731e63dd37955daa06f4b705c9e Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Fri, 28 Oct 2022 00:05:03 +0100 Subject: [PATCH 02/11] Fix bug --- mods/ENTITIES/mcl_mobs/api.lua | 7 +++---- mods/ENTITIES/mobs_mc/villager.lua | 8 ++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 5742ebb85..ad390b9ff 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2614,8 +2614,7 @@ local function check_gowp(self,dtime) elseif self.current_target then -- No waypoints left, but have current target. Potentially last waypoint to go to. - mcl_log("self.current_target: ".. minetest.pos_to_string(self.current_target)) - mcl_log("pos: ".. minetest.pos_to_string(p)) + mcl_log("pos: ".. minetest.pos_to_string(p) .. "self.current_target: ".. minetest.pos_to_string(self.current_target)) go_to_pos(self,self.current_target) -- Do i just delete current_target, and return so we can find final path. else @@ -2644,10 +2643,10 @@ local function check_gowp(self,dtime) -- 1.6 is good. is 1.9 better? It could fail less, but will it path to door when it isn't after door if distance_to_cur_targ > 1.9 then - mcl_log("no LOS to target: ".. minetest.pos_to_string(self.current_target)) + mcl_log("not close to current target: ".. minetest.pos_to_string(self.current_target)) go_to_pos(self,self._current_target) else - mcl_log("Let's go to target: ".. minetest.pos_to_string(self.current_target)) + mcl_log("close to current target: ".. minetest.pos_to_string(self.current_target)) self.current_target = nil --go_to_pos(self,self._target) self.waypoints=minetest.find_path(updated_p,self._target,150,1,4) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index a80c4e78f..f5bb599ea 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -952,7 +952,7 @@ local function validate_jobsite(self) end local function do_work (self) - debug_trades(self) + --debug_trades(self) if self.child or self.order == WORK then mcl_log("A child or already working so don't send to work") return @@ -1057,7 +1057,11 @@ local function do_activity (self) end -- Only check in day or during thunderstorm but wandered_too_far code won't work - local wandered_too_far = ( self.state ~= PATHFINDING ) and (vector.distance(self.object:get_pos(),self._bed) > 50 ) + local wandered_too_far = false + if check_bed (self) then + wandered_too_far = ( self.state ~= PATHFINDING ) and (vector.distance(self.object:get_pos(),self._bed) > 50 ) + end + if wandered_too_far then --mcl_log("Wandered too far! Return home ") From cabe2994562d970208f93a60857090b831b0338d Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Fri, 28 Oct 2022 22:02:36 +0100 Subject: [PATCH 03/11] Villager fixes --- mods/ENTITIES/mobs_mc/villager.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index f5bb599ea..c65d63938 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -953,8 +953,8 @@ end local function do_work (self) --debug_trades(self) - if self.child or self.order == WORK then - mcl_log("A child or already working so don't send to work") + if self.child then + mcl_log("A child so don't send to work") return end --mcl_log("Time for work") @@ -971,7 +971,7 @@ local function do_work (self) --mcl_log("Villager: ".. minetest.pos_to_string(self.object:get_pos()) .. ", jobsite: " .. minetest.pos_to_string(self._jobsite) .. ", distance to jobsite: ".. distance_to_jobsite) if distance_to_jobsite < 2 then - if not (self.state == PATHFINDING) then + if self.state ~= PATHFINDING and self.order ~= WORK then mcl_log("Setting order to work.") self.order = WORK unlock_trades(self) @@ -1752,10 +1752,10 @@ mcl_mobs:register_mob("mobs_mc:villager", { self.attack = nil end -- Don't do at night. Go to bed? Maybe do_activity needs it's own method - if validate_jobsite(self) then - -- mcl_mobs:gopath(self,self._jobsite,function() - --minetest.log("arrived at jobsite") - -- end) + if validate_jobsite(self) and not self.order == WORK then + --mcl_mobs:gopath(self,self._jobsite,function() + -- minetest.log("sent to jobsite") + --end) else self.state = "stand" -- cancel gowp in case it has messed up self.order = nil -- cancel work if working @@ -1766,11 +1766,13 @@ mcl_mobs:register_mob("mobs_mc:villager", { local name = clicker:get_player_name() self._trading_players[name] = true - if self._trades == nil then + if self._trades == nil or self._trades == false then + minetest.log("Trades is nil so init") init_trades(self) end update_max_tradenum(self) if self._trades == false then + minetest.log("Trades is false. no right click op") -- Villager has no trades, rightclick is a no-op return end From f9ec402b29e7ddb172cb51e57686eed1a3cd21bb Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Fri, 28 Oct 2022 23:53:09 +0100 Subject: [PATCH 04/11] Only to door if we can get from door to target --- mods/ENTITIES/mcl_mobs/api.lua | 124 ++++++++++++++++++++++++--------- 1 file changed, 92 insertions(+), 32 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index ad390b9ff..98db5e418 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2582,7 +2582,7 @@ local function check_gowp(self,dtime) -- arrived at location, finish gowp local distance_to_targ = vector.distance(p,self._target) - mcl_log("Distance to targ: ".. tostring(distance_to_targ)) + --mcl_log("Distance to targ: ".. tostring(distance_to_targ)) if distance_to_targ < 2 then mcl_log("Arrived at _target") self.waypoints = nil @@ -2597,24 +2597,26 @@ local function check_gowp(self,dtime) end -- More pathing to be done - if self.waypoints and #self.waypoints > 0 and ( not self.current_target or vector.distance(p,self.current_target) < 2 ) then + + local distance_to_current_target = 50 + if self.current_target then + distance_to_current_target = vector.distance(p,self.current_target) + --mcl_log("current target:".. minetest.pos_to_string(self.current_target) .. ", Current target distance: ".. tostring(distance_to_current_target)) + end + + -- 1.6 is good but fails more than it should. Maybe 1.7 + if self.waypoints and #self.waypoints > 0 and ( not self.current_target or distance_to_current_target < 1.7 ) then -- We have waypoints, and no current target, or we're at it. We need a new current_target. - if not self.current_target then - for i, j in pairs (self.waypoints) do - mcl_log("Val: ".. tostring(j)) - end - end - self.current_target = table.remove(self.waypoints, 1) - mcl_log("current target:".. minetest.pos_to_string(self.current_target) ) + mcl_log("There. current target:".. minetest.pos_to_string(self.current_target) .. ". Distance: " .. distance_to_current_target) --mcl_log("type:".. type(self.current_target) ) go_to_pos(self,self.current_target) return elseif self.current_target then -- No waypoints left, but have current target. Potentially last waypoint to go to. - mcl_log("pos: ".. minetest.pos_to_string(p) .. "self.current_target: ".. minetest.pos_to_string(self.current_target)) + mcl_log("Not there... pos: ".. minetest.pos_to_string(p) .. "self.current_target: ".. minetest.pos_to_string(self.current_target) .. ". Distance: ".. distance_to_current_target) go_to_pos(self,self.current_target) -- Do i just delete current_target, and return so we can find final path. else @@ -2625,9 +2627,10 @@ local function check_gowp(self,dtime) local final_wp = minetest.find_path(p,self._target,150,1,4) if final_wp then mcl_log("We might be able to get to target here.") - self.waypoints = final_wp + -- self.waypoints = final_wp --go_to_pos(self,self._target) else + -- Abandon route? mcl_log("Cannot plot final route to target") end end @@ -2649,7 +2652,9 @@ local function check_gowp(self,dtime) mcl_log("close to current target: ".. minetest.pos_to_string(self.current_target)) self.current_target = nil --go_to_pos(self,self._target) - self.waypoints=minetest.find_path(updated_p,self._target,150,1,4) + + --self.waypoints=minetest.find_path(updated_p,self._target,150,1,4) + --if not self.waypoints then --mcl_log("Give up ") --self.state = "walk" @@ -3257,6 +3262,28 @@ local do_states = function(self, dtime) end end +function output_table (wp) + if not wp then return end + mcl_log("wp items: ".. tostring(#wp)) + for a,b in pairs(wp) do + mcl_log(a.. ": ".. tostring(b)) + end +end + +function append_paths (wp1, wp2) + mcl_log("Start append") + if not wp1 or not wp2 then + mcl_log("Cannot append wp's") + return + end + output_table(wp1) + output_table(wp2) + for _,a in pairs (wp2) do + table.insert(wp1, a) + end + mcl_log("End append") +end + local plane_adjacents = { vector.new(1,0,0), vector.new(-1,0,0), @@ -3264,41 +3291,45 @@ local plane_adjacents = { vector.new(0,0,-1), } +-- This function is used to see if we can path. We could use to check a route, rather than making people move. +local function calculate_path_through_door (p, t, target) + -- target is the same as t, just 1 square difference. Maybe we don't need target -local gopath_last = os.time() -function mcl_mobs:gopath(self,target,callback_arrived) - if self.state == PATHFINDING then mcl_log("Already set as gowp, don't set another path until done.") return end + mcl_log("Plot route from mob: " .. minetest.pos_to_string(p) .. ", to target: " .. minetest.pos_to_string(t)) - if os.time() - gopath_last < 15 then - mcl_log("Not ready to path yet") - return - end - gopath_last = os.time() - - self.order = nil - - mcl_log("gowp target: " .. minetest.pos_to_string(target)) - local p = self.object:get_pos() - local t = vector.offset(target,0,1,0) local wp = minetest.find_path(p,t,150,1,4) --Path to door first if not wp then --mcl_log("gowp. no wp. Look for door") - local d = minetest.find_node_near(target,16,{"group:door"}) - if d then + + local cur_door_pos = minetest.find_node_near(target,16,{"group:door"}) + if cur_door_pos then + --mcl_log("Found a door near") for _,v in pairs(plane_adjacents) do - local pos = vector.add(d,v) + local pos = vector.add(cur_door_pos,v) local n = minetest.get_node(pos) if n.name == "air" then wp = minetest.find_path(p,pos,150,1,4) if wp then mcl_log("Found a path to next to door".. minetest.pos_to_string(pos)) - local other_side_of_door = vector.add(d,-v) + local other_side_of_door = vector.add(cur_door_pos,-v) mcl_log("Opposite is: ".. minetest.pos_to_string(other_side_of_door)) - table.insert(wp, other_side_of_door) + --table.insert(wp, other_side_of_door) + + + + local wp_otherside_door_to_target = minetest.find_path(other_side_of_door,t,150,1,4) + if wp_otherside_door_to_target and #wp_otherside_door_to_target > 0 then + table.insert(wp, cur_door_pos) + append_paths (wp, wp_otherside_door_to_target) + mcl_log("We have a path from outside door to target") + return wp + else + mcl_log("We cannot path from outside door to target") + end break else @@ -3312,11 +3343,40 @@ function mcl_mobs:gopath(self,target,callback_arrived) else mcl_log("No door found") end + else + mcl_log("We have a direct route") + return wp end +end + +local gopath_last = os.time() +function mcl_mobs:gopath(self,target,callback_arrived) + if self.state == PATHFINDING then mcl_log("Already set as gowp, don't set another path until done.") return end + + if os.time() - gopath_last < 5 then + mcl_log("Not ready to path yet") + return + end + gopath_last = os.time() + + self.order = nil + + --mcl_log("gowp target: " .. minetest.pos_to_string(target)) + local p = self.object:get_pos() + local t = vector.offset(target,0,1,0) + + local wp = calculate_path_through_door(p, t, target) + if not wp then + mcl_log("WP empty") + end + output_table(wp) + if wp and #wp > 0 then self._target = t self.callback_arrived = callback_arrived - table.remove(wp,1) + local current_location = table.remove(wp,1) + mcl_log("Removing first co-ord? " .. tostring(current_locaion)) + --self.current_target self.waypoints = wp self.state = PATHFINDING return true From a01c3d134209f7aa87715938aeeaf2c0545d8819 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Mon, 31 Oct 2022 19:51:31 +0000 Subject: [PATCH 05/11] Pumkin price unreasonable and fix logging. --- mods/ENTITIES/mobs_mc/villager.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index c65d63938..ac5d3a285 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -107,7 +107,7 @@ local professions = { }, { - { { "mcl_farming:pumpkin", 8, 13 }, E1 }, + { { "mcl_farming:pumpkin", 6, 7 }, E1 }, { E1, { "mcl_farming:pumpkin_pie", 2, 3} }, { E1, { "mcl_core:apple", 2, 3} }, }, @@ -797,10 +797,10 @@ local function unlock_trades (self) if trades and type(trades) == "table" then for trader, trade in pairs(trades) do local trade_tier_too_high = trade.tier > self._max_trade_tier - mcl_log("Max trade tier of villager: ".. tostring(self._max_trade_tier)) - mcl_log("current trade.tier: ".. tostring(trade.tier)) + --mcl_log("Max trade tier of villager: ".. tostring(self._max_trade_tier)) + --mcl_log("current trade.tier: ".. tostring(trade.tier)) mcl_log("trade tier too high: ".. tostring(trade_tier_too_high)) - mcl_log("locked: ".. tostring(trade["locked"])) + --mcl_log("locked: ".. tostring(trade["locked"])) if not trade_tier_too_high then if trade["locked"] == true then trade.locked = false From 1d667c26b5a97ddc8653b16acfc91b0a6274d34c Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Mon, 31 Oct 2022 19:53:06 +0000 Subject: [PATCH 06/11] Villagers will open and close doors when pathing through. Any failing steps now have a threshold to abandon failed pathing. --- mods/ENTITIES/mcl_mobs/api.lua | 256 +++++++++++++++++++++++---------- 1 file changed, 182 insertions(+), 74 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 98db5e418..2b02aac95 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2545,22 +2545,50 @@ local function go_to_pos(entity,b) mcl_mobs:set_animation(entity, "walk") end -local function check_doors(self) +local function interact_with_door(self, action, target) local p = self.object:get_pos() - local t = minetest.get_timeofday() - local dd = minetest.find_nodes_in_area(vector.offset(p,-1,-1,-1),vector.offset(p,1,1,1),{"group:door"}) - for _,d in pairs(dd) do - local n = minetest.get_node(d) - if n.name:find("_b_") then + --local t = minetest.get_timeofday() + --local dd = minetest.find_nodes_in_area(vector.offset(p,-1,-1,-1),vector.offset(p,1,1,1),{"group:door"}) + --for _,d in pairs(dd) do + if target then + mcl_log("Door target is: ".. minetest.pos_to_string(target)) + + local n = minetest.get_node(target) + if n.name:find("_b_") or n.name:find("_t_") then + mcl_log("Door") local def = minetest.registered_nodes[n.name] - local closed = n.name:find("_b_1") - if self.state == PATHFINDING then - if closed and def.on_rightclick then def.on_rightclick(d,n,self) end - --if not closed and def.on_rightclick then def.on_rightclick(d,n,self) end - else - - end + local closed = n.name:find("_b_1") or n.name:find("_t_1") + --if self.state == PATHFINDING then + if closed and action == "open" and def.on_rightclick then + mcl_log("Open door") + def.on_rightclick(target,n,self) + end + if not closed and action == "close" and def.on_rightclick then + mcl_log("Close door") + def.on_rightclick(target,n,self) + end + --else + else + mcl_log("Not door") + end + else + mcl_log("no target. cannot try and open or close door") + end + --end +end +local function do_pathfind_action (self, action) + if action then + mcl_log("Action present") + local type = action["type"] + local action_val = action["action"] + local target = action["target"] + if target then + mcl_log("Target: ".. minetest.pos_to_string(target)) + end + if type and type == "door" then + mcl_log("Type is door") + interact_with_door(self, action_val, target) end end end @@ -2569,7 +2597,11 @@ local gowp_etime = 0 local function check_gowp(self,dtime) gowp_etime = gowp_etime + dtime - if gowp_etime < 0.1 then return end + + -- 0.1 is optimal. + --less frequently = villager will get sent back after passing a point. + --more frequently = villager will fail points they shouldn't they just didn't get there yet + if gowp_etime < 0.125 then return end gowp_etime = 0 local p = self.object:get_pos() @@ -2597,27 +2629,41 @@ local function check_gowp(self,dtime) end -- More pathing to be done - local distance_to_current_target = 50 - if self.current_target then - distance_to_current_target = vector.distance(p,self.current_target) - --mcl_log("current target:".. minetest.pos_to_string(self.current_target) .. ", Current target distance: ".. tostring(distance_to_current_target)) + if self.current_target and self.current_target["pos"] then + distance_to_current_target = vector.distance(p,self.current_target["pos"]) end - -- 1.6 is good but fails more than it should. Maybe 1.7 - if self.waypoints and #self.waypoints > 0 and ( not self.current_target or distance_to_current_target < 1.7 ) then + -- 0.6 is working but too sensitive. sends villager back too frequently. 0.7 is quite good, but not with heights + -- 0.8 is optimal for 0.025 frequency checks and also 1... Actually. 0.8 is winning + -- 0.9 and 1.0 is also good. Stick with unless door open or closing issues + if self.waypoints and #self.waypoints > 0 and ( not self.current_target or not self.current_target["pos"] or distance_to_current_target < 1 ) then -- We have waypoints, and no current target, or we're at it. We need a new current_target. + do_pathfind_action (self, self.current_target["action"]) + + local failed_attempts = self.current_target["failed_attempts"] + mcl_log("There after " .. failed_attempts .. " failed attempts. current target:".. minetest.pos_to_string(self.current_target["pos"]) .. ". Distance: " .. distance_to_current_target) self.current_target = table.remove(self.waypoints, 1) - mcl_log("There. current target:".. minetest.pos_to_string(self.current_target) .. ". Distance: " .. distance_to_current_target) - --mcl_log("type:".. type(self.current_target) ) - go_to_pos(self,self.current_target) + go_to_pos(self, self.current_target["pos"]) return - elseif self.current_target then + elseif self.current_target and self.current_target["pos"] then -- No waypoints left, but have current target. Potentially last waypoint to go to. + self.current_target["failed_attempts"] = self.current_target["failed_attempts"] + 1 + local failed_attempts = self.current_target["failed_attempts"] + if failed_attempts >= 20 then + mcl_log("Failed to reach position too many times. Abandon route. Times tried: " .. failed_attempts) + self.state = "stand" + self.current_target = nil + self.waypoints = nil + self._target = nil + self.object:set_velocity({x = 0, y = 0, z = 0}) + self.object:set_acceleration({x = 0, y = 0, z = 0}) + return + end - mcl_log("Not there... pos: ".. minetest.pos_to_string(p) .. "self.current_target: ".. minetest.pos_to_string(self.current_target) .. ". Distance: ".. distance_to_current_target) - go_to_pos(self,self.current_target) + mcl_log("Not at pos with failed attempts ".. failed_attempts ..": ".. minetest.pos_to_string(p) .. "self.current_target: ".. minetest.pos_to_string(self.current_target["pos"]) .. ". Distance: ".. distance_to_current_target) + go_to_pos(self, self.current_target["pos"]) -- Do i just delete current_target, and return so we can find final path. else -- Not at target, no current waypoints or current_target. Through the door and should be able to path to target. @@ -2635,50 +2681,32 @@ local function check_gowp(self,dtime) end end - --if self.current_target and not minetest.line_of_sight(self.object:get_pos(),self.current_target) then - if self.current_target and (self.waypoints and #self.waypoints == 0) then + -- I don't think we need the following anymore, but test first. + -- Maybe just need something to path to target if no waypoints left + if self.current_target and self.current_target["pos"] and (self.waypoints and #self.waypoints == 0) then local updated_p = self.object:get_pos() - local distance_to_cur_targ = vector.distance(updated_p,self.current_target) + local distance_to_cur_targ = vector.distance(updated_p,self.current_target["pos"]) mcl_log("Distance to current target: ".. tostring(distance_to_cur_targ)) mcl_log("Current p: ".. minetest.pos_to_string(updated_p)) - --if not minetest.line_of_sight(self.object:get_pos(),self._target) then -- 1.6 is good. is 1.9 better? It could fail less, but will it path to door when it isn't after door if distance_to_cur_targ > 1.9 then - mcl_log("not close to current target: ".. minetest.pos_to_string(self.current_target)) + mcl_log("not close to current target: ".. minetest.pos_to_string(self.current_target["pos"])) go_to_pos(self,self._current_target) else - mcl_log("close to current target: ".. minetest.pos_to_string(self.current_target)) + mcl_log("close to current target: ".. minetest.pos_to_string(self.current_target["pos"])) self.current_target = nil - --go_to_pos(self,self._target) - - --self.waypoints=minetest.find_path(updated_p,self._target,150,1,4) - - --if not self.waypoints then - --mcl_log("Give up ") - --self.state = "walk" - --end --give up end - --self.waypoints=minetest.find_path(p,self._target,150,1,4) - --if not self.waypoints then - --mcl_log("Give up ") - --self.state = "walk" - --end --give up - --self.current_target = nil return end - --if not self.current_target then - --mcl_log("no path. Give up") - --self.state = "walk" - --end end -- execute current state (stand, walk, run, attacks) -- returns true if mob has died local do_states = function(self, dtime) - if self.can_open_doors then check_doors(self) end + --if self.can_open_doors then check_doors(self) end local yaw = self.object:get_yaw() or 0 @@ -3284,6 +3312,73 @@ function append_paths (wp1, wp2) mcl_log("End append") end +local function output_enriched (wp_out) + mcl_log("Output enriched path") + local i = 0 + for _,outy in pairs (wp_out) do + i = i + 1 + mcl_log("Pos ".. i ..":" .. minetest.pos_to_string(outy["pos"])) + + local action = outy["action"] + if action then + mcl_log("type: " .. action["type"]) + mcl_log("action: " .. action["action"]) + mcl_log("target: " .. minetest.pos_to_string(action["target"])) + end + mcl_log("failed attempts: " .. outy["failed_attempts"]) + end +end + +-- This function will take a list of paths, and enrich it with: +-- a var for failed attempts +-- an action, such as to open or close a door where we know that pos requires that action +local function generate_enriched_path(wp_in, door_open_pos, door_close_pos, cur_door_pos) + local wp_out = {} + for i, cur_pos in pairs(wp_in) do + local action = nil + + local one_down = vector.new(0,-1,0) + local cur_pos_to_add = vector.add(cur_pos, one_down) + if door_open_pos and vector.equals (cur_pos, door_open_pos) then + mcl_log ("Door open match") + --action = {type = "door", action = "open"} + action = {} + action["type"] = "door" + action["action"] = "open" + action["target"] = cur_door_pos + cur_pos_to_add = vector.add(cur_pos, one_down) + elseif door_close_pos and vector.equals(cur_pos, door_close_pos) then + mcl_log ("Door close match") + --action = {type = "door", action = "closed"} + action = {} + action["type"] = "door" + action["action"] = "close" + action["target"] = cur_door_pos + cur_pos_to_add = vector.add(cur_pos, one_down) + elseif cur_door_pos and vector.equals(cur_pos, cur_door_pos) then + mcl_log("Current door pos") + cur_pos_to_add = vector.add(cur_pos, one_down) + action = {} + action["type"] = "door" + action["action"] = "open" + action["target"] = cur_door_pos + else + cur_pos_to_add = cur_pos + mcl_log ("Pos doesn't match") + end + + wp_out[i] = {} + wp_out[i]["pos"] = cur_pos_to_add + wp_out[i]["failed_attempts"] = 0 + wp_out[i]["action"] = action + + --wp_out[i] = {"pos" = cur_pos, "failed_attempts" = 0, "action" = action} + --output_pos(cur_pos, i) + end + output_enriched(wp_out) + return wp_out +end + local plane_adjacents = { vector.new(1,0,0), vector.new(-1,0,0), @@ -3294,49 +3389,48 @@ local plane_adjacents = { -- This function is used to see if we can path. We could use to check a route, rather than making people move. local function calculate_path_through_door (p, t, target) -- target is the same as t, just 1 square difference. Maybe we don't need target - mcl_log("Plot route from mob: " .. minetest.pos_to_string(p) .. ", to target: " .. minetest.pos_to_string(t)) - local wp = minetest.find_path(p,t,150,1,4) + local enriched_path = nil + + local cur_door_pos = nil + local pos_closest_to_door = nil + local other_side_of_door = nil --Path to door first + local wp = minetest.find_path(p,t,150,1,4) if not wp then - --mcl_log("gowp. no wp. Look for door") + mcl_log("No direct path. Path through door") local cur_door_pos = minetest.find_node_near(target,16,{"group:door"}) if cur_door_pos then - - --mcl_log("Found a door near") + mcl_log("Found a door near: " .. minetest.pos_to_string(cur_door_pos)) for _,v in pairs(plane_adjacents) do - local pos = vector.add(cur_door_pos,v) + pos_closest_to_door = vector.add(cur_door_pos,v) - local n = minetest.get_node(pos) + local n = minetest.get_node(pos_closest_to_door) if n.name == "air" then - wp = minetest.find_path(p,pos,150,1,4) + wp = minetest.find_path(p,pos_closest_to_door,150,1,4) if wp then - mcl_log("Found a path to next to door".. minetest.pos_to_string(pos)) - local other_side_of_door = vector.add(cur_door_pos,-v) + mcl_log("Found a path to next to door".. minetest.pos_to_string(pos_closest_to_door)) + other_side_of_door = vector.add(cur_door_pos,-v) mcl_log("Opposite is: ".. minetest.pos_to_string(other_side_of_door)) - --table.insert(wp, other_side_of_door) - - local wp_otherside_door_to_target = minetest.find_path(other_side_of_door,t,150,1,4) if wp_otherside_door_to_target and #wp_otherside_door_to_target > 0 then table.insert(wp, cur_door_pos) append_paths (wp, wp_otherside_door_to_target) + enriched_path = generate_enriched_path(wp, pos_closest_to_door, other_side_of_door, cur_door_pos) mcl_log("We have a path from outside door to target") - return wp else mcl_log("We cannot path from outside door to target") end break - else - --mcl_log("This block next to door doesn't work.") + mcl_log("This block next to door doesn't work.") end else - --mcl_log("Block is not air, it is: ".. n.name) + mcl_log("Block is not air, it is: ".. n.name) end end @@ -3345,13 +3439,17 @@ local function calculate_path_through_door (p, t, target) end else mcl_log("We have a direct route") - return wp end + + if wp and not enriched_path then + enriched_path = generate_enriched_path(wp) + end + return enriched_path end local gopath_last = os.time() function mcl_mobs:gopath(self,target,callback_arrived) - if self.state == PATHFINDING then mcl_log("Already set as gowp, don't set another path until done.") return end + if self.state == PATHFINDING then mcl_log("Already pathfinding, don't set another until done.") return end if os.time() - gopath_last < 5 then mcl_log("Not ready to path yet") @@ -3367,16 +3465,26 @@ function mcl_mobs:gopath(self,target,callback_arrived) local wp = calculate_path_through_door(p, t, target) if not wp then - mcl_log("WP empty") + mcl_log("Could not calculate path") end - output_table(wp) + --output_table(wp) if wp and #wp > 0 then self._target = t self.callback_arrived = callback_arrived local current_location = table.remove(wp,1) - mcl_log("Removing first co-ord? " .. tostring(current_locaion)) - --self.current_target + if current_location and current_location["pos"] then + mcl_log("Removing first co-ord? " .. tostring(current_location["pos"])) + else + mcl_log("Nil pos") + end + --current_location = table.remove(wp,1) + --if current_location and current_location["pos"] then + -- mcl_log("Removing first co-ord? " .. tostring(current_location["pos"])) + --else + -- mcl_log("Nil pos") + --end + self.current_target = current_location self.waypoints = wp self.state = PATHFINDING return true From 7f33287e18e22fb60914bd891446f3384f916ba7 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Tue, 1 Nov 2022 01:01:13 +0000 Subject: [PATCH 07/11] Reset trade counter when unlocking trades --- mods/ENTITIES/mobs_mc/villager.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index ac5d3a285..49ddbfac6 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -804,6 +804,7 @@ local function unlock_trades (self) if not trade_tier_too_high then if trade["locked"] == true then trade.locked = false + trade.trade_counter = 0 has_unlocked = true mcl_log("Villager has a locked trade. Unlocking") end @@ -1593,6 +1594,7 @@ local trade_inventory = { trader.health = math.min(trader.hp_max, trader.health + 4) end trade.trade_counter = trade.trade_counter + 1 + mcl_log("Trade counter is: ".. trade.trade_counter) -- Semi-randomly lock trade for repeated trade (not if there's only 1 trade) if trader._max_tradenum > 1 then if trade.trade_counter >= 12 then From 5d5babdb20afce8d67a0a713a01b56c8da9933c8 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Tue, 1 Nov 2022 01:02:22 +0000 Subject: [PATCH 08/11] Tweak distance to current_target check --- mods/ENTITIES/mcl_mobs/api.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 2b02aac95..8fdc459d3 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2637,7 +2637,7 @@ local function check_gowp(self,dtime) -- 0.6 is working but too sensitive. sends villager back too frequently. 0.7 is quite good, but not with heights -- 0.8 is optimal for 0.025 frequency checks and also 1... Actually. 0.8 is winning -- 0.9 and 1.0 is also good. Stick with unless door open or closing issues - if self.waypoints and #self.waypoints > 0 and ( not self.current_target or not self.current_target["pos"] or distance_to_current_target < 1 ) then + if self.waypoints and #self.waypoints > 0 and ( not self.current_target or not self.current_target["pos"] or distance_to_current_target < 0.9 ) then -- We have waypoints, and no current target, or we're at it. We need a new current_target. do_pathfind_action (self, self.current_target["action"]) From c606092066fe5c51448f263e89813eb75aec05b9 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Tue, 1 Nov 2022 20:31:03 +0000 Subject: [PATCH 09/11] Pathfinding fix for villagers --- mods/ENTITIES/mcl_mobs/api.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 8fdc459d3..b10468dde 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -414,11 +414,14 @@ end local set_yaw = function(self, yaw, delay, dtime) - - if self.noyaw then return end - self._turn_to = yaw + if self.state ~= PATHFINDING then + self._turn_to = yaw + end + + --mcl_log("Yaw is: \t\t" .. tostring(math.deg(yaw))) + --mcl_log("self.object:get_yaw() is: \t" .. tostring(math.deg(self.object:get_yaw()))) --clamp our yaw to a 360 range if math.deg(self.object:get_yaw()) > 360 then @@ -2601,7 +2604,7 @@ local function check_gowp(self,dtime) -- 0.1 is optimal. --less frequently = villager will get sent back after passing a point. --more frequently = villager will fail points they shouldn't they just didn't get there yet - if gowp_etime < 0.125 then return end + if gowp_etime < 0.1 then return end gowp_etime = 0 local p = self.object:get_pos() @@ -2651,8 +2654,8 @@ local function check_gowp(self,dtime) -- No waypoints left, but have current target. Potentially last waypoint to go to. self.current_target["failed_attempts"] = self.current_target["failed_attempts"] + 1 local failed_attempts = self.current_target["failed_attempts"] - if failed_attempts >= 20 then - mcl_log("Failed to reach position too many times. Abandon route. Times tried: " .. failed_attempts) + if failed_attempts >= 50 then + mcl_log("Failed to reach position (" .. minetest.pos_to_string(self.current_target["pos"]) .. ") too many times. Abandon route. Times tried: " .. failed_attempts) self.state = "stand" self.current_target = nil self.waypoints = nil @@ -2662,7 +2665,7 @@ local function check_gowp(self,dtime) return end - mcl_log("Not at pos with failed attempts ".. failed_attempts ..": ".. minetest.pos_to_string(p) .. "self.current_target: ".. minetest.pos_to_string(self.current_target["pos"]) .. ". Distance: ".. distance_to_current_target) + --mcl_log("Not at pos with failed attempts ".. failed_attempts ..": ".. minetest.pos_to_string(p) .. "self.current_target: ".. minetest.pos_to_string(self.current_target["pos"]) .. ". Distance: ".. distance_to_current_target) go_to_pos(self, self.current_target["pos"]) -- Do i just delete current_target, and return so we can find final path. else @@ -3364,7 +3367,7 @@ local function generate_enriched_path(wp_in, door_open_pos, door_close_pos, cur_ action["target"] = cur_door_pos else cur_pos_to_add = cur_pos - mcl_log ("Pos doesn't match") + --mcl_log ("Pos doesn't match") end wp_out[i] = {} From 5ff4ce7116e0abd7b1941eb0506092bd7d520664 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Tue, 1 Nov 2022 20:31:51 +0000 Subject: [PATCH 10/11] Less verbose logging --- mods/ENTITIES/mobs_mc/villager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 49ddbfac6..39f0655d4 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -799,7 +799,7 @@ local function unlock_trades (self) local trade_tier_too_high = trade.tier > self._max_trade_tier --mcl_log("Max trade tier of villager: ".. tostring(self._max_trade_tier)) --mcl_log("current trade.tier: ".. tostring(trade.tier)) - mcl_log("trade tier too high: ".. tostring(trade_tier_too_high)) + --mcl_log("trade tier too high: ".. tostring(trade_tier_too_high)) --mcl_log("locked: ".. tostring(trade["locked"])) if not trade_tier_too_high then if trade["locked"] == true then From 2f4622909e8c28d40d2c53581048ecde01206122 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Tue, 1 Nov 2022 21:02:46 +0000 Subject: [PATCH 11/11] Right click shouldn't stop work and allow a reset of trades --- mods/ENTITIES/mobs_mc/villager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 39f0655d4..440a5d127 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -1760,7 +1760,7 @@ mcl_mobs:register_mob("mobs_mc:villager", { --end) else self.state = "stand" -- cancel gowp in case it has messed up - self.order = nil -- cancel work if working + --self.order = nil -- cancel work if working end -- Initiate trading