Add minetest.override_item
authorShadowNinja <shadowninja@minetest.net>
Tue, 14 Jan 2014 00:28:55 +0000 (19:28 -0500)
committerShadowNinja <shadowninja@minetest.net>
Tue, 14 Jan 2014 02:41:00 +0000 (21:41 -0500)
builtin/misc_register.lua
doc/lua_api.txt

index 6c50ff02e53e7d3426c979dcf8ef4840d0341a34..d00945dbd077e25db4fce0c9da96cc895726be0d 100644 (file)
@@ -315,6 +315,24 @@ minetest.register_item(":", {
 })
 
 
+function minetest.override_item(name, redefinition)
+       if redefinition.name ~= nil then
+               error("Attemt to redefine name of "..name.." to "..dump(redefinition.name), 2)
+       end
+       if redefinition.type ~= nil then
+               error("Attemt to redefine type of "..name.." to "..dump(redefinition.type), 2)
+       end
+       local item = minetest.registered_items[name]
+       if not item then
+               error("Attemt to override non-existent item "..name, 2)
+       end
+       for k, v in pairs(redefinition) do
+               rawset(item, k, v)
+       end
+       register_item_raw(item)
+end
+
+
 function minetest.run_callbacks(callbacks, mode, ...)
        assert(type(callbacks) == "table")
        local cb_len = #callbacks
index 8bd83995e67d53a3b50cc2ca888bbbf354ccda62..40dace9da3521163058b9a47c223351a5346882b 100644 (file)
@@ -1189,6 +1189,10 @@ minetest.register_alias(name, convert_to)
 minetest.register_craft(recipe)
 minetest.register_ore(ore definition)
 minetest.register_decoration(decoration definition)
+minetest.override_item(name, redefinition)
+^ Overrides fields of an item registered with register_node/tool/craftitem.
+^ Note: Item must already be defined, (opt)depend on the mod defining it.
+^ Example: minetest.override_item("default:mese", {light_source=LIGHT_MAX})
 
 Global callback registration functions: (Call these only at load time)
 minetest.register_globalstep(func(dtime))