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

View File

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

View File

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

View File

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