From 6d2658ac255892e85296520feacd4f2e4a2c68d5 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Mon, 22 Nov 2021 17:37:28 +0100 Subject: [PATCH] Some cleaning --- init.lua | 3 ++- src/api.lua | 4 ++-- src/bags.lua | 38 ++++------------------------------- src/gui.lua | 6 +++--- tests/test_custom_recipes.lua | 1 + 5 files changed, 12 insertions(+), 40 deletions(-) diff --git a/init.lua b/init.lua index 2d2a26e..a73140d 100644 --- a/init.lua +++ b/init.lua @@ -72,7 +72,8 @@ i3.files.groups() i3.files.callbacks() local storage = core.get_mod_storage() -local slz, dslz, copy, str_to_pos, add_hud_waypoint = i3.get("slz", "dslz", "copy", "str_to_pos", "add_hud_waypoint") +local slz, dslz, copy = i3.get("slz", "dslz", "copy") +local str_to_pos, add_hud_waypoint = i3.get("str_to_pos", "add_hud_waypoint") local set_fs = i3.set_fs i3.data = dslz(storage:get_string "data") or {} diff --git a/src/api.lua b/src/api.lua index 4bf266e..685db0b 100644 --- a/src/api.lua +++ b/src/api.lua @@ -1,6 +1,6 @@ local make_fs = i3.files.gui() -local gmatch, match, split = i3.get("gmatch", "match", "split") +local gmatch, split = i3.get("gmatch", "split") local S, err, fmt, reg_items = i3.get("S", "err", "fmt", "reg_items") local sorter, sort_inventory = i3.get("sorter", "sort_inventory") local sort, concat, copy, insert, remove = i3.get("sort", "concat", "copy", "insert", "remove") @@ -115,7 +115,7 @@ function i3.register_craft(def) end end - local item = match(def.output, "%S+") + local item = ItemStack(def.output):get_name() i3.recipes_cache[item] = i3.recipes_cache[item] or {} def.custom = true diff --git a/src/bags.lua b/src/bags.lua index a78fc08..db27712 100644 --- a/src/bags.lua +++ b/src/bags.lua @@ -14,42 +14,12 @@ local function get_content(content) local t = {} for i, v in pairs(content) do - local stack = ItemStack(v.name) - - if v.meta then - local m = stack:get_meta() - m:from_table(v.meta) - end - - if v.wear then - stack:set_wear(v.wear) - end - - t[i] = stack + t[i] = ItemStack(v) end return t end -local function safe_format(stack) - local meta = stack:get_meta():to_table() - local wear = stack:get_wear() - local has_meta = next(meta.fields) - - local info = {} - info.name = fmt("%s %u", stack:get_name(), stack:get_count()) - - if has_meta then - info.meta = meta - end - - if wear > 0 then - info.wear = wear - end - - return info -end - local function init_bags(player) local name = player:get_player_name() local data = i3.data[name] @@ -73,7 +43,7 @@ local function init_bags(player) end, on_put = function(_, _, _, stack) - data.bag_item = safe_format(stack) + data.bag_item = stack:to_string() data.bag_size = core.get_item_group(stack:get_name(), "bag") local meta = stack:get_meta() @@ -119,7 +89,7 @@ local function init_bags(player) local stack = list[i] if not stack:is_empty() then - t[i] = safe_format(stack) + t[i] = stack:to_string() end end @@ -141,7 +111,7 @@ local function init_bags(player) end bag:set_stack("main", 1, bagstack) - data.bag_item = safe_format(bagstack) + data.bag_item = bagstack:to_string() set_fs(player) end diff --git a/src/gui.lua b/src/gui.lua index c203dca..2bbdf0c 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -71,8 +71,8 @@ local function get_desc(item) end local function get_stack_max(inv, data, is_recipe, rcp) - local list = inv:get_list("main") - local size = inv:get_size("main") + local list = inv:get_list"main" + local size = inv:get_size"main" local counts_inv, counts_rcp, counts = {}, {}, {} local rcp_usg = is_recipe and "recipe" or "usage" @@ -643,7 +643,7 @@ local function get_tooltip(item, info, pos) if info.replace then for i = 1, #info.replace.items do - local rpl = match(info.replace.items[i], "%S+") + local rpl = ItemStack(info.replace.items[i]):get_name() local desc = clr("#ff0", get_desc(rpl)) if info.replace.type == "cooking" then diff --git a/tests/test_custom_recipes.lua b/tests/test_custom_recipes.lua index 629a781..fe15def 100644 --- a/tests/test_custom_recipes.lua +++ b/tests/test_custom_recipes.lua @@ -8,6 +8,7 @@ mt2:get_meta():set_string("color", "#ff0") local mt3 = ItemStack("default:pick_diamond") mt3:get_meta():set_string("description", "Worn Pick") +mt3:get_meta():set_string("color", "yellow") mt3:set_wear(10000) minetest.register_craft({