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
|
|
|
|
|
2020-01-04 10:51:10 -05:00
|
|
|
local function maketick(mult, getname, oldtick)
|
|
|
|
oldtick = oldtick or function() end
|
|
|
|
return function(self, dtime, ...)
|
2021-12-13 21:54:13 -05:00
|
|
|
local age = self.crush_age or 0
|
|
|
|
age = age + dtime
|
|
|
|
self.crush_age = age
|
|
|
|
if age < 1 then return end
|
|
|
|
|
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()
|
2020-05-18 18:36:06 -04:00
|
|
|
if not pos then return end
|
2019-09-13 22:26:47 -04:00
|
|
|
pos.y = pos.y - 1
|
2019-12-29 12:12:08 -05:00
|
|
|
local vel = self.object:get_velocity()
|
2020-03-22 00:09:24 -04:00
|
|
|
local v = vel and -vel.y or 0
|
2019-09-13 22:26:47 -04:00
|
|
|
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
|
2021-08-06 21:11:42 -04:00
|
|
|
nodecore.addphealth(o, -q, {
|
2020-02-20 07:16:19 -05:00
|
|
|
nc_type = "crushing",
|
|
|
|
entity = self
|
|
|
|
})
|
2019-09-13 22:26:47 -04:00
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2020-01-04 10:51:10 -05:00
|
|
|
nodecore.register_falling_node_step(maketick(1, function(s) return s.node.name end))
|
2020-01-05 11:42:22 -05:00
|
|
|
nodecore.register_item_entity_step(maketick(0.2, function(s) return ItemStack(s.itemstring):get_name() end))
|