Fixed fall damage

This commit is contained in:
tenplus1 2015-03-08 15:49:37 +00:00
parent bdd331bd8b
commit 5ce41f42f7
4 changed files with 25 additions and 30 deletions

17
api.lua
View File

@ -32,7 +32,7 @@ function mobs:register_mob(name, def)
light_damage = def.light_damage,
water_damage = def.water_damage,
lava_damage = def.lava_damage,
fall_damage = def.fall_damage or true,
fall_damage = def.fall_damage or 1,
drops = def.drops,
armor = def.armor,
drawtype = def.drawtype,
@ -207,19 +207,15 @@ function mobs:register_mob(name, def)
end
-- fall damage
if self.fall_damage and self.object:getvelocity().y == 0 then
if not self.old_y then
self.old_y = self.object:getpos().y
else
if self.fall_damage == 1 and self.object:getvelocity().y == 0 then
local d = self.old_y - self.object:getpos().y
if d > 5 then
local damage = d-5
local damage = math.floor(d - 5)
self.object:set_hp(self.object:get_hp()-damage)
check_for_death(self)
end
self.old_y = self.object:getpos().y
end
end
-- if pause state then this is where the loop ends
-- pause is only set after a monster is hit
@ -584,7 +580,7 @@ function mobs:register_mob(name, def)
self.object:set_armor_groups({fleshy=self.armor})
self.object:setacceleration({x=0, y=-10, z=0})
self.state = "stand"
self.object:setvelocity({x=0, y=self.object:getvelocity().y, z=0})
self.object:setvelocity({x=0, y=self.object:getvelocity().y, z=0}) ; self.old_y = self.object:getpos().y
self.object:setyaw(math.random(1, 360)/180*math.pi)
if self.type == "monster" and peaceful_only then
self.object:remove()
@ -764,7 +760,7 @@ end
-- on mob death drop items
function check_for_death(self)
if self.object:get_hp() < 1 then
if self.object:get_hp() > 0 then return end
local pos = self.object:getpos()
pos.y = pos.y + 0.5 -- drop items half a block higher
self.object:remove()
@ -777,12 +773,9 @@ function check_for_death(self)
end
end
end
if self.sounds.death ~= nil then
minetest.sound_play(self.sounds.death,{object = self.object,})
end
end
end
function mobs:register_arrow(name, def)

View File

@ -34,6 +34,7 @@ mobs:register_mob("mobs:bee", {
water_damage = 1,
lava_damage = 1,
light_damage = 0,
fall_damage = 0,
-- model animation
animation = {
speed_normal = 15,

View File

@ -40,6 +40,7 @@ mobs:register_mob("mobs:chicken", {
water_damage = 1,
lava_damage = 5,
light_damage = 0,
fall_damage = 0,
-- model animation
animation = {
speed_normal = 15,

View File

@ -34,7 +34,7 @@ mobs:register_mob("mobs:mese_monster", {
walk_velocity = 0.5,
run_velocity = 2,
jump = true,
fall_damage = false,
fall_damage = 0,
-- drops mese when dead
drops = {
{name = "default:mese_crystal",