Merge pull request 'Merge finished item ID and hudbar fix by NO11' (#25) from testing into production

Reviewed-on: MineClone5/MineClone5#25
This commit is contained in:
kay27 2021-08-06 22:36:59 +00:00
commit d30e5b4ba1
3 changed files with 57 additions and 10 deletions

View 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")

View File

@ -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 = {
@ -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")

View File

@ -35,13 +35,13 @@ local function potions_init_icons(player)
local name = player:get_player_name() local name = player:get_player_name()
icon_ids[name] = {} icon_ids[name] = {}
for e=1, EFFECT_TYPES do for e=1, EFFECT_TYPES do
local x = -7 + -38 * e local x = -52 * e - 2
local id = player:hud_add({ local id = player:hud_add({
hud_elem_type = "image", hud_elem_type = "image",
text = "blank.png", text = "blank.png",
position = { x = 1, y = 0 }, position = { x = 1, y = 0 },
offset = { x = x, y = 272 }, offset = { x = x, y = 3 },
scale = { x = 2, y = 2 }, scale = { x = 3, y = 3 },
alignment = { x = 1, y = 1 }, alignment = { x = 1, y = 1 },
z_index = 100, z_index = 100,
}) })