summaryrefslogtreecommitdiff
path: root/builtin/game/register.lua
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/game/register.lua')
-rw-r--r--builtin/game/register.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/builtin/game/register.lua b/builtin/game/register.lua
index f330491a2..90f095e9f 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
@@ -124,6 +127,11 @@ function core.register_item(name, itemdef)
fixed = {-1/8, -1/2, -1/8, 1/8, 1/2, 1/8},
}
end
+ if itemdef.light_source and itemdef.light_source > core.LIGHT_MAX then
+ itemdef.light_source = core.LIGHT_MAX
+ core.log("warning", "Node 'light_source' value exceeds maximum," ..
+ " limiting to maximum: " ..name)
+ end
setmetatable(itemdef, {__index = core.nodedef_default})
core.registered_nodes[itemdef.name] = itemdef
elseif itemdef.type == "craft" then
@@ -172,6 +180,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 +271,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