Default: update Cactus
This commit is contained in:
parent
c0a58f4a87
commit
d52cbad344
@ -699,28 +699,49 @@ function default.can_interact_with_node(player, pos)
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Cactus damage
|
||||
--
|
||||
|
||||
if not minetest.settings:get_bool("creative_mode") then
|
||||
local objects = minetest.get_objects_inside_radius
|
||||
minetest.register_abm({
|
||||
label = "Cactus damage",
|
||||
nodenames = {"default:cactus"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
catch_up = false,
|
||||
action = function(pos)
|
||||
local players = objects(pos, 1)
|
||||
for _, player in pairs(players) do
|
||||
if player:is_player() then
|
||||
player:set_hp(player:get_hp() - 2)
|
||||
end
|
||||
minetest.register_entity("default:cactus_entity", {
|
||||
physical = false,
|
||||
collisionbox = {0},
|
||||
visual = "sprite",
|
||||
textures = {"blank.png"},
|
||||
on_punch = function() return true end,
|
||||
on_activate = function(self)
|
||||
local ent = self.object
|
||||
local pos = ent:get_pos()
|
||||
if #minetest.get_objects_inside_radius(pos, 1) > 0 then
|
||||
return
|
||||
end
|
||||
ent:remove()
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
label = "Cactus damage",
|
||||
nodenames = {"default:cactus"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
catch_up = false,
|
||||
action = function(pos)
|
||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 1)) do
|
||||
-- Only entity can really do `punch`.
|
||||
-- Attacking yourself (obj punched obj) is not a good idea
|
||||
local cactus = minetest.add_entity(pos, "default:cactus_entity")
|
||||
if cactus then
|
||||
obj:punch(cactus, 1.0, {
|
||||
full_punch_interval = 0,
|
||||
damage_groups = {fleshy = 3}
|
||||
}, nil)
|
||||
cactus:remove()
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
--
|
||||
-- Snowballs
|
||||
|
@ -995,6 +995,28 @@ minetest.register_node("default:cactus", {
|
||||
fixed = {
|
||||
{-7/16, -8/16, -7/16, 7/16, 8/16, 7/16}
|
||||
}
|
||||
},
|
||||
|
||||
mesecon = {
|
||||
on_mvps_move = function(pos, _, oldpos)
|
||||
local check_pos = {x = oldpos.x, y = oldpos.y + 1, z = oldpos.z}
|
||||
local oldnode = minetest.get_node(check_pos)
|
||||
local height = 1
|
||||
local drop = false
|
||||
while oldnode.name == "default:cactus" do
|
||||
local new_pos = {x = pos.x, y = pos.y + height, z = pos.z}
|
||||
minetest.remove_node(check_pos)
|
||||
if drop or minetest.get_node(new_pos).name ~= "air" then
|
||||
minetest.add_item(check_pos, "default:cactus")
|
||||
drop = true
|
||||
else
|
||||
minetest.add_node(new_pos, {name = "default:cactus"})
|
||||
end
|
||||
height = height + 1
|
||||
check_pos.y = check_pos.y + 1
|
||||
oldnode = minetest.get_node(check_pos)
|
||||
end
|
||||
end
|
||||
}
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user