forked from VoxeLibre/VoxeLibre
meta based: proof of concept
This commit is contained in:
parent
8176e7319f
commit
2f8bb9726b
|
@ -1,57 +1,77 @@
|
||||||
|
--TODO: put this mod entirely into mcl_armor
|
||||||
|
|
||||||
mcl_armor_trims = {
|
mcl_armor_trims = {
|
||||||
blacklisted = {["mcl_farming:pumpkin_face"]=true, ["mcl_armor:elytra"]=true, ["mcl_armor:elytra_enchanted"]=true},
|
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"},
|
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"}
|
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 define_items()
|
local function override_items()
|
||||||
local register_list = {}
|
|
||||||
for itemname, itemdef in pairs(minetest.registered_tools) do
|
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
|
if itemdef._mcl_armor_texture and type(itemdef._mcl_armor_texture) == "string" and not mcl_armor_trims.blacklisted[itemname] then
|
||||||
for _, overlay in pairs(mcl_armor_trims.overlays) do
|
mcl_armor_trims.old_textures[itemname] = itemdef._mcl_armor_texture
|
||||||
for mineral, color in pairs(mcl_armor_trims.colors) do
|
minetest.override_item(itemname, {
|
||||||
local new_name = itemname .. "_trimmed_" .. overlay .. "_" .. mineral
|
_mcl_armor_texture = function(obj, itemstack)
|
||||||
local new_def = table.copy(itemdef)
|
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 piece_overlay = overlay
|
||||||
local invOverlay = ""
|
local inv_overlay = ""
|
||||||
if string.find(itemname,"helmet") then
|
local piece_type = def._mcl_armor_element
|
||||||
invOverlay = "^(helmet_trim.png"
|
|
||||||
|
if piece_type == "head" then --helmet
|
||||||
|
inv_overlay = "^(helmet_trim.png"
|
||||||
piece_overlay = piece_overlay .. "_helmet"
|
piece_overlay = piece_overlay .. "_helmet"
|
||||||
elseif string.find(itemname,"chestplate") then
|
elseif piece_type == "torso" then --chestplate
|
||||||
invOverlay = "^(chestplate_trim.png"
|
inv_overlay = "^(chestplate_trim.png"
|
||||||
piece_overlay = piece_overlay .. "_chestplate"
|
piece_overlay = piece_overlay .. "_chestplate"
|
||||||
elseif string.find(itemname,"leggings") then
|
elseif piece_type == "legs" then --leggings
|
||||||
invOverlay = "^(leggings_trim.png"
|
inv_overlay = "^(leggings_trim.png"
|
||||||
piece_overlay = piece_overlay .. "_leggings"
|
piece_overlay = piece_overlay .. "_leggings"
|
||||||
elseif string.find(itemname,"boots") then
|
elseif piece_type == "feet" then --boots
|
||||||
invOverlay = "^(boots_trim.png"
|
inv_overlay = "^(boots_trim.png"
|
||||||
piece_overlay = piece_overlay .. "_boots"
|
piece_overlay = piece_overlay .. "_boots"
|
||||||
end
|
end
|
||||||
|
local color = mcl_armor_trims.colors[color_string]
|
||||||
invOverlay = invOverlay .. "^[colorize:" .. color .. ":150)"
|
inv_overlay = inv_overlay .. "^[colorize:" .. color .. ":150)"
|
||||||
piece_overlay = piece_overlay .. ".png"
|
piece_overlay = piece_overlay .. ".png"
|
||||||
|
|
||||||
new_def.groups.not_in_creative_inventory = 1
|
piece_overlay = "^(" .. piece_overlay .. "^[colorize:" .. color .. ":150)"
|
||||||
new_def.groups.not_in_craft_guide = 1
|
|
||||||
new_def._mcl_armor_texture = new_def._mcl_armor_texture .. "^(" .. piece_overlay .. "^[colorize:" .. color .. ":150)"
|
|
||||||
new_def.inventory_image = itemdef.inventory_image .. invOverlay
|
|
||||||
|
|
||||||
if string.find(itemname, "_enchanted") then
|
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
|
||||||
new_def._mcl_enchanting_enchanted_tool = new_name
|
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
|
||||||
else
|
meta:set_string("inventory_image", def.inventory_image .. inv_overlay) -- dont use reload_inv_image as it's a one liner in this enviorment
|
||||||
new_def._mcl_enchanting_enchanted_tool = itemname .. "_enchanted_trimmed_" .. overlay .. "_" .. mineral
|
|
||||||
end
|
|
||||||
register_list[":" .. new_name] = new_def
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for new_name, new_def in pairs(register_list) do
|
function mcl_armor_trims.reload_inv_image(itemstack)
|
||||||
minetest.register_tool(new_name, new_def)
|
local meta = itemstack:get_meta()
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
minetest.register_on_mods_loaded(define_items)
|
minetest.register_on_mods_loaded(override_items)
|
||||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/templates.lua")
|
dofile(minetest.get_modpath(minetest.get_current_modname()).."/templates.lua")
|
|
@ -20,6 +20,7 @@ function mcl_smithing_table.upgrade_item_netherite(itemstack)
|
||||||
end
|
end
|
||||||
|
|
||||||
itemstack:set_name(upgrade_item)
|
itemstack:set_name(upgrade_item)
|
||||||
|
mcl_armor_trims.reload_inv_image(itemstack)
|
||||||
|
|
||||||
-- Reload the ToolTips of the tool
|
-- Reload the ToolTips of the tool
|
||||||
|
|
||||||
|
@ -74,7 +75,8 @@ function mcl_smithing_table.upgrade_trimmed(itemstack, color_mineral, template)
|
||||||
local overlay = template:get_name():gsub("mcl_armor_trims:","")
|
local overlay = template:get_name():gsub("mcl_armor_trims:","")
|
||||||
|
|
||||||
--trimming process
|
--trimming process
|
||||||
itemstack:set_name(itemstack:get_name() .. "_trimmed_" .. overlay .. "_" .. material_name)
|
mcl_armor_trims.trim(itemstack, overlay, material_name)
|
||||||
|
--itemstack:set_name(itemstack:get_name() .. "_trimmed_" .. overlay .. "_" .. material_name)
|
||||||
tt.reload_itemstack_description(itemstack)
|
tt.reload_itemstack_description(itemstack)
|
||||||
|
|
||||||
return itemstack
|
return itemstack
|
||||||
|
|
Loading…
Reference in New Issue