Page 1 of 1

[question] items and naming conventions

PostPosted: Mon May 13, 2019 21:33
by Exilyth
So, after updating from 4.?.? to 5.0.1, I'm having a problem with naming conventions with my mod.

I would like to depend on some item from another mod, but also provide a replacement in case that mod is not installed (e.g. only have an optional dependency on that mod).

What I'm currently doing is:
If [someothermod] is installed then use someothermod:someitem
else define othermod:someitem

Obviously, defining objects with a prefix unequal to the [modname] results in a naming convention error.

Thus the question is:
How can I provide a replacement item without violating naming conventions?

Re: [question] items and naming conventions

PostPosted: Tue May 14, 2019 12:42
by ThorfinnS
If I'm understanding your question, you want to use "alias".

Re: [question] items and naming conventions

PostPosted: Tue May 14, 2019 22:55
by v-rob
Add an extra colon before the other mod's name, like so:

Code: Select all
minetest.register_node(":someothermod:someitem", {
    ...
})


This works even if the other mod isn't installed or doesn't exist.

Re: [question] items and naming conventions

PostPosted: Wed May 15, 2019 13:14
by Exilyth
What I would like to do is use a crafting material from another mod and supply a replacement if that mod is not installed, so players can still create the recipe.

But, if [someothermod] is not installed, ':someothermod:someitem' does not exist and thus there's no way to craft?

Re: [question] items and naming conventions

PostPosted: Wed May 15, 2019 14:49
by AiTechEye
Exilyth wrote:But, if [someothermod] is not installed, ':someothermod:someitem' does not exist and thus there's no way to craft?


I guess you meant something like this, "if bones doesn't exist" default wood and its craft recipe disappear, as an example.

at least some help i hope :)

Code: Select all
clear_craft=function(mod,r)
   if not minetest.get_modpath(mod) then
      minetest.clear_craft({output=r})
      minetest.unregister_item(r)
   end
end

minetest.register_on_mods_loaded(function()
   -- add lines here
   clear_craft("bones","default:wood")
end)

Re: [question] items and naming conventions

PostPosted: Wed May 15, 2019 21:29
by v-rob
Exilyth wrote:What I would like to do is use a crafting material from another mod and supply a replacement if that mod is not installed, so players can still create the recipe.

But, if [someothermod] is not installed, ':someothermod:someitem' does not exist and thus there's no way to craft?


No, using the colon first allows you to define an item for any mod inside your own mod, whether it exists or not. If 'someothermod' doesn't exist, ':someothermod:someitem' inside your own mod will create an item in this non-existant mod's namespace.

Don't do this in your code:
Code: Select all
if mod_is_enabled then
    craft using othermod:item
else
    mymod:item
    craft using mymod:item
end


Do this instead:
Code: Select all
if not mod_is_enabled then
    :othermod:item
end
craft using othermod:item


As you can see, if it doesn't exist, you create it using the colon before in the other mod's namespace.