From ec4e929491ff153cad0741a616d5c677c1486cd6 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Sun, 21 Nov 2021 18:44:49 +0100 Subject: [PATCH] GUI: show wear for recipe output --- init.lua | 4 +- src/gui.lua | 100 +++++++++++++++++----------------- tests/test_custom_recipes.lua | 13 +++++ 3 files changed, 66 insertions(+), 51 deletions(-) diff --git a/init.lua b/init.lua index 3130485..2d2a26e 100644 --- a/init.lua +++ b/init.lua @@ -72,7 +72,7 @@ i3.files.groups() i3.files.callbacks() local storage = core.get_mod_storage() -local slz, dslz, str_to_pos, add_hud_waypoint = i3.get("slz", "dslz", "str_to_pos", "add_hud_waypoint") +local slz, dslz, copy, str_to_pos, add_hud_waypoint = i3.get("slz", "dslz", "copy", "str_to_pos", "add_hud_waypoint") local set_fs = i3.set_fs i3.data = dslz(storage:get_string "data") or {} @@ -189,7 +189,7 @@ local function init_hudbar(player) end local function save_data(player_name) - local _data = table.copy(i3.data) + local _data = copy(i3.data) for name, v in pairs(_data) do for dat in pairs(v) do diff --git a/src/gui.lua b/src/gui.lua index 9f0f961..e9d66c1 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -721,61 +721,63 @@ local function get_output_fs(fs, data, rcp, is_recipe, shapeless, right, btn_siz if rcp.type == "fuel" then fs("animated_image", X + 0.05, Y, i3.ITEM_BTN_SIZE, i3.ITEM_BTN_SIZE, PNG.fire_anim, 8, 180) - else - local item = ItemStack(rcp.output) - local meta = item:get_meta() - local name = item:get_name() - local count = item:get_count() - local bt_s = i3.ITEM_BTN_SIZE * 1.2 - local _name = fmt("_%s", name) - local pos + return + end - if meta:get_string("color") ~= "" or meta:get_string("palette_index") ~= "" then - local rcp_usg = is_recipe and "rcp" or "usg" + local item = ItemStack(rcp.output) + local meta = item:get_meta() + local name = item:get_name() + local count = item:get_count() + local wear = item:get_wear() + local bt_s = i3.ITEM_BTN_SIZE * 1.2 + local _name = fmt("_%s", name) + local pos - fs(fmt("style_type[list;size=%f]", i3.ITEM_BTN_SIZE)) - fs("listcolors[#bababa50;#bababa99]") - fs(fmt("list[detached:i3_output_%s_%s;main;%f,%f;1,1;]", rcp_usg, data.player_name, X + 0.11, Y)) - fs("button", X + 0.11, Y, i3.ITEM_BTN_SIZE, i3.ITEM_BTN_SIZE, _name, "") + if meta:get_string("color") ~= "" or meta:get_string("palette_index") ~= "" then + local rcp_usg = is_recipe and "rcp" or "usg" - local inv = core.get_inventory { - type = "detached", - name = fmt("i3_output_%s_%s", rcp_usg, data.player_name) - } + fs(fmt("style_type[list;size=%f]", i3.ITEM_BTN_SIZE)) + fs("listcolors[#bababa50;#bababa99]") + fs(fmt("list[detached:i3_output_%s_%s;main;%f,%f;1,1;]", rcp_usg, data.player_name, X + 0.11, Y)) + fs("button", X + 0.11, Y, i3.ITEM_BTN_SIZE, i3.ITEM_BTN_SIZE, _name, "") - inv:set_stack("main", 1, item) - pos = {x = X + 0.11, y = Y} - else - fs("image", X, Y - 0.11, bt_s, bt_s, PNG.slot) - fs("item_image_button", - X + 0.11, Y, i3.ITEM_BTN_SIZE, i3.ITEM_BTN_SIZE, - fmt("%s %u", name, count * (is_recipe and data.scrbar_rcp or data.scrbar_usg or 1)), - _name, "") - end - - local def = reg_items[name] - local unknown = not def or nil - local desc = def and def.description - local weird = name ~= "" and desc and weird_desc(desc) or nil - local burntime = i3.fuel_cache[name] and i3.fuel_cache[name].burntime - - local short_desc = meta:get_string("short_description") - local long_desc = meta:get_string("description") - local meta_desc = (short_desc ~= "" and short_desc) or (long_desc ~= "" and long_desc) - - local infos = { - unknown = unknown, - weird = weird, - burntime = burntime, - repair = repairable(name), - rarity = rcp.rarity, - tools = rcp.tools, - meta_desc = meta_desc, + local inv = core.get_inventory { + type = "detached", + name = fmt("i3_output_%s_%s", rcp_usg, data.player_name) } - if next(infos) then - fs(get_tooltip(_name, infos, pos)) - end + inv:set_stack("main", 1, item) + pos = {x = X + 0.11, y = Y} + else + fs("image", X, Y - 0.11, bt_s, bt_s, PNG.slot) + fs("item_image_button", + X + 0.11, Y, i3.ITEM_BTN_SIZE, i3.ITEM_BTN_SIZE, + fmt("%s %u %u", name, count * (is_recipe and data.scrbar_rcp or data.scrbar_usg or 1), wear), + _name, "") + end + + local def = reg_items[name] + local unknown = not def or nil + local desc = def and def.description + local weird = name ~= "" and desc and weird_desc(desc) or nil + local burntime = i3.fuel_cache[name] and i3.fuel_cache[name].burntime + + local short_desc = meta:get_string("short_description") + local long_desc = meta:get_string("description") + local meta_desc = (short_desc ~= "" and short_desc) or (long_desc ~= "" and long_desc) + + local infos = { + unknown = unknown, + weird = weird, + burntime = burntime, + repair = repairable(name), + rarity = rcp.rarity, + tools = rcp.tools, + meta_desc = meta_desc, + } + + if next(infos) then + fs(get_tooltip(_name, infos, pos)) end end diff --git a/tests/test_custom_recipes.lua b/tests/test_custom_recipes.lua index 0f91808..629a781 100644 --- a/tests/test_custom_recipes.lua +++ b/tests/test_custom_recipes.lua @@ -6,6 +6,10 @@ local mt2 = ItemStack("dye:red") mt2:get_meta():set_string("description", "test red") mt2:get_meta():set_string("color", "#ff0") +local mt3 = ItemStack("default:pick_diamond") +mt3:get_meta():set_string("description", "Worn Pick") +mt3:set_wear(10000) + minetest.register_craft({ output = mt:to_string(), type = "shapeless", @@ -15,6 +19,15 @@ minetest.register_craft({ }, }) +minetest.register_craft({ + output = mt3:to_string(), + type = "shapeless", + recipe = { + "default:pick_mese", + "default:diamond", + }, +}) + i3.register_craft { url = "https://raw.githubusercontent.com/minetest-mods/i3/main/tests/test_online_recipe.json" }