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