move mcl_armor_trims to mcl_armor

This commit is contained in:
chmodsayshello 2023-08-28 15:09:48 +02:00
parent 2f8bb9726b
commit da024bb4b8
11 changed files with 78 additions and 94 deletions

View File

@ -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

View File

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

View File

@ -21,3 +21,6 @@ Iron Boots=Eisenstiefel
Golden Boots=Goldstiefel
Diamond Boots=Diamantstiefel
Chain Boots=Kettenstiefel
Smithing Template '@1'=Schiedevorlage '@1'

View File

@ -46,3 +46,6 @@ 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=
#Translations for armor trims
Smithing Template '@1'=

View File

@ -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",

View File

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

View File

@ -1,2 +0,0 @@
# textdomain: mcl_armor_trims
Smithing Template '@1'=Schiedevorlage '@1'

View File

@ -1,2 +0,0 @@
# textdomain: mcl_armor_trims
Smithing Template '@1'

View File

@ -1,4 +0,0 @@
name = mcl_armor_trims
author = chmodsayshello
optional_depends = mcl_armor
depends = mcl_enchanting, mcl_core, mcl_end

View File

@ -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

View File

@ -1,2 +1,2 @@
name = mcl_smithing_table
depends = mcl_colors, mcl_formspec, mcl_armor_trims
depends = mcl_colors, mcl_formspec, mcl_armor