Are custom item definition fields OK?

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Are custom item definition fields OK?

by Wuzzy » Sat Oct 29, 2016 21:29

Hi!
I noticed that it is possible to add custom fields to item definitions. For example, if you do this:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_node("example:hello", {
    description="HelloNode",
    tiles = { "example_hello.png" },
    my_custom_field_1 = "Test",
    my_custom_field_2 = 123,
    my_custom_field_3 = true,
})

It works! The 3 custom fields will be retained and can later be queried by using minetest.registered_nodes.

I wonder if the practice of adding custom fields to item definitions is “allowed” and intended by Minetest or if this is just possible “by pure luck” and may be deprecated or unsupported later.
Also, is this safe? Can I really store arbitrary information in any item definition like this? Or is there a risk of data loss?

If this is safe and intended, that would be very useful!

If yes, Minetest should introduce some naming conventions.
Like, custom fields should always have the form “x_modname_fieldname” to avoid naming collisions.
I'm creating MineClone 2, a Minecraft clone for Minetest.
I made the Help modpack, adding in-game help to Minetest.
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Are custom item definition fields OK?

by kaeza » Sat Oct 29, 2016 21:44

I mostly agree with the naming conventions, but this shouldn't be enforced by the engine. Rather, it should be a convention adopted by modders like this is (I hope?) done for formspec names.

I'd say the only thing required is that the core devs don't introduce any fields beginning with `x_`, and leave that prefix for modders.

We should form the MANA (Minetest Assigned Numbers Authority) :P

Edit: And just in case, yes it is 99% safe, as long as the core devs don't decide to use the same field as a mod for another purposes, like you said.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: Are custom item definition fields OK?

by Wuzzy » Sun Oct 30, 2016 00:10

Cool, thanks. Yes, I agree, the name should only be a convention and not be enforced (it would be overkill).
I think it might help to write this down into lua_api.txt. First the fact that custom fields are allowed and possible. Second that names starting with “x_” are safe, the only thing is that core devs need to be aware of this.
I post an issue soon.
I'm creating MineClone 2, a Minecraft clone for Minetest.
I made the Help modpack, adding in-game help to Minetest.
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron