Created
October 2, 2012 01:48
-
-
Save cornernote/3815683 to your computer and use it in GitHub Desktop.
Override Registered Nodes for Minetest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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