Code: Select all
if minetest.item_is_registered("default:cobble") then
minetest.override_item("default:cobble", ...)
end
Code: Select all
if minetest.item_is_registered("default:cobble") then
minetest.override_item("default:cobble", ...)
end
Code: Select all
if minetest.registered_nodes["default:dirt"] then
--exists
end
Just so I'm sure I'm understanding how it works, an optional depend ("default?") is sufficient for this, right? It's what I've been doing, and haven't run into anything yet, but maybe that's just dumb luck..Krock wrote:To ensure this code always works as expected, depend your mod on "default". This ensures that the nodes are registered before your mod is loaded. However, that does not matter as soon you're checking the node presence from a callback because then all nodes will already be registered.
Code: Select all
if minetest.registered_nodes["default:dirt"] then
--exists
end
Code: Select all
minetest.register_on_joinplayer(function(player)
if minetest.registered_nodes["default:dirt"] then
--exists
end
end)
This wont work for overriding.TalkLounge wrote:But if you do something like this in your init.lua
then you don't need to set default as optional dependency, because all mods will be loaded, before this callback will be called.Code: Select all
minetest.register_on_joinplayer(function(player) if minetest.registered_nodes["default:dirt"] then --exists end end)
Code: Select all
minetest.register_on_mods_loaded(function()
if minetest.registered_nodes["default:cobble"] then
minetest.override_item("default:cobble", {})
end
end)
Users browsing this forum: Ahrefs [Bot] and 6 guests