mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-12-23 16:39:33 +01:00
Merge pull request 'Fix #1842 (several fixes for mcl_item_id
)' (#1843) from NO11/MineClone2:item_id_fixes into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/1843
This commit is contained in:
commit
289ba826ba
2 changed files with 54 additions and 7 deletions
24
mods/HELP/mcl_item_id/API.md
Normal file
24
mods/HELP/mcl_item_id/API.md
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# mcl_item_id
|
||||||
|
Show the item ID of an item in the description.
|
||||||
|
With this API, you can register a different name space than "mineclone" for your mod.
|
||||||
|
|
||||||
|
## mcl_item_id.set_mod_namespace(modname, namespace)
|
||||||
|
Set a name space for all items in a mod.
|
||||||
|
|
||||||
|
* param1: the modname
|
||||||
|
* param2: (optional) string of the desired name space, if nil, it is the name of the mod
|
||||||
|
|
||||||
|
## mcl_item_id.get_mod_namespace(modname)
|
||||||
|
Get the name space of a mod registered with mcl_item_id.set_mod_namespace(modname, namespace).
|
||||||
|
|
||||||
|
* param1: the modname
|
||||||
|
|
||||||
|
### Examples:
|
||||||
|
|
||||||
|
The name of the mod is "mod" which registered an item called "mod:itemname".
|
||||||
|
|
||||||
|
* mcl_item_id.set_mod_namespace("mod", "mymod") will show "mymod:itemname" in the description of "mod:itemname"
|
||||||
|
* mcl_item_id.set_mod_namespace(minetest.get_current_modname()) will show "mod:itemname" in the description of "mod:itemname"
|
||||||
|
* mcl_item_id.get_mod_namespace(minetest.get_current_modname()) will return "mod"
|
||||||
|
|
||||||
|
(If no namespace is set by a mod, mcl_item_id.get_mod_namespace(minetest.get_current_modname()) will return "mineclone")
|
|
@ -1,6 +1,26 @@
|
||||||
|
mcl_item_id = {
|
||||||
|
mod_namespaces = {},
|
||||||
|
}
|
||||||
|
|
||||||
local game = "mineclone"
|
local game = "mineclone"
|
||||||
|
|
||||||
|
function mcl_item_id.set_mod_namespace(modname, namespace)
|
||||||
|
local namespace = namespace or modname
|
||||||
|
mcl_item_id.mod_namespaces[modname] = namespace
|
||||||
|
end
|
||||||
|
|
||||||
|
function mcl_item_id.get_mod_namespace(modname)
|
||||||
|
local namespace = mcl_item_id.mod_namespaces[modname]
|
||||||
|
if namespace then
|
||||||
|
return namespace
|
||||||
|
else
|
||||||
|
return game
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local same_id = {
|
local same_id = {
|
||||||
|
enchanting = { "table" },
|
||||||
|
experience = { "bottle" },
|
||||||
heads = { "skeleton", "zombie", "creeper", "wither_skeleton" },
|
heads = { "skeleton", "zombie", "creeper", "wither_skeleton" },
|
||||||
mobitems = { "rabbit", "chicken" },
|
mobitems = { "rabbit", "chicken" },
|
||||||
walls = {
|
walls = {
|
||||||
|
@ -10,7 +30,7 @@ local same_id = {
|
||||||
"stonebrick", "stonebrickmossy",
|
"stonebrick", "stonebrickmossy",
|
||||||
},
|
},
|
||||||
wool = {
|
wool = {
|
||||||
"black", "blue", "brown", "cyan", "green",
|
"black", "blue", "brown", "cyan", "green",
|
||||||
"grey", "light_blue", "lime", "magenta", "orange",
|
"grey", "light_blue", "lime", "magenta", "orange",
|
||||||
"pink", "purple", "red", "silver", "white", "yellow",
|
"pink", "purple", "red", "silver", "white", "yellow",
|
||||||
},
|
},
|
||||||
|
@ -18,9 +38,11 @@ local same_id = {
|
||||||
|
|
||||||
tt.register_snippet(function(itemstring)
|
tt.register_snippet(function(itemstring)
|
||||||
local def = minetest.registered_items[itemstring]
|
local def = minetest.registered_items[itemstring]
|
||||||
local desc = def.description
|
|
||||||
local item_split = itemstring:find(":")
|
local item_split = itemstring:find(":")
|
||||||
local new_id = game .. itemstring:sub(item_split)
|
local id_string = itemstring:sub(item_split)
|
||||||
|
local id_modname = itemstring:sub(1, item_split - 1)
|
||||||
|
local new_id = game .. id_string
|
||||||
|
local mod_namespace = mcl_item_id.get_mod_namespace(id_modname)
|
||||||
for mod, ids in pairs(same_id) do
|
for mod, ids in pairs(same_id) do
|
||||||
for _, id in pairs(ids) do
|
for _, id in pairs(ids) do
|
||||||
if itemstring == "mcl_" .. mod .. ":" .. id then
|
if itemstring == "mcl_" .. mod .. ":" .. id then
|
||||||
|
@ -28,12 +50,13 @@ tt.register_snippet(function(itemstring)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if new_id ~= game .. ":book_enchanted" then
|
if mod_namespace ~= game then
|
||||||
|
new_id = mod_namespace .. id_string
|
||||||
|
end
|
||||||
|
if mod_namespace ~= id_modname then
|
||||||
minetest.register_alias_force(new_id, itemstring)
|
minetest.register_alias_force(new_id, itemstring)
|
||||||
end
|
end
|
||||||
if minetest.settings:get_bool("mcl_item_id_debug", false) then
|
if minetest.settings:get_bool("mcl_item_id_debug", false) then
|
||||||
return new_id, "#555555"
|
return new_id, "#555555"
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_alias_force(game .. ":book_enchanted", "mcl_enchanting:book_enchanted")
|
|
Loading…
Reference in a new issue