Skip to content

Instantly share code, notes, and snippets.

@cornernote
Created October 2, 2012 01:48
Show Gist options
  • Save cornernote/3815683 to your computer and use it in GitHub Desktop.
Save cornernote/3815683 to your computer and use it in GitHub Desktop.
Override Registered Nodes for Minetest
-- The reason this is needed is because the following code does not work as expected:
local node = minetest.registered_nodes["default:sapling"]
node.after_place_node = function(pos) print("TESTING123") end
minetest.register_node(":default:sapling", node)
--
-- inline solution
--
local node = {}
for k,v in pairs(minetest.registered_nodes["default:sapling"]) do node[k] = v end
node.after_place_node = function(pos) print("TESTING123") end
minetest.register_node(":default:sapling", node)
--
-- global function that can be reused
--
-- function
clone_registered = function(case,name)
local params = {}
local list
if case == "item" then list = minetest.registered_items end
if case == "node" then list = minetest.registered_nodes end
if case == "craftitem" then list = minetest.registered_craftitems end
if case == "tool" then list = minetest.registered_tools end
if case == "entity" then list = minetest.registered_entities end
if list then
for k,v in pairs(list[name]) do
params[k] = v
end
end
return params
end
-- usage
local node = clone_registered("node","default:tree")
node.after_place_node = function(pos) print("TESTING123") end
minetest.register_node(":default:tree", node)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment