hijack the ABM to check for orphaned bamboo nodes.

This commit is contained in:
Michieal 2023-02-05 00:59:21 -05:00
parent 449cbdb330
commit a44566f863
3 changed files with 37 additions and 8 deletions

View File

@ -293,7 +293,6 @@ local bamboo_block_def = {
return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under))) return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
end, end,
} }
minetest.register_node("mcl_bamboo:bamboo_block", bamboo_block_def) minetest.register_node("mcl_bamboo:bamboo_block", bamboo_block_def)

View File

@ -67,6 +67,35 @@ end
local BAMBOO_ENDCAP_NAME = "mcl_bamboo:bamboo_endcap" local BAMBOO_ENDCAP_NAME = "mcl_bamboo:bamboo_endcap"
function mcl_bamboo.break_orphaned(pos)
local node_below = minetest.get_node(vector.offset(pos, 0, -1, 0))
local node_name = node_below.name
-- prevent accidental calling on non-bamboo nodes.
if mcl_bamboo.is_bamboo(minetest.get_node(pos).name) == false then
return
end
if mcl_bamboo.is_dirt(node_name) == false and mcl_bamboo.is_bamboo(node_name) == false then
-- dig the node.
if not minetest.dig_node(pos) then
-- If dig_node fails, to prevent the bamboo from hanging in the air, manually remove it.
minetest.remove_node(pos) -- if that fails, remove the node
local istack = ItemStack("mcl_bamboo:bamboo")
local sound_params = {
pos = pos,
gain = 1.0, -- default
max_hear_distance = 10, -- default, uses a Euclidean metric
}
minetest.remove_node(pos)
minetest.sound_play(mcl_sounds.node_sound_wood_defaults().dug, sound_params, true)
minetest.add_item(pos, istack)
end
end
end
function mcl_bamboo.grow_bamboo(pos, bonemeal_applied) function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
local node_above = minetest.get_node(vector.offset(pos, 0, 1, 0)) local node_above = minetest.get_node(vector.offset(pos, 0, 1, 0))
mcl_bamboo.mcl_log("Grow bamboo called; bonemeal: " .. tostring(bonemeal_applied)) mcl_bamboo.mcl_log("Grow bamboo called; bonemeal: " .. tostring(bonemeal_applied))

View File

@ -30,6 +30,7 @@ minetest.register_abm({
interval = 10, interval = 10,
chance = 20, chance = 20,
action = function(pos, _) action = function(pos, _)
mcl_bamboo.break_orphaned(pos)
mcl_bamboo.grow_bamboo(pos, false) mcl_bamboo.grow_bamboo(pos, false)
end, end,
}) })