Document changed API and restore backwards compatibility

27e216112e changed the API of mcl_armor.register_set to facilitate
automated localization string extraction. This wasn't documented and mods
depending on the old contract were broken.

This also fixes translation of leather armor that was partially depending
on the old API contract.
This commit is contained in:
Jürgen Rühle 2024-03-24 12:02:19 +01:00
parent 460a02d6f3
commit cfc4bbdbbc
3 changed files with 28 additions and 1 deletions

View File

@ -13,6 +13,18 @@ mcl_armor.register_set({
--name of the armor material (used for generating itemstrings)
name = "dummy_armor",
--localized description of each armor piece
descriptions = {
head = S("Dummy Cap"),
torso = S("Dummy Tunic"),
legs = S("Dummy Pants"),
feet = S("Dummy Shoes"),
},
--The following MCL2 compatible legacy behavior is still supported, but
--deprecated, because it interferes with proper localization
--it is triggered when description is non nil
--[[
--description of the armor material
--do NOT translate this string, it will be concatenated will each piece of armor's description and result will be automatically fetched from your mod's translation files
description = "Dummy Armor",
@ -25,6 +37,7 @@ mcl_armor.register_set({
legs = "Pants", --default: "Leggings"
feet = "Shoes", --default: "Boots"
},
]]
--this is used to calculate each armor piece durability with the minecraft algorithm
--head durability = durability * 0.6857 + 1

View File

@ -119,6 +119,16 @@ function mcl_armor.register_set(def)
local durabilities = def.durabilities or {}
local element_groups = def.element_groups or {}
-- backwards compatibility
local descriptions = def.descriptions or {}
if def.description then
minetest.log("warning", "[mcl_armor] using the description field of armor set definitions is deprecated, please provide the localized strings in def.descriptions instead. Currently processing " .. def.name)
local S = minetest.get_translator(modname)
for name, element in pairs(mcl_armor.elements) do
descriptions[name] = S(def.description .. " " .. (descriptions[name] or element.description))
end
end
for name, element in pairs(mcl_armor.elements) do
local itemname = element.name .. "_" .. def.name
local itemstring = modname .. ":" .. itemname
@ -143,7 +153,7 @@ function mcl_armor.register_set(def)
end
minetest.register_tool(itemstring, {
description = def.descriptions[name],
description = descriptions[name],
_doc_items_longdesc = mcl_armor.longdesc,
_doc_items_usagehelp = mcl_armor.usage,
inventory_image = modname .. "_inv_" .. itemname .. ".png",

View File

@ -6,6 +6,7 @@ mcl_armor = {
elements = {
head = {
name = "helmet",
description = "Helmet", -- provided for backwards compatability
durability = 0.6857,
index = 2,
craft = function(m)
@ -18,6 +19,7 @@ mcl_armor = {
},
torso = {
name = "chestplate",
description = "Chestplate", -- provided for backwards compatability
durability = 1.0,
index = 3,
craft = function(m)
@ -30,6 +32,7 @@ mcl_armor = {
},
legs = {
name = "leggings",
description = "Leggings", -- provided for backwards compatability
durability = 0.9375,
index = 4,
craft = function(m)
@ -42,6 +45,7 @@ mcl_armor = {
},
feet = {
name = "boots",
description = "Boots", -- provided for backwards compatability
durability = 0.8125,
index = 5,
craft = function(m)