From da024bb4b8bb1dedf584283fa7754a4bf07dbecf Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Mon, 28 Aug 2023 15:09:48 +0200 Subject: [PATCH] move mcl_armor_trims to mcl_armor --- mods/ITEMS/mcl_armor/api.lua | 58 +++++++++++++- mods/ITEMS/mcl_armor/init.lua | 7 ++ mods/ITEMS/mcl_armor/locale/mcl_armor.de.tr | 3 + mods/ITEMS/mcl_armor/locale/template.txt | 5 +- .../templates.lua => mcl_armor/trims.lua} | 2 +- mods/ITEMS/mcl_armor_trims/init.lua | 77 ------------------- .../locale/mcl_armor_trims.de.tr | 2 - .../ITEMS/mcl_armor_trims/locale/template.txt | 2 - mods/ITEMS/mcl_armor_trims/mod.conf | 4 - mods/ITEMS/mcl_smithing_table/init.lua | 10 +-- mods/ITEMS/mcl_smithing_table/mod.conf | 2 +- 11 files changed, 78 insertions(+), 94 deletions(-) rename mods/ITEMS/{mcl_armor_trims/templates.lua => mcl_armor/trims.lua} (96%) delete mode 100644 mods/ITEMS/mcl_armor_trims/init.lua delete mode 100644 mods/ITEMS/mcl_armor_trims/locale/mcl_armor_trims.de.tr delete mode 100644 mods/ITEMS/mcl_armor_trims/locale/template.txt delete mode 100644 mods/ITEMS/mcl_armor_trims/mod.conf diff --git a/mods/ITEMS/mcl_armor/api.lua b/mods/ITEMS/mcl_armor/api.lua index 1b9aa4f73..0d82ca440 100644 --- a/mods/ITEMS/mcl_armor/api.lua +++ b/mods/ITEMS/mcl_armor/api.lua @@ -85,6 +85,22 @@ function mcl_armor.equip_on_use(itemstack, player, pointed_thing) return mcl_armor.equip(itemstack, player) end +local function get_armor_texture(textures, name, modname, itemname, itemstring) + local core_texture = textures[name] or modname .. "_" .. itemname .. ".png" + if type(core_texture) == "function" then return core_texture end + mcl_armor.trims.core_textures[itemstring] = core_texture + local func = function(obj, itemstack) + local overlay = itemstack:get_meta():get_string("mcl_armor:trim_overlay") + local core_armor_texture = mcl_armor.trims.core_textures[itemstack:get_name()] + + if overlay == "" then return core_armor_texture end -- key not present; armor not trimmed + + return core_armor_texture .. overlay + end + + return func +end + function mcl_armor.register_set(def) local modname = minetest.get_current_modname() local S = minetest.get_translator(modname) @@ -136,7 +152,7 @@ function mcl_armor.register_set(def) _on_unequip = on_unequip_callbacks[name] or def.on_unequip, _on_break = on_break_callbacks[name] or def.on_break, _mcl_armor_element = name, - _mcl_armor_texture = textures[name] or modname .. "_" .. itemname .. ".png", + _mcl_armor_texture = get_armor_texture(textures, name, modname, itemname, itemstring), _mcl_upgradable = def._mcl_upgradable, _mcl_upgrade_item = upgrade_item }) @@ -257,3 +273,43 @@ function mcl_armor.update(obj) end end +function mcl_armor.trim(itemstack, overlay, color_string) + local def = itemstack:get_definition() + if not def._mcl_armor_texture and not mcl_armor.trims.blacklisted[itemstack:get_name()] then return end + local meta = itemstack:get_meta() + + local piece_overlay = overlay + local inv_overlay = "" + local piece_type = def._mcl_armor_element + + if piece_type == "head" then --helmet + inv_overlay = "^(helmet_trim.png" + piece_overlay = piece_overlay .. "_helmet" + elseif piece_type == "torso" then --chestplate + inv_overlay = "^(chestplate_trim.png" + piece_overlay = piece_overlay .. "_chestplate" + elseif piece_type == "legs" then --leggings + inv_overlay = "^(leggings_trim.png" + piece_overlay = piece_overlay .. "_leggings" + elseif piece_type == "feet" then --boots + inv_overlay = "^(boots_trim.png" + piece_overlay = piece_overlay .. "_boots" + end + local color = mcl_armor.trims.colors[color_string] + inv_overlay = inv_overlay .. "^[colorize:" .. color .. ":150)" + piece_overlay = piece_overlay .. ".png" + + piece_overlay = "^(" .. piece_overlay .. "^[colorize:" .. color .. ":150)" + + meta:set_string("mcl_armor:trim_overlay" , piece_overlay) -- set textures to render on the player, will work for clients below 5.8 as well + meta:set_string("mcl_armor:inv", inv_overlay) -- make 5.8+ clients display the fancy inv image, older ones will see no change in the *inventory* image + meta:set_string("inventory_image", def.inventory_image .. inv_overlay) -- dont use reload_inv_image as it's a one liner in this enviorment +end + +function mcl_armor.reload_trim_inv_image(itemstack) + local meta = itemstack:get_meta() + local inv_overlay = meta:get_string("mcl_armor:inv") + local def = itemstack:get_definition() + if inv_overlay == "" then return end + meta:set_string("inventory_image", def.inventory_image .. inv_overlay) +end \ No newline at end of file diff --git a/mods/ITEMS/mcl_armor/init.lua b/mods/ITEMS/mcl_armor/init.lua index 799bf2e9c..e85158f6c 100644 --- a/mods/ITEMS/mcl_armor/init.lua +++ b/mods/ITEMS/mcl_armor/init.lua @@ -57,6 +57,12 @@ mcl_armor = { } }, player_view_range_factors = {}, + trims = { + core_textures = {}, + blacklisted = {["mcl_armor:elytra"]=true, ["mcl_armor:elytra_enchanted"]=true}, + overlays = {"sentry","dune","coast","wild","tide","ward","vex","rib","snout","eye","spire"}, + colors = {["amethyst"]="#8246a5",["gold"]="#ce9627",["emerald"]="#1b9958",["copper"]="#c36447",["diamond"]="#5faed8",["iron"]="#938e88",["lapis"]="#1c306b",["netherite"]="#302a26",["quartz"]="#c9bcb9",["redstone"]="#af2c23"}, + }, } local modpath = minetest.get_modpath("mcl_armor") @@ -66,3 +72,4 @@ dofile(modpath .. "/player.lua") dofile(modpath .. "/damage.lua") dofile(modpath .. "/register.lua") dofile(modpath .. "/alias.lua") +dofile(modpath .. "/trims.lua") diff --git a/mods/ITEMS/mcl_armor/locale/mcl_armor.de.tr b/mods/ITEMS/mcl_armor/locale/mcl_armor.de.tr index 09da3a9cc..312b9fafb 100644 --- a/mods/ITEMS/mcl_armor/locale/mcl_armor.de.tr +++ b/mods/ITEMS/mcl_armor/locale/mcl_armor.de.tr @@ -21,3 +21,6 @@ Iron Boots=Eisenstiefel Golden Boots=Goldstiefel Diamond Boots=Diamantstiefel Chain Boots=Kettenstiefel + + +Smithing Template '@1'=Schiedevorlage '@1' \ No newline at end of file diff --git a/mods/ITEMS/mcl_armor/locale/template.txt b/mods/ITEMS/mcl_armor/locale/template.txt index 4b4ad8385..64318f41b 100644 --- a/mods/ITEMS/mcl_armor/locale/template.txt +++ b/mods/ITEMS/mcl_armor/locale/template.txt @@ -45,4 +45,7 @@ Protection= Reduces most types of damage by 4% for each level.= Thorns= Reflects some of the damage taken when hit, at the cost of reducing durability with each proc.= -Aqua Affinity= \ No newline at end of file +Aqua Affinity= + +#Translations for armor trims +Smithing Template '@1'= \ No newline at end of file diff --git a/mods/ITEMS/mcl_armor_trims/templates.lua b/mods/ITEMS/mcl_armor/trims.lua similarity index 96% rename from mods/ITEMS/mcl_armor_trims/templates.lua rename to mods/ITEMS/mcl_armor/trims.lua index 6a8c23667..c29d16bb6 100644 --- a/mods/ITEMS/mcl_armor_trims/templates.lua +++ b/mods/ITEMS/mcl_armor/trims.lua @@ -1,7 +1,7 @@ local mod_registername = minetest.get_current_modname() .. ":" local S = minetest.get_translator(modname) -for _, template_name in pairs(mcl_armor_trims.overlays) do +for _, template_name in pairs(mcl_armor.trims.overlays) do minetest.register_craftitem(mod_registername .. template_name, { description = S("Smithing Template '@1'", template_name), inventory_image = template_name .. "_armor_trim_smithing_template.png", diff --git a/mods/ITEMS/mcl_armor_trims/init.lua b/mods/ITEMS/mcl_armor_trims/init.lua deleted file mode 100644 index dd9ca8785..000000000 --- a/mods/ITEMS/mcl_armor_trims/init.lua +++ /dev/null @@ -1,77 +0,0 @@ ---TODO: put this mod entirely into mcl_armor - -mcl_armor_trims = { - blacklisted = {["mcl_farming:pumpkin_face"]=true, ["mcl_armor:elytra"]=true, ["mcl_armor:elytra_enchanted"]=true}, - overlays = {"sentry","dune","coast","wild","tide","ward","vex","rib","snout","eye","spire"}, - colors = {["amethyst"]="#8246a5",["gold"]="#ce9627",["emerald"]="#1b9958",["copper"]="#c36447",["diamond"]="#5faed8",["iron"]="#938e88",["lapis"]="#1c306b",["netherite"]="#302a26",["quartz"]="#c9bcb9",["redstone"]="#af2c23"}, - old_textures = {} -} - -local function override_items() - for itemname, itemdef in pairs(minetest.registered_tools) do - if itemdef._mcl_armor_texture and type(itemdef._mcl_armor_texture) == "string" and not mcl_armor_trims.blacklisted[itemname] then - mcl_armor_trims.old_textures[itemname] = itemdef._mcl_armor_texture - minetest.override_item(itemname, { - _mcl_armor_texture = function(obj, itemstack) - local overlay = itemstack:get_meta():get_string("mcl_armor_trims:trim_overlay") - local old_armor_texture = mcl_armor_trims.old_textures[itemstack:get_name()] - if type(old_armor_texture) == "function" then - old_armor_texture = old_armor_texture(obj, itemstack) - end - - if overlay == "" then -- key not present; armor not trimmed - return old_armor_texture - end - - return old_armor_texture .. overlay - end - }) - end - end -end - -function mcl_armor_trims.trim(itemstack, overlay, color_string) - local def = itemstack:get_definition() - if not def._mcl_armor_texture and not mcl_armor_trims.blacklisted[itemstack:get_name()] then - return - end - local meta = itemstack:get_meta() - - local piece_overlay = overlay - local inv_overlay = "" - local piece_type = def._mcl_armor_element - - if piece_type == "head" then --helmet - inv_overlay = "^(helmet_trim.png" - piece_overlay = piece_overlay .. "_helmet" - elseif piece_type == "torso" then --chestplate - inv_overlay = "^(chestplate_trim.png" - piece_overlay = piece_overlay .. "_chestplate" - elseif piece_type == "legs" then --leggings - inv_overlay = "^(leggings_trim.png" - piece_overlay = piece_overlay .. "_leggings" - elseif piece_type == "feet" then --boots - inv_overlay = "^(boots_trim.png" - piece_overlay = piece_overlay .. "_boots" - end - local color = mcl_armor_trims.colors[color_string] - inv_overlay = inv_overlay .. "^[colorize:" .. color .. ":150)" - piece_overlay = piece_overlay .. ".png" - - piece_overlay = "^(" .. piece_overlay .. "^[colorize:" .. color .. ":150)" - - meta:set_string("mcl_armor_trims:trim_overlay" , piece_overlay) -- set textures to render on the player, will work for clients below 5.8 as well - meta:set_string("mcl_armor_trims:inv", inv_overlay) -- make 5.8+ clients display the fancy inv image, older ones will see no change in the *inventory* image - meta:set_string("inventory_image", def.inventory_image .. inv_overlay) -- dont use reload_inv_image as it's a one liner in this enviorment -end - -function mcl_armor_trims.reload_inv_image(itemstack) - local meta = itemstack:get_meta() - local inv_overlay = meta:get_string("mcl_armor_trims:inv") - local def = itemstack:get_definition() - if inv_overlay == "" then return end - meta:set_string("inventory_image", def.inventory_image .. inv_overlay) -end - -minetest.register_on_mods_loaded(override_items) -dofile(minetest.get_modpath(minetest.get_current_modname()).."/templates.lua") \ No newline at end of file diff --git a/mods/ITEMS/mcl_armor_trims/locale/mcl_armor_trims.de.tr b/mods/ITEMS/mcl_armor_trims/locale/mcl_armor_trims.de.tr deleted file mode 100644 index 71b363ec6..000000000 --- a/mods/ITEMS/mcl_armor_trims/locale/mcl_armor_trims.de.tr +++ /dev/null @@ -1,2 +0,0 @@ -# textdomain: mcl_armor_trims -Smithing Template '@1'=Schiedevorlage '@1' diff --git a/mods/ITEMS/mcl_armor_trims/locale/template.txt b/mods/ITEMS/mcl_armor_trims/locale/template.txt deleted file mode 100644 index 58eef9444..000000000 --- a/mods/ITEMS/mcl_armor_trims/locale/template.txt +++ /dev/null @@ -1,2 +0,0 @@ -# textdomain: mcl_armor_trims -Smithing Template '@1' diff --git a/mods/ITEMS/mcl_armor_trims/mod.conf b/mods/ITEMS/mcl_armor_trims/mod.conf deleted file mode 100644 index de381b16f..000000000 --- a/mods/ITEMS/mcl_armor_trims/mod.conf +++ /dev/null @@ -1,4 +0,0 @@ -name = mcl_armor_trims -author = chmodsayshello -optional_depends = mcl_armor -depends = mcl_enchanting, mcl_core, mcl_end \ No newline at end of file diff --git a/mods/ITEMS/mcl_smithing_table/init.lua b/mods/ITEMS/mcl_smithing_table/init.lua index 541f46159..528b6843d 100644 --- a/mods/ITEMS/mcl_smithing_table/init.lua +++ b/mods/ITEMS/mcl_smithing_table/init.lua @@ -20,7 +20,7 @@ function mcl_smithing_table.upgrade_item_netherite(itemstack) end itemstack:set_name(upgrade_item) - mcl_armor_trims.reload_inv_image(itemstack) + mcl_armor.reload_trim_inv_image(itemstack) -- Reload the ToolTips of the tool @@ -72,10 +72,10 @@ function mcl_smithing_table.upgrade_trimmed(itemstack, color_mineral, template) local material_name = color_mineral:get_name() material_name = smithing_materials[material_name] - local overlay = template:get_name():gsub("mcl_armor_trims:","") + local overlay = template:get_name():gsub("mcl_armor:","") --trimming process - mcl_armor_trims.trim(itemstack, overlay, material_name) + mcl_armor.trim(itemstack, overlay, material_name) --itemstack:set_name(itemstack:get_name() .. "_trimmed_" .. overlay .. "_" .. material_name) tt.reload_itemstack_description(itemstack) @@ -137,13 +137,13 @@ minetest.register_node("mcl_smithing_table:table", { if listname == "upgrade_item" and string.find(stack:get_name(),"mcl_armor:") -- allow any armor piece to go in (in case the player wants to trim them) - and not mcl_armor_trims.blacklisted[stack:get_name()] + and not mcl_armor.trims.blacklisted[stack:get_name()] or listname == "mineral" and mcl_smithing_table.is_smithing_mineral(stack:get_name()) or listname == "template" - and string.find(stack:get_name(),"mcl_armor_trims") + and string.find(stack:get_name(),"mcl_armor") then return stack:get_count() end diff --git a/mods/ITEMS/mcl_smithing_table/mod.conf b/mods/ITEMS/mcl_smithing_table/mod.conf index c38c8ef36..d947b850e 100644 --- a/mods/ITEMS/mcl_smithing_table/mod.conf +++ b/mods/ITEMS/mcl_smithing_table/mod.conf @@ -1,2 +1,2 @@ name = mcl_smithing_table -depends = mcl_colors, mcl_formspec, mcl_armor_trims +depends = mcl_colors, mcl_formspec, mcl_armor