2019-01-26 13:58:35 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
|
|
|
local math, minetest, pairs, vector
|
|
|
|
= math, minetest, pairs, vector
|
|
|
|
local math_floor
|
|
|
|
= math.floor
|
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
|
|
|
|
local fallname = "__builtin:falling_node"
|
|
|
|
local fallnode = minetest.registered_entities[fallname]
|
|
|
|
|
|
|
|
local dmg = {}
|
|
|
|
|
|
|
|
local function dmggc()
|
|
|
|
dmg = {}
|
|
|
|
minetest.after(10, dmggc)
|
|
|
|
end
|
|
|
|
dmggc()
|
|
|
|
|
|
|
|
local oldtick = fallnode.on_step
|
|
|
|
fallnode.on_step = function(self, dtime, ...)
|
2019-01-29 20:41:29 -05:00
|
|
|
if not self.crush_damage then
|
|
|
|
local def = minetest.registered_items[self.node.name]
|
2019-02-03 09:11:36 -05:00
|
|
|
self.crush_damage = def and def.crush_damage or 0
|
2019-01-29 20:41:29 -05:00
|
|
|
end
|
|
|
|
if self.crush_damage <= 0 then
|
|
|
|
return oldtick(self, dtime, ...)
|
|
|
|
end
|
|
|
|
|
2019-01-26 13:58:35 -05:00
|
|
|
local pos = self.object:getpos()
|
|
|
|
local vel = self.object:getvelocity()
|
|
|
|
local q = dmg[self] or 0
|
|
|
|
local v = vector.length(vel)
|
2019-01-29 20:41:29 -05:00
|
|
|
q = q + v * v * dtime * self.crush_damage
|
2019-01-26 13:58:35 -05:00
|
|
|
if q > 1 then
|
|
|
|
local n = math_floor(q)
|
|
|
|
for k, v in pairs(minetest.get_objects_inside_radius(pos, 1)) do
|
|
|
|
v:set_hp(v:get_hp() - n)
|
|
|
|
end
|
|
|
|
q = q - n
|
|
|
|
end
|
|
|
|
dmg[self] = q
|
|
|
|
|
|
|
|
return oldtick(self, dtime, ...)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_entity(":" .. fallname, fallnode)
|