Fixed mob feeding function bug from going over hp_max

This commit is contained in:
TenPlus1 2015-10-27 19:15:55 +00:00
parent 1e09b87997
commit 7aab8df677
2 changed files with 27 additions and 23 deletions

31
api.lua
View File

@ -207,6 +207,7 @@ function within_limits(pos, radius)
return false -- beyond limits return false -- beyond limits
end end
-- environmental damage (water, lava, fire, light)
do_env_damage = function(self) do_env_damage = function(self)
-- feed/tame text timer (so mob full messages dont spam chat) -- feed/tame text timer (so mob full messages dont spam chat)
@ -259,6 +260,7 @@ do_env_damage = function(self)
check_for_death(self) check_for_death(self)
end end
-- jump if facing a solid node (not fences)
do_jump = function(self) do_jump = function(self)
if self.fly then if self.fly then
@ -307,9 +309,9 @@ do_jump = function(self)
end end
end end
-- check if POS is in mobs field of view
in_fov = function(self, pos) in_fov = function(self, pos)
-- check if POS is in mobs field of view
local yaw = self.object:getyaw() + self.rotate local yaw = self.object:getyaw() + self.rotate
local vx = math.sin(yaw) local vx = math.sin(yaw)
local vz = math.cos(yaw) local vz = math.cos(yaw)
@ -326,7 +328,7 @@ in_fov = function(self, pos)
return true return true
end end
-- modified from TNT mod -- blast damage to entities nearby (modified from TNT mod)
function entity_physics(pos, radius) function entity_physics(pos, radius)
radius = radius * 2 radius = radius * 2
@ -344,7 +346,7 @@ function entity_physics(pos, radius)
end end
end end
-- get node at location but with fallback for nil or unknown -- get node but use fallback for nil or unknown
function node_ok(pos, fallback) function node_ok(pos, fallback)
fallback = fallback or "default:dirt" fallback = fallback or "default:dirt"
@ -386,6 +388,7 @@ function follow_holding(self, clicker)
end end
local function breed(self) local function breed(self)
-- horny animal can mate for 40 seconds, -- horny animal can mate for 40 seconds,
-- afterwards horny animal cannot mate again for 200 seconds -- afterwards horny animal cannot mate again for 200 seconds
if self.horny == true if self.horny == true
@ -412,10 +415,11 @@ local function breed(self)
}) })
-- jump when grown so not to fall into ground -- jump when grown so not to fall into ground
local v = self.object:getvelocity() local v = self.object:getvelocity()
v.x = 0 self.object:setvelocity({
v.y = self.jump_height x = 0,
v.z = 0 y = self.jump_height,
self.object:setvelocity(v) z = 0
})
end end
end end
@ -1721,13 +1725,14 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
-- heal health -- heal health
local hp = self.object:get_hp() local hp = self.object:get_hp()
hp = hp + 4 hp = hp + 4
if hp >= self.hp_max if hp >= self.hp_max then
and self.htimer < 1 then
hp = self.hp_max hp = self.hp_max
minetest.chat_send_player(clicker:get_player_name(), if self.htimer < 1 then
self.name:split(":")[2] minetest.chat_send_player(clicker:get_player_name(),
.. " at full health (" .. tostring(hp) .. ")") self.name:split(":")[2]
self.htimer = 5 .. " at full health (" .. tostring(hp) .. ")")
self.htimer = 5
end
end end
self.object:set_hp(hp) self.object:set_hp(hp)
self.health = hp self.health = hp

View File

@ -159,16 +159,15 @@ minetest.register_entity("mobs:sheep", {
on_step = function(self, dtime) on_step = function(self, dtime)
self.timer = self.timer + dtime self.timer = self.timer + dtime
if self.timer >= 1 then if self.timer >= 1 then
self.timer = 0 self.timer = 0
self.object:setacceleration({ self.object:setacceleration({
x = 0, x = 0,
y = -10, y = -10,
z = 0 z = 0
}) })
end end
end, end,
}) })