1
0
Fork 0

Make cactus be able to damage mobs

This commit is contained in:
Eliy21 2024-01-16 14:55:40 +00:00
parent 2d2b64006b
commit aea5c6f7be
1 changed files with 37 additions and 0 deletions

View File

@ -136,3 +136,40 @@ minetest.register_node("mcl_core:reeds", {
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
})
local function cactus_damage_check(obj)
-- where am I?
local pos = obj:get_pos()
if pos then
-- Am I near a cactus?
local near = minetest.find_node_near(pos, 1, "mcl_core:cactus")
if not near and near ~= nil then
near = find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, "mcl_core:cactus")
end
if near then
-- Am I touching the cactus? If so, it hurts
local dist = vector.distance(pos, near)
local dist_feet = vector.distance({x=pos.x, y=pos.y-1, z=pos.z}, near)
if dist < 1.1 or dist_feet < 1.1 then
if obj:get_hp() > 0 then
mcl_util.deal_damage(obj, 1, {type = "cactus"})
end
end
end
end
end
local etime = 0
minetest.register_globalstep(function(dtime)
etime = dtime + etime
if etime < 0.5 then return end
etime = 0
--for _,pl in pairs(minetest.get_connected_players()) do
--cactus_damage_check(pl) -- Another player cactus damage check code is in mcl_playerplus
--end
for _,ent in pairs(minetest.luaentities) do
if ent.is_mob then
cactus_damage_check(ent.object)
end
end
end)