[question] items and naming conventions

Post Reply
Exilyth
Member
Posts: 73
Joined: Sun Jul 28, 2013 18:46
Location: Earth

[question] items and naming conventions

by Exilyth » Post

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: 311
Joined: Mon Feb 25, 2019 22:05
GitHub: ThorfinnS

Re: [question] items and naming conventions

by ThorfinnS » Post

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

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

Re: [question] items and naming conventions

by v-rob » Post

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.
Core Developer | My Best Mods: Bridger - Slats - Stained Glass

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

Re: [question] items and naming conventions

by Exilyth » Post

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: 1000
Joined: Fri May 29, 2015 21:14
GitHub: AiTechEye
Location: Sweden

Re: [question] items and naming conventions

by AiTechEye » Post

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 76 times

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

Re: [question] items and naming conventions

by v-rob » Post

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.
Core Developer | My Best Mods: Bridger - Slats - Stained Glass

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests