From caa82c40c9290ef5942159e28518da2825ccae79 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Tue, 10 May 2022 15:55:56 +0200 Subject: [PATCH 1/5] Colored Leather Armor --- mods/ITEMS/mcl_armor/init.lua | 1 + mods/ITEMS/mcl_armor/leather.lua | 110 ++++++++++++++++++++++++++++++ mods/ITEMS/mcl_armor/mod.conf | 2 +- mods/ITEMS/mcl_armor/register.lua | 19 ------ 4 files changed, 112 insertions(+), 20 deletions(-) create mode 100644 mods/ITEMS/mcl_armor/leather.lua diff --git a/mods/ITEMS/mcl_armor/init.lua b/mods/ITEMS/mcl_armor/init.lua index 402d9eef3..8f592d3ac 100644 --- a/mods/ITEMS/mcl_armor/init.lua +++ b/mods/ITEMS/mcl_armor/init.lua @@ -71,5 +71,6 @@ dofile(modpath .. "/api.lua") dofile(modpath .. "/player.lua") dofile(modpath .. "/damage.lua") dofile(modpath .. "/register.lua") +dofile(modpath .. "/leather.lua") dofile(modpath .. "/alias.lua") dofile(modpath .. "/trims.lua") diff --git a/mods/ITEMS/mcl_armor/leather.lua b/mods/ITEMS/mcl_armor/leather.lua new file mode 100644 index 000000000..58ea5cc4b --- /dev/null +++ b/mods/ITEMS/mcl_armor/leather.lua @@ -0,0 +1,110 @@ +local C = minetest.colorize + +local colors = { + -- { ID, decription, wool, dye } + { "red", "Red", "mcl_dye:red", "#951d1d" }, + { "blue", "Blue", "mcl_dye:blue", "#2a2c94" }, + { "cyan", "Cyan", "mcl_dye:cyan", "#0d7d8e" }, + { "grey", "Grey", "mcl_dye:dark_grey", "#363a3f" }, + { "silver", "Light Grey", "mcl_dye:grey", "#818177" }, + { "black", "Black", "mcl_dye:black", "#020307" }, + { "yellow", "Yellow", "mcl_dye:yellow", "#f2b410" }, + { "green", "Green", "mcl_dye:dark_green", "#495d20" }, + { "magenta", "Magenta", "mcl_dye:magenta", "#ae2ea4" }, + { "orange", "Orange", "mcl_dye:orange", "#e36501" }, + { "purple", "Purple", "mcl_dye:violet", "#681ba1" }, + { "brown", "Brown", "mcl_dye:brown", "#623b1a" }, + { "pink", "Pink", "mcl_dye:pink", "#d66691" }, + { "lime", "Lime", "mcl_dye:green", "#60ad13" }, + { "light_blue", "Light Blue", "mcl_dye:lightblue", "#1f8eca" }, + { "white", "White", "mcl_dye:white", "#d1d7d8" }, +} + +--local function get_color_rgb(color) +-- return tonumber(str.sub(first, 2, 3)), tonumber(str.sub(first, 4, 5)), tonumber(str.sub(first, 6, 7)) +--end + + +local function calculate_color(first, last) + --local first_r = tonumber(str.sub(first, 2, 3)) + --local first_g = tonumber(str.sub(first, 4, 5)) + return tonumber(first)*tonumber(last) +end + +local function get_texture_function(texture) + local function get_texture(_, itemstack) + local out + local color = itemstack:get_meta():get_string("color") + if color == "" or color == nil then + out = texture + else + out = texture.."^[multiply:"..color + end + + if mcl_enchanting.is_enchanted(itemstack:get_name()) then + minetest.chat_send_all(out..mcl_enchanting.overlay) + return out..mcl_enchanting.overlay + else + minetest.chat_send_all(out) + return out + end + end + return get_texture +end + +mcl_armor.register_set({ + name = "leather", + description = "Leather", + descriptions = { + head = "Cap", + torso = "Tunic", + legs = "Pants", + }, + durability = 80, + enchantability = 15, + points = { + head = 1, + torso = 3, + legs = 2, + feet = 1, + }, + textures = { + head = get_texture_function("mcl_armor_helmet_leather.png"), + torso = get_texture_function("mcl_armor_chestplate_leather.png"), + legs = get_texture_function("mcl_armor_leggings_leather.png"), + feet = get_texture_function("mcl_armor_boots_leather.png"), + }, + craft_material = "mcl_mobitems:leather", +}) + +tt.register_priority_snippet(function(_, _, itemstack) + if not itemstack or not itemstack:get_definition().groups.armor_leather == 1 then + return + end + local color = itemstack:get_meta():get_string("color") + if color and color ~= "" then + --TODO: replace by just "Dyed" + local text = C(mcl_colors.GRAY, "Dyed: "..color) + return text, false + end +end) + + +-- This command is only temporary + +minetest.register_chatcommand("color_leather", { + params = "", + description = "Colorize a leather armor", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if player then + local item = player:get_wielded_item() + item:get_meta():set_string("color", param) + tt.reload_itemstack_description(item) + player:set_wielded_item(item) + return true, "Done." + else + return false, "Player isn't online" + end + end, +}) \ No newline at end of file diff --git a/mods/ITEMS/mcl_armor/mod.conf b/mods/ITEMS/mcl_armor/mod.conf index cfbaa831f..48e00a30c 100644 --- a/mods/ITEMS/mcl_armor/mod.conf +++ b/mods/ITEMS/mcl_armor/mod.conf @@ -1,5 +1,5 @@ name = mcl_armor author = stu description = Adds craftable armor that is visible to other players. -depends = mcl_core, mcl_player, mcl_enchanting, mcl_damage, mcl_grindstone +depends = mcl_core, mcl_player, mcl_enchanting, mcl_damage, mcl_colors, mcl_grindstone optional_depends = mcl_fire, ethereal, bakedclay diff --git a/mods/ITEMS/mcl_armor/register.lua b/mods/ITEMS/mcl_armor/register.lua index f4f1fb4d0..4c4330f3e 100644 --- a/mods/ITEMS/mcl_armor/register.lua +++ b/mods/ITEMS/mcl_armor/register.lua @@ -1,24 +1,5 @@ local S = minetest.get_translator(minetest.get_current_modname()) -mcl_armor.register_set({ - name = "leather", - description = "Leather", - descriptions = { - head = "Cap", - torso = "Tunic", - legs = "Pants", - }, - durability = 80, - enchantability = 15, - points = { - head = 1, - torso = 3, - legs = 2, - feet = 1, - }, - craft_material = "mcl_mobitems:leather", -}) - mcl_armor.register_set({ name = "gold", description = "Golden", From 3d799266c3b1edc477b73b932832dc31d5a680d8 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Thu, 25 Jan 2024 09:20:17 +0100 Subject: [PATCH 2/5] Finished leather armor colorizing --- mods/ITEMS/mcl_armor/leather.lua | 81 +++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 18 deletions(-) diff --git a/mods/ITEMS/mcl_armor/leather.lua b/mods/ITEMS/mcl_armor/leather.lua index 58ea5cc4b..9466de77d 100644 --- a/mods/ITEMS/mcl_armor/leather.lua +++ b/mods/ITEMS/mcl_armor/leather.lua @@ -20,25 +20,36 @@ local colors = { { "white", "White", "mcl_dye:white", "#d1d7d8" }, } ---local function get_color_rgb(color) --- return tonumber(str.sub(first, 2, 3)), tonumber(str.sub(first, 4, 5)), tonumber(str.sub(first, 6, 7)) ---end +-- #608b03 from #495d20 +local function color_string_to_table(colorstring) + return { + r = tonumber(colorstring:sub(2,3), 16), -- 16 as second parameter allows hexadecimal + g = tonumber(colorstring:sub(4,5), 16), + b = tonumber(colorstring:sub(6,7), 16), + } +end + +local function av(a, b) + return (a + b)/2 +end local function calculate_color(first, last) - --local first_r = tonumber(str.sub(first, 2, 3)) - --local first_g = tonumber(str.sub(first, 4, 5)) - return tonumber(first)*tonumber(last) + return { + r = av(first.r, last.r), + g = av(first.g, last.g), + b = av(first.b, last.b), + } end local function get_texture_function(texture) local function get_texture(_, itemstack) local out - local color = itemstack:get_meta():get_string("color") + local color = itemstack:get_meta():get_string("mcl_armor:color") if color == "" or color == nil then out = texture else - out = texture.."^[multiply:"..color + out = texture.."^[hsl:0:100:50^[multiply:"..color end if mcl_enchanting.is_enchanted(itemstack:get_name()) then @@ -52,6 +63,36 @@ local function get_texture_function(texture) return get_texture end +function mcl_armor.colorize_leather_armor(itemstack, colorstring) + local color = color_string_to_table(colorstring) + local meta = itemstack:get_meta() + local old_color = meta:get_string("mcl_armor:color") + if old_color ~= "" then + color = calculate_color( + color_string_to_table(minetest.colorspec_to_colorstring(old_color)), + color + ) + colorstring = minetest.colorspec_to_colorstring(color) + end + meta:set_string("mcl_armor:color", colorstring) + meta:set_string("inventory_image", + itemstack:get_definition().inventory_image .. "^[hsl:0:100:50^[multiply:" .. colorstring + ) + tt.reload_itemstack_description(itemstack) + return itemstack +end + +function mcl_armor.wash_leather_armor(itemstack) + if not itemstack or not itemstack:get_definition().groups.armor_leather == 1 then + return + end + local meta = itemstack:get_meta() + meta:set_string("mcl_armor:color", "") + meta:set_string("inventory_image", "") + tt.reload_itemstack_description(itemstack) + return itemstack +end + mcl_armor.register_set({ name = "leather", description = "Leather", @@ -81,30 +122,34 @@ tt.register_priority_snippet(function(_, _, itemstack) if not itemstack or not itemstack:get_definition().groups.armor_leather == 1 then return end - local color = itemstack:get_meta():get_string("color") + local color = itemstack:get_meta():get_string("mcl_armor:color") if color and color ~= "" then - --TODO: replace by just "Dyed" local text = C(mcl_colors.GRAY, "Dyed: "..color) return text, false end end) --- This command is only temporary - minetest.register_chatcommand("color_leather", { params = "", - description = "Colorize a leather armor", + description = "Colorize a piece of leather armor, or wash it", func = function(name, param) local player = minetest.get_player_by_name(name) if player then local item = player:get_wielded_item() - item:get_meta():set_string("color", param) - tt.reload_itemstack_description(item) - player:set_wielded_item(item) - return true, "Done." + if not item or not item:get_definition().groups.armor_leather == 1 then + return false, "Not leather armor." + end + if param == "wash" then + player:set_wielded_item(mcl_armor.wash_leather_armor(item)) + return true, "Washed." + end + local colorstring = minetest.colorspec_to_colorstring(param) + if not colorstring then return false, "Invalid color" end + player:set_wielded_item(mcl_armor.colorize_leather_armor(item, colorstring)) + return true, "Done: " .. colorstring else return false, "Player isn't online" end end, -}) \ No newline at end of file +}) From 3fa4cf6d524cd189f4e66661414d6df3c89e304d Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Thu, 25 Jan 2024 11:56:54 +0100 Subject: [PATCH 3/5] Cauldron leather armor washing --- mods/ITEMS/mcl_armor/api.lua | 11 ++++++----- mods/ITEMS/mcl_armor/leather.lua | 13 ++++++++----- mods/ITEMS/mcl_cauldrons/init.lua | 8 ++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/mods/ITEMS/mcl_armor/api.lua b/mods/ITEMS/mcl_armor/api.lua index 1e88643f1..750bd66c8 100755 --- a/mods/ITEMS/mcl_armor/api.lua +++ b/mods/ITEMS/mcl_armor/api.lua @@ -103,10 +103,10 @@ local function get_armor_texture(textures, name, modname, itemname, itemstring) end if overlay == "" then return core_armor_texture end -- key not present; armor not trimmed - + return core_armor_texture .. overlay end - + return func end @@ -129,6 +129,7 @@ function mcl_armor.register_set(def) local groups = table.copy(groups) groups["armor_" .. name] = 1 groups["combat_armor_" .. name] = 1 + groups["armor_" .. def.name] = 1 groups.armor = 1 groups.combat_armor = 1 groups.mcl_armor_points = def.points[name] @@ -326,12 +327,12 @@ end tt.register_snippet(function(itemstring, toolcaps, stack) if not stack then return nil end local meta = stack:get_meta() - if not mcl_armor.is_trimmed(stack) then return nil end + if not mcl_armor.is_trimmed(stack) then return nil end -- we need to get the part of the overlay image between the overlay begin ( and the trim name end _ -- we COULD easily store this info in meta, but that would bloat the meta storage, as the same few values would be stored over and over again on every trimmed item -- this is fine here as this code gets only executed when you put armor and a trim in a smithing table local full_overlay = meta:get_string("mcl_armor:trim_overlay") - local trim_name = full_overlay:match("%((.-)%_") + local trim_name = full_overlay:match("%((.-)%_") return "Upgrade:\n " .. trim_name:gsub("^%l", string.upper) .. " Armor Trim" end) @@ -339,4 +340,4 @@ function mcl_armor.is_trimmed(itemstack) -- this meta value will be there for every trimmed armor piece -- remember, get_string returns "" if the key doesn't exist return itemstack:get_meta():get_string("mcl_armor:trim_overlay") ~= "" -end \ No newline at end of file +end diff --git a/mods/ITEMS/mcl_armor/leather.lua b/mods/ITEMS/mcl_armor/leather.lua index 9466de77d..8c0b45689 100644 --- a/mods/ITEMS/mcl_armor/leather.lua +++ b/mods/ITEMS/mcl_armor/leather.lua @@ -53,10 +53,10 @@ local function get_texture_function(texture) end if mcl_enchanting.is_enchanted(itemstack:get_name()) then - minetest.chat_send_all(out..mcl_enchanting.overlay) +-- minetest.chat_send_all(out..mcl_enchanting.overlay) -- TODO remove return out..mcl_enchanting.overlay else - minetest.chat_send_all(out) +-- minetest.chat_send_all(out) -- TODO remove return out end end @@ -64,6 +64,9 @@ local function get_texture_function(texture) end function mcl_armor.colorize_leather_armor(itemstack, colorstring) + if not itemstack or minetest.get_item_group(itemstack:get_name(), "armor_leather") == 0 then + return + end local color = color_string_to_table(colorstring) local meta = itemstack:get_meta() local old_color = meta:get_string("mcl_armor:color") @@ -83,7 +86,7 @@ function mcl_armor.colorize_leather_armor(itemstack, colorstring) end function mcl_armor.wash_leather_armor(itemstack) - if not itemstack or not itemstack:get_definition().groups.armor_leather == 1 then + if not itemstack or minetest.get_item_group(itemstack:get_name(), "armor_leather") == 0 then return end local meta = itemstack:get_meta() @@ -119,7 +122,7 @@ mcl_armor.register_set({ }) tt.register_priority_snippet(function(_, _, itemstack) - if not itemstack or not itemstack:get_definition().groups.armor_leather == 1 then + if not itemstack or minetest.get_item_group(itemstack:get_name(), "armor_leather") == 0 then return end local color = itemstack:get_meta():get_string("mcl_armor:color") @@ -137,7 +140,7 @@ minetest.register_chatcommand("color_leather", { local player = minetest.get_player_by_name(name) if player then local item = player:get_wielded_item() - if not item or not item:get_definition().groups.armor_leather == 1 then + if not item or minetest.get_item_group(item:get_name(), "armor_leather") == 0 then return false, "Not leather armor." end if param == "wash" then diff --git a/mods/ITEMS/mcl_cauldrons/init.lua b/mods/ITEMS/mcl_cauldrons/init.lua index 0ba678583..89f173399 100644 --- a/mods/ITEMS/mcl_cauldrons/init.lua +++ b/mods/ITEMS/mcl_cauldrons/init.lua @@ -94,6 +94,14 @@ local function register_filled_cauldron(water_level, description, liquid) drop = "mcl_cauldrons:cauldron", _mcl_hardness = 2, _mcl_blast_resistance = 2, + on_rightclick = function(pos, node, player, itemstack) + local outcome = mcl_armor.wash_leather_armor(itemstack) + if outcome then + minetest.sound_play("mcl_potions_bottle_pour", + {pos=pos, gain=0.5, max_hear_range=16},true) + end + return outcome + end, }) -- Add entry aliases for the Help From fc6fe3f1edbca79d99b6983c750852e17c8b71c4 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Thu, 25 Jan 2024 12:47:20 +0100 Subject: [PATCH 4/5] Crafting colorized leather armor --- mods/ITEMS/mcl_armor/leather.lua | 56 ++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_armor/leather.lua b/mods/ITEMS/mcl_armor/leather.lua index 8c0b45689..76e1bf6be 100644 --- a/mods/ITEMS/mcl_armor/leather.lua +++ b/mods/ITEMS/mcl_armor/leather.lua @@ -53,10 +53,8 @@ local function get_texture_function(texture) end if mcl_enchanting.is_enchanted(itemstack:get_name()) then --- minetest.chat_send_all(out..mcl_enchanting.overlay) -- TODO remove return out..mcl_enchanting.overlay else --- minetest.chat_send_all(out) -- TODO remove return out end end @@ -68,9 +66,11 @@ function mcl_armor.colorize_leather_armor(itemstack, colorstring) return end local color = color_string_to_table(colorstring) + colorstring = minetest.colorspec_to_colorstring(color) local meta = itemstack:get_meta() local old_color = meta:get_string("mcl_armor:color") - if old_color ~= "" then + if old_color == colorstring then return + elseif old_color ~= "" then color = calculate_color( color_string_to_table(minetest.colorspec_to_colorstring(old_color)), color @@ -132,6 +132,56 @@ tt.register_priority_snippet(function(_, _, itemstack) end end) +for name, element in pairs(mcl_armor.elements) do + local modname = minetest.get_current_modname() + local itemname = modname .. ":" .. element.name .. "_leather" + minetest.register_craft({ + type = "shapeless", + output = itemname, + recipe = { + itemname, + "group:dye", + }, + }) + local ench_itemname = itemname .. "_enchanted" + minetest.register_craft({ + type = "shapeless", + output = ench_itemname, + recipe = { + ench_itemname, + "group:dye", + }, + }) +end + +local function colorizing_crafting(itemstack, player, old_craft_grid, craft_inv) + if minetest.get_item_group(itemstack:get_name(), "armor_leather") == 0 then + return + end + + local found_la = nil + local dye_color = nil + for _, item in pairs(old_craft_grid) do + local name = item:get_name() + if name == "" then + -- continue + elseif minetest.get_item_group(name, "armor_leather") > 0 then + if found_la then return end + found_la = item + elseif minetest.get_item_group(name, "dye") > 0 then + if dye_color then return end + for _, row in pairs(colors) do + if row[3] == name then dye_color = row[4] end + end + else return end + end + + return mcl_armor.colorize_leather_armor(found_la, dye_color) or ItemStack() +end + +minetest.register_craft_predict(colorizing_crafting) +minetest.register_on_craft(colorizing_crafting) + minetest.register_chatcommand("color_leather", { params = "", From 03b8ad15e36c07b1212a90f36d1d19520994cff5 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Fri, 2 Feb 2024 04:05:28 +0100 Subject: [PATCH 5/5] Privs for colorizing command and comment cleanup --- mods/ITEMS/mcl_armor/leather.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_armor/leather.lua b/mods/ITEMS/mcl_armor/leather.lua index 76e1bf6be..c2366166b 100644 --- a/mods/ITEMS/mcl_armor/leather.lua +++ b/mods/ITEMS/mcl_armor/leather.lua @@ -20,8 +20,6 @@ local colors = { { "white", "White", "mcl_dye:white", "#d1d7d8" }, } --- #608b03 from #495d20 - local function color_string_to_table(colorstring) return { r = tonumber(colorstring:sub(2,3), 16), -- 16 as second parameter allows hexadecimal @@ -186,6 +184,7 @@ minetest.register_on_craft(colorizing_crafting) minetest.register_chatcommand("color_leather", { params = "", description = "Colorize a piece of leather armor, or wash it", + privs = {debug = true}, func = function(name, param) local player = minetest.get_player_by_name(name) if player then