Page 1 of 1

Are custom item definition fields OK?

PostPosted: Sat Oct 29, 2016 21:29
by Wuzzy
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.

Re: Are custom item definition fields OK?

PostPosted: Sat Oct 29, 2016 21:44
by kaeza
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.

Re: Are custom item definition fields OK?

PostPosted: Sun Oct 30, 2016 00:10
by Wuzzy
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.