Make placed leaves always become player leaves

Any players which still have leaves in their inventory from before this update would have had those leaves rot if someone were to break any log withing 6 nodes of the leaves if they were placed. This commit adds an `after_place_node` callback which makes sure that any leaves placed by the player, become non-rotting player leaves.
This commit is contained in:
FossFanatic 2023-02-10 10:39:43 +00:00
parent 1defd03408
commit fdb2333493

@ -44,6 +44,14 @@ function mcl_core.update_leaves(pos, oldnode)
end end
end end
function mcl_core.make_player_leaves(pos)
local node = minetest.get_node(pos)
if minetest.get_item_group(node.name, "player_leaves") ~= 1 then
local playerleafname = node.name .. "_player"
minetest.set_node(pos, {name = playerleafname})
end
end
-- Register tree trunk (wood) and bark -- Register tree trunk (wood) and bark
local function register_tree_trunk(subname, description_trunk, description_bark, longdesc, tile_inner, tile_bark, stripped_variant) local function register_tree_trunk(subname, description_trunk, description_bark, longdesc, tile_inner, tile_bark, stripped_variant)
minetest.register_node("mcl_core:"..subname, { minetest.register_node("mcl_core:"..subname, {
@ -207,10 +215,13 @@ local function register_leaves(subname, description, longdesc, tiles, color, par
minetest.swap_node(pos, new_node) minetest.swap_node(pos, new_node)
end end
end end
end,
after_place_node = function(pos)
mcl_core.make_player_leaves(pos) -- Leaves placed by the player should always be player leaves.
end, end,
} }
minetest.register_node("mcl_core:player" .. subname, pl_def) minetest.register_node("mcl_core:" .. subname .. "_player", pl_def)
local l_def = table.copy(pl_def) local l_def = table.copy(pl_def)
l_def.groups.player_leaves = nil l_def.groups.player_leaves = nil