From 563dc719d0c4d7d5efba76456301ba8a8e5c7b7a Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Sun, 19 Jun 2022 14:43:39 +0200 Subject: [PATCH] Put a upper limit for sprite creation --- src/caches.lua | 10 +++++++--- src/groups.lua | 2 ++ src/gui.lua | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/caches.lua b/src/caches.lua index 2f65a68..99143bc 100644 --- a/src/caches.lua +++ b/src/caches.lua @@ -33,21 +33,24 @@ local function cache_groups(group, groups) local c = 0 local px = 256 + local limit = 10 local sprite = "[combine:WxH" for _, item in ipairs(items) do local def = reg_items[item] - local texture = def.inventory_image or def.wield_image + local texture = def.inventory_image if true_str(texture) then texture = texture:gsub("%^", "\\^"):gsub(":", "\\:") .. "\\^[resize\\:150x150" elseif is_cube(def.drawtype) then - texture = get_cube(def.tiles) + local tiles = def.tiles or def.tile_images + texture = get_cube(tiles) end if true_str(texture) then sprite = sprite .. fmt(":0,%u=%s", c * px, texture) c++ + if c == limit then break end end end @@ -330,7 +333,8 @@ local function init_cubes() local id = core.get_content_id(name) if is_cube(def.drawtype) then - i3.cubes[id] = get_cube(def.tiles) + local tiles = def.tiles or def.tile_images + i3.cubes[id] = get_cube(tiles) elseif sub(def.drawtype, 1, 9) == "plantlike" or sub(def.drawtype, 1, 8) == "firelike" then i3.plants[id] = def.inventory_image end diff --git a/src/groups.lua b/src/groups.lua index 4ffff92..6db4cd0 100644 --- a/src/groups.lua +++ b/src/groups.lua @@ -11,6 +11,7 @@ i3.group_stereotypes = { stone = "default:stone", leaves = "default:leaves", coal = "default:coal_lump", + fence = "default:fence_wood", vessel = "vessels:glass_bottle", flower = "flowers:dandelion_yellow", water_bucket = "bucket:bucket_water", @@ -26,6 +27,7 @@ i3.group_names = { glass = S"Any glass", stick = S"Any stick", stone = S"Any stone", + fence = S"Any fence", carpet = S"Any carpet", flower = S"Any flower", leaves = S"Any leaves", diff --git a/src/gui.lua b/src/gui.lua index 95b33f7..88ba426 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -18,7 +18,7 @@ IMPORT("S", "ES", "translate", "ItemStack", "toupper") IMPORT("get_sorting_idx", "compression_active", "compressible") IMPORT("get_bag_description", "get_detached_inv", "get_recipes") IMPORT("maxn", "sort", "concat", "copy", "insert", "remove", "unpack") -IMPORT("get_group_stereotype", "extract_groups", "is_group", "item_has_groups", "get_group") +IMPORT("get_group_stereotype", "extract_groups", "groups_to_items", "is_group", "item_has_groups", "get_group") local function fmt(elem, ...) if not fs_elements[elem] then @@ -997,8 +997,8 @@ local function get_grid_fs(fs, data, rcp, is_recipe) if is_group(name) then groups = group_cache and group_cache.groups or extract_groups(name) - name = group_cache and group_cache.stereotype or - get_group_stereotype(groups[1]) or group_cache.items[1] + name = group_cache and (group_cache.stereotype or group_cache.items[1]) or + get_group_stereotype(groups[1]) or groups_to_items(groups)[1] end local label = groups and "\nG" or ""