aboutsummaryrefslogtreecommitdiff
path: root/builtin/game/register.lua
diff options
context:
space:
mode:
authorpaly2 <plangrognet@laposte.net>2016-07-10 15:15:43 +0200
committerkwolekr <kwolekr@minetest.net>2016-09-08 03:26:52 -0400
commitaa33166386f737f213f1f3005ffd6a6adfd2d97f (patch)
tree6ddbec97ff34fd231a7cb23e70d1dc7dce6049cb /builtin/game/register.lua
parent7eacdc7bb8ec8f8b06b5e0b2464af219e623cd56 (diff)
downloadminetest-aa33166386f737f213f1f3005ffd6a6adfd2d97f.tar.gz
minetest-aa33166386f737f213f1f3005ffd6a6adfd2d97f.tar.bz2
minetest-aa33166386f737f213f1f3005ffd6a6adfd2d97f.zip
Add minetest.unregister_item and minetest.register_alias_force
Diffstat (limited to 'builtin/game/register.lua')
-rw-r--r--builtin/game/register.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/builtin/game/register.lua b/builtin/game/register.lua
index f330491a2..05dc5fef8 100644
--- a/builtin/game/register.lua
+++ b/builtin/game/register.lua
@@ -7,6 +7,9 @@
local register_item_raw = core.register_item_raw
core.register_item_raw = nil
+local unregister_item_raw = core.unregister_item_raw
+core.unregister_item_raw = nil
+
local register_alias_raw = core.register_alias_raw
core.register_alias_raw = nil
@@ -172,6 +175,27 @@ function core.register_item(name, itemdef)
register_item_raw(itemdef)
end
+function core.unregister_item(name)
+ if not core.registered_items[name] then
+ core.log("warning", "Not unregistering item " ..name..
+ " because it doesn't exist.")
+ return
+ end
+ -- Erase from registered_* table
+ local type = core.registered_items[name].type
+ if type == "node" then
+ core.registered_nodes[name] = nil
+ elseif type == "craft" then
+ core.registered_craftitems[name] = nil
+ elseif type == "tool" then
+ core.registered_tools[name] = nil
+ end
+ core.registered_items[name] = nil
+
+
+ unregister_item_raw(name)
+end
+
function core.register_node(name, nodedef)
nodedef.type = "node"
core.register_item(name, nodedef)
@@ -242,6 +266,20 @@ function core.register_alias(name, convert_to)
end
end
+function core.register_alias_force(name, convert_to)
+ if forbidden_item_names[name] then
+ error("Unable to register alias: Name is forbidden: " .. name)
+ end
+ if core.registered_items[name] ~= nil then
+ core.unregister_item(name)
+ core.log("info", "Removed item " ..name..
+ " while attempting to force add an alias")
+ end
+ --core.log("Registering alias: " .. name .. " -> " .. convert_to)
+ core.registered_aliases[name] = convert_to
+ register_alias_raw(name, convert_to)
+end
+
function core.on_craft(itemstack, player, old_craft_list, craft_inv)
for _, func in ipairs(core.registered_on_crafts) do
itemstack = func(itemstack, player, old_craft_list, craft_inv) or itemstack