2019-01-26 13:58:35 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-09-13 22:26:47 -04:00
|
|
|
local ItemStack, minetest, nodecore, pairs
|
|
|
|
= ItemStack, minetest, nodecore, pairs
|
2019-01-26 13:58:35 -05:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
2019-09-21 08:38:16 -04:00
|
|
|
local function getcrushdamage(name, alreadyloose)
|
|
|
|
local def = minetest.registered_items[name]
|
|
|
|
if def and def.crush_damage then return def.crush_damage end
|
|
|
|
if alreadyloose then return 0 end
|
2019-10-11 01:14:00 -04:00
|
|
|
return name and getcrushdamage(name .. "_loose", true) or 0
|
2019-09-21 08:38:16 -04:00
|
|
|
end
|
|
|
|
|
2019-09-13 22:26:47 -04:00
|
|
|
local function register(fallname, mult, getname)
|
|
|
|
local fallnode = minetest.registered_entities[fallname]
|
2019-01-26 13:58:35 -05:00
|
|
|
|
2019-09-13 22:26:47 -04:00
|
|
|
local oldtick = fallnode.on_step
|
|
|
|
fallnode.on_step = function(self, dtime, ...)
|
2019-09-21 08:38:16 -04:00
|
|
|
self.crush_damage = self.crush_damage or getcrushdamage(getname(self))
|
2019-09-13 22:26:47 -04:00
|
|
|
if self.crush_damage <= 0 then
|
|
|
|
return oldtick(self, dtime, ...)
|
|
|
|
end
|
2019-01-29 20:41:29 -05:00
|
|
|
|
2019-09-13 22:26:47 -04:00
|
|
|
local pos = self.object:get_pos()
|
|
|
|
pos.y = pos.y - 1
|
|
|
|
local v = -self.object:get_velocity().y
|
|
|
|
if v <= 0 then
|
|
|
|
return oldtick(self, dtime, ...)
|
|
|
|
end
|
|
|
|
local q = v * v * dtime * self.crush_damage * mult
|
|
|
|
for _, o in pairs(minetest.get_objects_inside_radius(pos, 1)) do
|
|
|
|
if o:is_player() then
|
|
|
|
nodecore.addphealth(o, -q)
|
|
|
|
end
|
2019-01-26 13:58:35 -05:00
|
|
|
end
|
2019-09-13 22:26:47 -04:00
|
|
|
|
|
|
|
return oldtick(self, dtime, ...)
|
2019-01-26 13:58:35 -05:00
|
|
|
end
|
|
|
|
|
2019-09-13 22:26:47 -04:00
|
|
|
minetest.register_entity(":" .. fallname, fallnode)
|
2019-01-26 13:58:35 -05:00
|
|
|
end
|
|
|
|
|
2019-09-13 22:26:47 -04:00
|
|
|
register("__builtin:falling_node", 1, function(s) return s.node.name end)
|
|
|
|
register("__builtin:item", 0.2, function(s) return ItemStack(s.itemstring):get_name() end)
|