1
0
Fork 0

Fix mobs walking into water too often

This commit is contained in:
Wuzzy 2020-01-29 23:11:20 +01:00
parent fff1949804
commit 9326a76973
1 changed files with 30 additions and 19 deletions

View File

@ -718,7 +718,9 @@ local do_env_damage = function(self)
-- what is mob standing in? -- what is mob standing in?
pos.y = pos.y + y_level + 0.25 -- foot level pos.y = pos.y + y_level + 0.25 -- foot level
local pos2 = {x=pos.x, y=pos.y-1, z=pos.z}
self.standing_in = node_ok(pos, "air").name self.standing_in = node_ok(pos, "air").name
self.standing_on = node_ok(pos2, "air").name
-- don't fall when on ignore, just stand still -- don't fall when on ignore, just stand still
if self.standing_in == "ignore" then if self.standing_in == "ignore" then
@ -1909,8 +1911,9 @@ local do_states = function(self, dtime)
local lp = nil local lp = nil
-- is there something I need to avoid? -- is there something I need to avoid?
if self.water_damage > 0 if (self.water_damage > 0
and self.lava_damage > 0 then and self.lava_damage > 0)
or self.breath_max ~= -1 then
lp = minetest.find_node_near(s, 1, {"group:water", "group:lava"}) lp = minetest.find_node_near(s, 1, {"group:water", "group:lava"})
@ -1921,18 +1924,27 @@ local do_states = function(self, dtime)
elseif self.lava_damage > 0 then elseif self.lava_damage > 0 then
lp = minetest.find_node_near(s, 1, {"group:lava"}) lp = minetest.find_node_near(s, 1, {"group:lava"})
elseif self.fire_damage > 0 then
lp = minetest.find_node_near(s, 1, {"group:fire"})
end end
if lp then if lp then
local def = minetest.registered_nodes[self.standing_in]
-- if mob in water or lava then look for land local def2 = minetest.registered_nodes[self.standing_on]
if (self.lava_damage -- If mob in or on dangerous block, look for land
and minetest.registered_nodes[self.standing_in].groups.lava) if (self.breath_max ~= -1
and (def.drowning > 0 or def2.drowning > 0))
or (self.lava_damage
and (def.groups.lava or def2.groups.lava))
or (self.water_damage or (self.water_damage
and minetest.registered_nodes[self.standing_in].groups.water) then and (def.groups.water or def2.groups.water))
or (self.fire_damage
and (def.groups.fire or def2.groups.fire)) then
lp = minetest.find_node_near(s, 5, {"group:soil", "group:stone", lp = minetest.find_node_near(s, 5, {"group:solid"})
"group:sand", node_ice, node_snowblock})
-- did we find land? -- did we find land?
if lp then if lp then
@ -1954,16 +1966,14 @@ local do_states = function(self, dtime)
yaw = yaw + random(-0.5, 0.5) yaw = yaw + random(-0.5, 0.5)
end end
-- A danger is near but mob is not inside
else else
local vec = { -- Randomly turn
x = lp.x - s.x, if random(1, 100) <= 30 then
z = lp.z - s.z yaw = yaw + random(-0.5, 0.5)
} yaw = set_yaw(self, yaw, 8)
end
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
if lp.x > s.x then yaw = yaw + pi end
end end
yaw = set_yaw(self, yaw, 8) yaw = set_yaw(self, yaw, 8)
@ -1972,7 +1982,6 @@ local do_states = function(self, dtime)
elseif random(1, 100) <= 30 then elseif random(1, 100) <= 30 then
yaw = yaw + random(-0.5, 0.5) yaw = yaw + random(-0.5, 0.5)
yaw = set_yaw(self, yaw, 8) yaw = set_yaw(self, yaw, 8)
end end
@ -1987,6 +1996,7 @@ local do_states = function(self, dtime)
self.state = "stand" self.state = "stand"
set_animation(self, "stand") set_animation(self, "stand")
else else
set_velocity(self, self.walk_velocity) set_velocity(self, self.walk_velocity)
if flight_check(self) if flight_check(self)
@ -2866,7 +2876,8 @@ local mob_activate = function(self, staticdata, def, dtime)
self.collisionbox = colbox self.collisionbox = colbox
self.selectionbox = selbox self.selectionbox = selbox
self.visual_size = vis_size self.visual_size = vis_size
self.standing_in = "" self.standing_in = "ignore"
self.standing_on = "ignore"
self.jump_sound_cooloff = 0 -- used to prevent jump sound from being played too often in short time self.jump_sound_cooloff = 0 -- used to prevent jump sound from being played too often in short time
self.opinion_sound_cooloff = 0 -- used to prevent sound spam of particular sound types self.opinion_sound_cooloff = 0 -- used to prevent sound spam of particular sound types