-- Make raw registration functions inaccessible to anyone except this file
--
-local register_item_raw = minetest.register_item_raw
-minetest.register_item_raw = nil
+local register_item_raw = core.register_item_raw
+core.register_item_raw = nil
-local register_alias_raw = minetest.register_alias_raw
-minetest.register_item_raw = nil
+local register_alias_raw = core.register_alias_raw
+core.register_item_raw = nil
--
-- Item / entity / ABM registration functions
--
-minetest.registered_abms = {}
-minetest.registered_entities = {}
-minetest.registered_items = {}
-minetest.registered_nodes = {}
-minetest.registered_craftitems = {}
-minetest.registered_tools = {}
-minetest.registered_aliases = {}
+core.registered_abms = {}
+core.registered_entities = {}
+core.registered_items = {}
+core.registered_nodes = {}
+core.registered_craftitems = {}
+core.registered_tools = {}
+core.registered_aliases = {}
-- For tables that are indexed by item name:
--- If table[X] does not exist, default to table[minetest.registered_aliases[X]]
+-- If table[X] does not exist, default to table[core.registered_aliases[X]]
local alias_metatable = {
__index = function(t, name)
- return rawget(t, minetest.registered_aliases[name])
+ return rawget(t, core.registered_aliases[name])
end
}
-setmetatable(minetest.registered_items, alias_metatable)
-setmetatable(minetest.registered_nodes, alias_metatable)
-setmetatable(minetest.registered_craftitems, alias_metatable)
-setmetatable(minetest.registered_tools, alias_metatable)
+setmetatable(core.registered_items, alias_metatable)
+setmetatable(core.registered_nodes, alias_metatable)
+setmetatable(core.registered_craftitems, alias_metatable)
+setmetatable(core.registered_tools, alias_metatable)
-- These item names may not be used because they would interfere
-- with legacy itemstrings
return name:sub(2)
else
-- Modname prefix enforcement
- local expected_prefix = minetest.get_current_modname() .. ":"
+ local expected_prefix = core.get_current_modname() .. ":"
if name:sub(1, #expected_prefix) ~= expected_prefix then
error("Name " .. name .. " does not follow naming conventions: " ..
"\"modname:\" or \":\" prefix required")
end
end
-function minetest.register_abm(spec)
- -- Add to minetest.registered_abms
- minetest.registered_abms[#minetest.registered_abms+1] = spec
+function core.register_abm(spec)
+ -- Add to core.registered_abms
+ core.registered_abms[#core.registered_abms+1] = spec
end
-function minetest.register_entity(name, prototype)
+function core.register_entity(name, prototype)
-- Check name
if name == nil then
error("Unable to register entity: Name is nil")
prototype.name = name
prototype.__index = prototype -- so that it can be used as a metatable
- -- Add to minetest.registered_entities
- minetest.registered_entities[name] = prototype
+ -- Add to core.registered_entities
+ core.registered_entities[name] = prototype
end
-function minetest.register_item(name, itemdef)
+function core.register_item(name, itemdef)
-- Check name
if name == nil then
error("Unable to register item: Name is nil")
fixed = {-1/8, -1/2, -1/8, 1/8, 1/2, 1/8},
}
end
- setmetatable(itemdef, {__index = minetest.nodedef_default})
- minetest.registered_nodes[itemdef.name] = itemdef
+ setmetatable(itemdef, {__index = core.nodedef_default})
+ core.registered_nodes[itemdef.name] = itemdef
elseif itemdef.type == "craft" then
- setmetatable(itemdef, {__index = minetest.craftitemdef_default})
- minetest.registered_craftitems[itemdef.name] = itemdef
+ setmetatable(itemdef, {__index = core.craftitemdef_default})
+ core.registered_craftitems[itemdef.name] = itemdef
elseif itemdef.type == "tool" then
- setmetatable(itemdef, {__index = minetest.tooldef_default})
- minetest.registered_tools[itemdef.name] = itemdef
+ setmetatable(itemdef, {__index = core.tooldef_default})
+ core.registered_tools[itemdef.name] = itemdef
elseif itemdef.type == "none" then
- setmetatable(itemdef, {__index = minetest.noneitemdef_default})
+ setmetatable(itemdef, {__index = core.noneitemdef_default})
else
error("Unable to register item: Type is invalid: " .. dump(itemdef))
end
-- BEGIN Legacy stuff
if itemdef.cookresult_itemstring ~= nil and itemdef.cookresult_itemstring ~= "" then
- minetest.register_craft({
+ core.register_craft({
type="cooking",
output=itemdef.cookresult_itemstring,
recipe=itemdef.name,
})
end
if itemdef.furnace_burntime ~= nil and itemdef.furnace_burntime >= 0 then
- minetest.register_craft({
+ core.register_craft({
type="fuel",
recipe=itemdef.name,
burntime=itemdef.furnace_burntime
-- Disable all further modifications
getmetatable(itemdef).__newindex = {}
- --minetest.log("Registering item: " .. itemdef.name)
- minetest.registered_items[itemdef.name] = itemdef
- minetest.registered_aliases[itemdef.name] = nil
+ --core.log("Registering item: " .. itemdef.name)
+ core.registered_items[itemdef.name] = itemdef
+ core.registered_aliases[itemdef.name] = nil
register_item_raw(itemdef)
end
-function minetest.register_node(name, nodedef)
+function core.register_node(name, nodedef)
nodedef.type = "node"
- minetest.register_item(name, nodedef)
+ core.register_item(name, nodedef)
end
-function minetest.register_craftitem(name, craftitemdef)
+function core.register_craftitem(name, craftitemdef)
craftitemdef.type = "craft"
-- BEGIN Legacy stuff
end
-- END Legacy stuff
- minetest.register_item(name, craftitemdef)
+ core.register_item(name, craftitemdef)
end
-function minetest.register_tool(name, tooldef)
+function core.register_tool(name, tooldef)
tooldef.type = "tool"
tooldef.stack_max = 1
end
-- END Legacy stuff
- minetest.register_item(name, tooldef)
+ core.register_item(name, tooldef)
end
-function minetest.register_alias(name, convert_to)
+function core.register_alias(name, convert_to)
if forbidden_item_names[name] then
error("Unable to register alias: Name is forbidden: " .. name)
end
- if minetest.registered_items[name] ~= nil then
- minetest.log("WARNING: Not registering alias, item with same name" ..
+ if core.registered_items[name] ~= nil then
+ core.log("WARNING: Not registering alias, item with same name" ..
" is already defined: " .. name .. " -> " .. convert_to)
else
- --minetest.log("Registering alias: " .. name .. " -> " .. convert_to)
- minetest.registered_aliases[name] = convert_to
+ --core.log("Registering alias: " .. name .. " -> " .. convert_to)
+ core.registered_aliases[name] = convert_to
register_alias_raw(name, convert_to)
end
end
-local register_biome_raw = minetest.register_biome
-minetest.registered_biomes = {}
-function minetest.register_biome(biome)
- minetest.registered_biomes[biome.name] = biome
+local register_biome_raw = core.register_biome
+core.registered_biomes = {}
+function core.register_biome(biome)
+ core.registered_biomes[biome.name] = biome
register_biome_raw(biome)
end
-function minetest.on_craft(itemstack, player, old_craft_list, craft_inv)
- for _, func in ipairs(minetest.registered_on_crafts) do
+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
end
return itemstack
end
-function minetest.craft_predict(itemstack, player, old_craft_list, craft_inv)
- for _, func in ipairs(minetest.registered_craft_predicts) do
+function core.craft_predict(itemstack, player, old_craft_list, craft_inv)
+ for _, func in ipairs(core.registered_craft_predicts) do
itemstack = func(itemstack, player, old_craft_list, craft_inv) or itemstack
end
return itemstack
-- created via itemstrings (e.g. /give)
local name
for name in pairs(forbidden_item_names) do
- minetest.registered_aliases[name] = ""
+ core.registered_aliases[name] = ""
register_alias_raw(name, "")
end
-- Deprecated:
--- Aliases for minetest.register_alias (how ironic...)
---minetest.alias_node = minetest.register_alias
---minetest.alias_tool = minetest.register_alias
---minetest.alias_craftitem = minetest.register_alias
+-- Aliases for core.register_alias (how ironic...)
+--core.alias_node = core.register_alias
+--core.alias_tool = core.register_alias
+--core.alias_craftitem = core.register_alias
--
-- Built-in node definitions. Also defined in C.
--
-minetest.register_item(":unknown", {
+core.register_item(":unknown", {
type = "none",
description = "Unknown Item",
inventory_image = "unknown_item.png",
- on_place = minetest.item_place,
- on_drop = minetest.item_drop,
+ on_place = core.item_place,
+ on_drop = core.item_drop,
groups = {not_in_creative_inventory=1},
diggable = true,
})
-minetest.register_node(":air", {
+core.register_node(":air", {
description = "Air (you hacker you!)",
inventory_image = "unknown_node.png",
wield_image = "unknown_node.png",
groups = {not_in_creative_inventory=1},
})
-minetest.register_node(":ignore", {
+core.register_node(":ignore", {
description = "Ignore (you hacker you!)",
inventory_image = "unknown_node.png",
wield_image = "unknown_node.png",
})
-- The hand (bare definition)
-minetest.register_item(":", {
+core.register_item(":", {
type = "none",
groups = {not_in_creative_inventory=1},
})
-function minetest.override_item(name, redefinition)
+function core.override_item(name, redefinition)
if redefinition.name ~= nil then
error("Attempt to redefine name of "..name.." to "..dump(redefinition.name), 2)
end
if redefinition.type ~= nil then
error("Attempt to redefine type of "..name.." to "..dump(redefinition.type), 2)
end
- local item = minetest.registered_items[name]
+ local item = core.registered_items[name]
if not item then
error("Attempt to override non-existent item "..name, 2)
end
end
-function minetest.run_callbacks(callbacks, mode, ...)
+function core.run_callbacks(callbacks, mode, ...)
assert(type(callbacks) == "table")
local cb_len = #callbacks
if cb_len == 0 then
return t, registerfunc
end
-minetest.registered_on_chat_messages, minetest.register_on_chat_message = make_registration()
-minetest.registered_globalsteps, minetest.register_globalstep = make_registration()
-minetest.registered_playerevents, minetest.register_playerevent = make_registration()
-minetest.registered_on_mapgen_inits, minetest.register_on_mapgen_init = make_registration()
-minetest.registered_on_shutdown, minetest.register_on_shutdown = make_registration()
-minetest.registered_on_punchnodes, minetest.register_on_punchnode = make_registration()
-minetest.registered_on_placenodes, minetest.register_on_placenode = make_registration()
-minetest.registered_on_dignodes, minetest.register_on_dignode = make_registration()
-minetest.registered_on_generateds, minetest.register_on_generated = make_registration()
-minetest.registered_on_newplayers, minetest.register_on_newplayer = make_registration()
-minetest.registered_on_dieplayers, minetest.register_on_dieplayer = make_registration()
-minetest.registered_on_respawnplayers, minetest.register_on_respawnplayer = make_registration()
-minetest.registered_on_prejoinplayers, minetest.register_on_prejoinplayer = make_registration()
-minetest.registered_on_joinplayers, minetest.register_on_joinplayer = make_registration()
-minetest.registered_on_leaveplayers, minetest.register_on_leaveplayer = make_registration()
-minetest.registered_on_player_receive_fields, minetest.register_on_player_receive_fields = make_registration_reverse()
-minetest.registered_on_cheats, minetest.register_on_cheat = make_registration()
-minetest.registered_on_crafts, minetest.register_on_craft = make_registration()
-minetest.registered_craft_predicts, minetest.register_craft_predict = make_registration()
-minetest.registered_on_protection_violation, minetest.register_on_protection_violation = make_registration()
+core.registered_on_chat_messages, core.register_on_chat_message = make_registration()
+core.registered_globalsteps, core.register_globalstep = make_registration()
+core.registered_playerevents, core.register_playerevent = make_registration()
+core.registered_on_mapgen_inits, core.register_on_mapgen_init = make_registration()
+core.registered_on_shutdown, core.register_on_shutdown = make_registration()
+core.registered_on_punchnodes, core.register_on_punchnode = make_registration()
+core.registered_on_placenodes, core.register_on_placenode = make_registration()
+core.registered_on_dignodes, core.register_on_dignode = make_registration()
+core.registered_on_generateds, core.register_on_generated = make_registration()
+core.registered_on_newplayers, core.register_on_newplayer = make_registration()
+core.registered_on_dieplayers, core.register_on_dieplayer = make_registration()
+core.registered_on_respawnplayers, core.register_on_respawnplayer = make_registration()
+core.registered_on_prejoinplayers, core.register_on_prejoinplayer = make_registration()
+core.registered_on_joinplayers, core.register_on_joinplayer = make_registration()
+core.registered_on_leaveplayers, core.register_on_leaveplayer = make_registration()
+core.registered_on_player_receive_fields, core.register_on_player_receive_fields = make_registration_reverse()
+core.registered_on_cheats, core.register_on_cheat = make_registration()
+core.registered_on_crafts, core.register_on_craft = make_registration()
+core.registered_craft_predicts, core.register_craft_predict = make_registration()
+core.registered_on_protection_violation, core.register_on_protection_violation = make_registration()