Default: update Cactus

This commit is contained in:
MoNTE48 2021-09-17 10:48:41 +02:00
parent c0a58f4a87
commit d52cbad344
2 changed files with 59 additions and 16 deletions

View File

@ -699,28 +699,49 @@ function default.can_interact_with_node(player, pos)
return false return false
end end
-- --
-- Cactus damage -- Cactus damage
-- --
if not minetest.settings:get_bool("creative_mode") then minetest.register_entity("default:cactus_entity", {
local objects = minetest.get_objects_inside_radius physical = false,
minetest.register_abm({ collisionbox = {0},
label = "Cactus damage", visual = "sprite",
nodenames = {"default:cactus"}, textures = {"blank.png"},
interval = 1, on_punch = function() return true end,
chance = 1, on_activate = function(self)
catch_up = false, local ent = self.object
action = function(pos) local pos = ent:get_pos()
local players = objects(pos, 1) if #minetest.get_objects_inside_radius(pos, 1) > 0 then
for _, player in pairs(players) do return
if player:is_player() then end
player:set_hp(player:get_hp() - 2) ent:remove()
end 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
}) end
end })
-- --
-- Snowballs -- Snowballs

View File

@ -995,6 +995,28 @@ minetest.register_node("default:cactus", {
fixed = { fixed = {
{-7/16, -8/16, -7/16, 7/16, 8/16, 7/16} {-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
} }
}) })