From 61c6d6e2764ad154194896fd4e6337c05f792b9a Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 28 Apr 2021 12:00:44 +0200 Subject: [PATCH 1/2] Add per element (un)equip callbacks --- mods/ITEMS/mcl_armor/api.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_armor/api.lua b/mods/ITEMS/mcl_armor/api.lua index 4d66868076..b1645ae3e5 100644 --- a/mods/ITEMS/mcl_armor/api.lua +++ b/mods/ITEMS/mcl_armor/api.lua @@ -90,6 +90,8 @@ function mcl_armor.register_set(def) local S = minetest.get_translator(modname) local descriptions = def.descriptions or {} local groups = def.groups or {} + local on_equip_callbacks = def.on_equip_callbacks or {} + local on_unequip_callbacks = def.on_unequip_callbacks or {} for name, element in pairs(mcl_armor.elements) do local itemname = element.name .. "_" .. def.name local itemstring = modname .. ":" .. itemname @@ -117,8 +119,8 @@ function mcl_armor.register_set(def) }, on_place = mcl_armor.equip_on_use, on_secondary_use = mcl_armor.equip_on_use, - _on_equip = def.on_equip, - _on_unequip = def.on_unequip, + _on_equip = on_equip_callbacks[name] or def.on_equip, + _on_unequip = on_unequip_callbacks[name] or def.on_unequip, _mcl_armor_element = name, _mcl_armor_texture = modname .. "_" .. itemname .. ".png", _mcl_armor_preview = modname .. "_" .. itemname .. "_preview.png", From 13a0fa231459631aab137457b81c0f2aa5861bf7 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 28 Apr 2021 12:16:01 +0200 Subject: [PATCH 2/2] Implement #1665 --- mods/ITEMS/mcl_armor/api.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_armor/api.lua b/mods/ITEMS/mcl_armor/api.lua index b1645ae3e5..2e5ba11120 100644 --- a/mods/ITEMS/mcl_armor/api.lua +++ b/mods/ITEMS/mcl_armor/api.lua @@ -92,6 +92,10 @@ function mcl_armor.register_set(def) local groups = def.groups or {} local on_equip_callbacks = def.on_equip_callbacks or {} local on_unequip_callbacks = def.on_unequip_callbacks or {} + local textures = def.textures or {} + local previews = def.previews or {} + local durabilities = def.durabilities or {} + for name, element in pairs(mcl_armor.elements) do local itemname = element.name .. "_" .. def.name local itemstring = modname .. ":" .. itemname @@ -103,7 +107,7 @@ function mcl_armor.register_set(def) groups.combat_armor = 1 groups.mcl_armor_points = def.points[name] groups.mcl_armor_toughness = def.toughness - groups.mcl_armor_uses = math.floor(def.durability * element.durability) + 1 + groups.mcl_armor_uses = (durabilities[name] or math.floor(def.durability * element.durability)) + 1 groups.enchantability = def.enchantability minetest.register_tool(itemstring, { @@ -122,8 +126,8 @@ function mcl_armor.register_set(def) _on_equip = on_equip_callbacks[name] or def.on_equip, _on_unequip = on_unequip_callbacks[name] or def.on_unequip, _mcl_armor_element = name, - _mcl_armor_texture = modname .. "_" .. itemname .. ".png", - _mcl_armor_preview = modname .. "_" .. itemname .. "_preview.png", + _mcl_armor_texture = textures[name] or modname .. "_" .. itemname .. ".png", + _mcl_armor_preview = previews[name] or modname .. "_" .. itemname .. "_preview.png", }) if def.craft_material then