Fix animals attacking players for no reason

This commit is contained in:
cora 2022-07-17 16:16:53 +02:00 committed by Gitea
parent 99037cb0ec
commit bf756403a3

View File

@ -1926,10 +1926,9 @@ local monster_attack = function(self)
for n = 1, #objs do for n = 1, #objs do
if objs[n]:is_player() then if objs[n]:is_player() then
if mcl_mobs.invis[ objs[n]:get_player_name() ] or (not object_in_range(self, objs[n])) then if mcl_mobs.invis[ objs[n]:get_player_name() ] or (not object_in_range(self, objs[n])) then
type = "" type = ""
else elseif (self.type == "monster" or self._aggro) then
player = objs[n] player = objs[n]
type = "player" type = "player"
name = "player" name = "player"
@ -3345,11 +3344,11 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
and (self.child == false or self.type == "monster") and (self.child == false or self.type == "monster")
and hitter:get_player_name() ~= self.owner and hitter:get_player_name() ~= self.owner
and not mcl_mobs.invis[ name ] then and not mcl_mobs.invis[ name ] then
if not die then if not die then
-- attack whoever punched mob -- attack whoever punched mob
self.state = "" self.state = ""
do_attack(self, hitter) do_attack(self, hitter)
self._aggro= true
end end
-- alert others to the attack -- alert others to the attack
@ -3361,7 +3360,6 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
obj = objs[n]:get_luaentity() obj = objs[n]:get_luaentity()
if obj then if obj then
-- only alert members of same mob or friends -- only alert members of same mob or friends
if obj.group_attack if obj.group_attack
and obj.state ~= "attack" and obj.state ~= "attack"
@ -3371,6 +3369,7 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
elseif type(obj.group_attack) == "table" then elseif type(obj.group_attack) == "table" then
for i=1, #obj.group_attack do for i=1, #obj.group_attack do
if obj.name == obj.group_attack[i] then if obj.name == obj.group_attack[i] then
obj._aggro = true
do_attack(obj, hitter) do_attack(obj, hitter)
break break
end end