[Solved!] Basing node def on other node overrides other node

Post Reply
User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

[Solved!] Basing node def on other node overrides other node

by texmex » Post

I have this weird problem where I'm basing a new node definition on default:tree:

Code: Select all

local def = minetest.registered_nodes["default:tree"]
minetest.register_node("mod:node", def)
I then go on overriding the new node's definition like so:

Code: Select all

minetest.override_item("mod:node", {
	description = "New node",
}
The problem is that now every time I place default:tree, it places mod:node instead. How can I correct that, while still utilizing this registering technique?

Just for clarification the default:tree definition contains no special handling of node placement, from what I can tell:

Code: Select all

minetest.register_node("default:tree", {
	description = "Apple Tree",
	tiles = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
Last edited by texmex on Sat Aug 18, 2018 08:44, edited 1 time in total.

User avatar
ChimneySwift
Member
Posts: 320
Joined: Fri Sep 22, 2017 06:46
GitHub: ChimneySwift
IRC: ChimneySwift
In-game: ChimneySwift
Location: 127.0.0.1

Re: Basing node def on other node overrides other node

by ChimneySwift » Post

Huh. Interesting. This probably won't fix the issue, but this might be more efficient than overriding after registering:

Code: Select all

local def = minetest.registered_nodes["default:tree"]
def.description = "New node"
minetest.register_node("mod:node", def)
-- Then don't bother with the override
Although I don't know if you want to change anything else, so this might not work for your use case.

As to the actual issue, rather unhelpfully I have no idea...
A spoon is basically a tiny bowl with a stick on it

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: Basing node def on other node overrides other node

by Krock » Post

ChimneySwift wrote:Huh. Interesting. This probably won't fix the issue, but this might be more efficient than overriding after registering:
Congratulations. The value of minetest.registered_nodes["default:tree"].description is now "New Node" due to table references.

Instead deep-copy the entire table so that any references are gone:

Code: Select all

local def = table.copy(minetest.registered_nodes["default:tree"])
def.description = "New node"
minetest.register_node("mod:node", def)
-- Then don't bother with the override
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: Basing node def on other node overrides other node

by texmex » Post

Excellent Krock, thank you!

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests