Page 1 of 1

Modify a node property from another mod

PostPosted: Thu Jun 09, 2016 17:54
by Zerock
I plan on soon beginning development on an extensive modpack which will require overrides of many default node definitions. Rather than having to fork the default mod, I'd like to re-register the ones that need changing.

Question 1: can you even re-register a node with the same name as an existing one?

If possible then,

Question 2: would I have to redefine the entire node, or could I somehow get all the properties of, say, default:dirt, make my modifications, and re-register default:dirt with the new node table?

Re: Modify a node property from another mod

PostPosted: Thu Jun 09, 2016 21:46
by kaeza
Look for `override_item` in the API docs. Here is an example of use.

Re: Modify a node property from another mod

PostPosted: Fri Jun 10, 2016 02:01
by Zerock
If I wanted to modify the groups of the node, would I have to know the original groups, or can I append to them?

Re: Modify a node property from another mod

PostPosted: Fri Jun 10, 2016 02:15
by duane
Zerock wrote:If I wanted to modify the groups of the node, would I have to know the original groups, or can I append to them?


Try "node.groups.newgroup = 1"

Re: Modify a node property from another mod

PostPosted: Fri Jun 10, 2016 13:30
by Zerock
How can I get "node" in that context? I've been looking at the API docs for node lookup, but the only functions with names resembling what I'd expect to get node information are only lookups by position, not registered node name.

Re: Modify a node property from another mod

PostPosted: Fri Jun 10, 2016 13:36
by rubenwardy
minetest.registered_nodes["modname:itemname"] gives you the def table

Re: Modify a node property from another mod

PostPosted: Fri Jun 10, 2016 14:27
by Zerock
Very good. I'll give this a shot.

Re: Modify a node property from another mod

PostPosted: Fri Jun 10, 2016 17:56
by Zerock
This doesn't seem to work.

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.registered_nodes['default:dirt'].groups.falling_node = 1


throws

attempt to index field 'default:dirt' (a nil value)

Re: Modify a node property from another mod

PostPosted: Fri Jun 10, 2016 18:27
by Krock
Zerock wrote:attempt to index field 'default:dirt' (a nil value)

Is "default" in your depends.txt file? If not, add it. (Create the file if it's missing)
This error means that the node was not registered yet to the time when Minetest loaded your mod. Adding it to the dependencies will load your mod after the listed mods.

Re: Modify a node property from another mod

PostPosted: Fri Jun 10, 2016 22:25
by Zerock
Okay, that seems to have worked, but now the line seems to have no effect. Dirt doesn't fall.

Re: Modify a node property from another mod

PostPosted: Fri Jun 10, 2016 23:20
by rubenwardy
You also need to depend on farming, as farming destructively overrides the dirty groups