Merge pull request 'Villager fixes' (#2387) from villager_fixes into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/2387 Reviewed-by: MysticTempest <mystictempest@noreply.git.minetest.land>
This commit is contained in:
commit
b0da96611e
|
@ -2283,6 +2283,9 @@ end
|
|||
local function go_to_pos(entity,b)
|
||||
if not entity then return end
|
||||
local s=entity.object:get_pos()
|
||||
if not b then
|
||||
--self.state = "stand"
|
||||
return end
|
||||
if vector.distance(b,s) < 1 then
|
||||
--set_velocity(entity,0)
|
||||
return true
|
||||
|
@ -2318,21 +2321,23 @@ local gowp_etime = 0
|
|||
|
||||
local function check_gowp(self,dtime)
|
||||
gowp_etime = gowp_etime + dtime
|
||||
if gowp_etime < 1 then return end
|
||||
if gowp_etime < 0.2 then return end
|
||||
gowp_etime = 0
|
||||
local p = self.object:get_pos()
|
||||
if not p or not self._target then return end
|
||||
if vector.distance(p,self._target) < 2 or ( self.waypoints and #self.waypoints == 0 ) then
|
||||
if vector.distance(p,self._target) < 1 then
|
||||
self.waypoints = nil
|
||||
self._target = nil
|
||||
self.current_target = nil
|
||||
self.state = "walk"
|
||||
self.state = "stand"
|
||||
if self.callback_arrived then return self.callback_arrived(self) end
|
||||
return true
|
||||
end
|
||||
if self.waypoints and ( not self.current_target or vector.distance(p,self.current_target) < 1.5 ) then
|
||||
if self.waypoints and ( not self.current_target or vector.distance(p,self.current_target) < 2 ) then
|
||||
self.current_target = table.remove(self.waypoints, 1)
|
||||
--minetest.log("nextwp:".. tostring(self.current_target) )
|
||||
go_to_pos(self,self.current_target)
|
||||
return
|
||||
elseif self.current_target then
|
||||
go_to_pos(self,self.current_target)
|
||||
end
|
||||
|
@ -2922,6 +2927,7 @@ local gopath_last = os.time()
|
|||
function mcl_mobs:gopath(self,target,callback_arrived)
|
||||
if os.time() - gopath_last < 15 then return end
|
||||
gopath_last = os.time()
|
||||
--minetest.log("gowp")
|
||||
local p = self.object:get_pos()
|
||||
local t = vector.offset(target,0,1,0)
|
||||
local wp = minetest.find_path(p,t,150,1,4)
|
||||
|
@ -2941,6 +2947,7 @@ function mcl_mobs:gopath(self,target,callback_arrived)
|
|||
if wp and #wp > 0 then
|
||||
self._target = t
|
||||
self.callback_arrived = callback_arrived
|
||||
table.remove(wp,1)
|
||||
self.waypoints = wp
|
||||
self.state = "gowp"
|
||||
return true
|
||||
|
@ -2948,7 +2955,7 @@ function mcl_mobs:gopath(self,target,callback_arrived)
|
|||
self.state = "walk"
|
||||
self.waypoints = nil
|
||||
self.current_target = nil
|
||||
--minetest.log("no path found")
|
||||
-- minetest.log("no path found")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -631,13 +631,21 @@ end
|
|||
|
||||
local function get_a_job(self)
|
||||
local p = self.object:get_pos()
|
||||
local nn = minetest.find_nodes_in_area(vector.offset(p,-8,-8,-8),vector.offset(p,8,8,8),jobsites)
|
||||
for _,n in pairs(nn) do
|
||||
if n and employ(self,n) then return true end
|
||||
end
|
||||
local n = minetest.find_node_near(p,1,jobsites)
|
||||
if n and employ(self,n) then return true end
|
||||
if self.state ~= "gowp" then look_for_job(self) end
|
||||
end
|
||||
|
||||
local function check_jobsite(self)
|
||||
if self._traded or not self._jobsite then 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
|
||||
self._profession = "unemployed"
|
||||
set_textures(self)
|
||||
end
|
||||
end
|
||||
|
||||
local function update_max_tradenum(self)
|
||||
if not self._trades then
|
||||
return
|
||||
|
@ -656,6 +664,7 @@ end
|
|||
local function init_trades(self, inv)
|
||||
local profession = professions[self._profession]
|
||||
local trade_tiers = profession.trades
|
||||
self._traded = true
|
||||
if trade_tiers == nil then
|
||||
-- Empty trades
|
||||
self._trades = false
|
||||
|
@ -1357,6 +1366,8 @@ mcl_mobs:register_mob("mobs_mc:villager", {
|
|||
end
|
||||
if self._profession == "unemployed" then
|
||||
get_a_job(self)
|
||||
else
|
||||
check_jobsite(self)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
@ -1391,7 +1402,8 @@ mcl_mobs:register_mob("mobs_mc:villager", {
|
|||
})
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
Villager spawning in mcl_villages
|
||||
mcl_mobs:spawn_specific(
|
||||
"mobs_mc:villager",
|
||||
"overworld",
|
||||
|
@ -1421,6 +1433,6 @@ minetest.LIGHT_MAX+1,
|
|||
4,
|
||||
mobs_mc.water_level+1,
|
||||
mcl_vars.mg_overworld_max)
|
||||
|
||||
--]]
|
||||
-- spawn eggs
|
||||
mcl_mobs:register_egg("mobs_mc:villager", S("Villager"), "mobs_mc_spawn_icon_villager.png", 0)
|
||||
|
|
Loading…
Reference in New Issue
Block a user