[question] items and naming conventions

Exilyth
Member
 
Posts: 71
Joined: Sun Jul 28, 2013 18:46
Location: Earth

[question] items and naming conventions

by Exilyth » Mon May 13, 2019 21:33

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?
 

ThorfinnS
Member
 
Posts: 59
Joined: Mon Feb 25, 2019 22:05
GitHub: ThorfinnS

Re: [question] items and naming conventions

by ThorfinnS » Tue May 14, 2019 12:42

If I'm understanding your question, you want to use "alias".
 

User avatar
v-rob
Member
 
Posts: 649
Joined: Thu Mar 24, 2016 03:19
Location: Right behind you.
GitHub: v-rob

Re: [question] items and naming conventions

by v-rob » Tue May 14, 2019 22:55

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.
 

Exilyth
Member
 
Posts: 71
Joined: Sun Jul 28, 2013 18:46
Location: Earth

Re: [question] items and naming conventions

by Exilyth » Wed May 15, 2019 13:14

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?
 

User avatar
AiTechEye
Member
 
Posts: 698
Joined: Fri May 29, 2015 21:14
Location: Sweden
GitHub: AiTechEye

Re: [question] items and naming conventions

by AiTechEye » Wed May 15, 2019 14:49

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)
Attachments
cc.zip
(261 Bytes) Downloaded 3 times
 

User avatar
v-rob
Member
 
Posts: 649
Joined: Thu Mar 24, 2016 03:19
Location: Right behind you.
GitHub: v-rob

Re: [question] items and naming conventions

by v-rob » Wed May 15, 2019 21:29

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.
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 0 guests