Make sure other mods don't override fruits

This commit is contained in:
philipmi 2022-02-26 17:31:19 +01:00
parent a6523eda1c
commit 704def8b8d

View file

@ -50,26 +50,29 @@ local add_fruit_regrowable = function(fruit, node, leaves)
end end
end end
-- override fruit -- wait until mods are loaded to ensure that other mods do not override overrides
minetest.override_item(node, { minetest.register_on_mods_loaded(function()
groups = groups, -- make sure (moretrees) fruits don't fall on dig -- override fruit
after_place_node = function(pos, placer) -- make sure (moretrees and plumtree) fruits aren't placed by player minetest.override_item(node, {
if placer:is_player() and node == "plumtree:plum" then groups = groups, -- make sure (moretrees) fruits don't fall on dig
minetest.set_node(pos, {name = node, param2 = 0}) after_place_node = function(pos, placer) -- make sure (moretrees and plumtree) fruits aren't placed by player
elseif placer:is_player() then if placer:is_player() and node == "plumtree:plum" then
minetest.set_node(pos, {name = node, param2 = 1}) minetest.set_node(pos, {name = node, param2 = 0})
end elseif placer:is_player() then
end, minetest.set_node(pos, {name = node, param2 = 1})
on_dig = minetest.node_dig, -- override on_dig functions causing regrowth not to work end
after_dig_node = function(pos, oldnode, oldmetadata, digger) end,
if oldnode.param2 == 0 and oldnode.name ~= "plumtree:plum" on_dig = minetest.node_dig, -- override on_dig functions causing regrowth not to work
or oldnode.name == "plumtree:plum" and oldnode.param2 == 1 after_dig_node = function(pos, oldnode, oldmetadata, digger)
or oldnode.name == "cacaotree:pod" then if oldnode.param2 == 0 and oldnode.name ~= "plumtree:plum"
minetest.set_node(pos, {name = "regrowing_fruits:"..fruit.."_mark", param2 = oldnode.param2}) or oldnode.name == "plumtree:plum" and oldnode.param2 == 1
minetest.get_node_timer(pos):start(math.random(300, 1500)) or oldnode.name == "cacaotree:pod" then
end minetest.set_node(pos, {name = "regrowing_fruits:"..fruit.."_mark", param2 = oldnode.param2})
end, minetest.get_node_timer(pos):start(math.random(300, 1500))
}) end
end,
})
end)
-- air node to mark fruit pos -- air node to mark fruit pos
minetest.register_node("regrowing_fruits:"..fruit.."_mark", { minetest.register_node("regrowing_fruits:"..fruit.."_mark", {