Fix potential crash during sprite creation

This commit is contained in:
Jean-Patrick Guerrero 2022-06-28 01:03:41 +02:00
parent c421c49916
commit dcc4068e46

View File

@ -39,26 +39,31 @@ local function cache_groups(group, groups)
for _, item in ipairs(items) do for _, item in ipairs(items) do
local def = reg_items[item] local def = reg_items[item]
local tiles = def.tiles or def.tile_images
local texture = true_str(def.inventory_image) and def.inventory_image --or tiles[1]
if is_cube(def.drawtype) then if def then
texture = get_cube(tiles) local tiles = def.tiles or def.tile_images
elseif texture then local texture = true_str(def.inventory_image) and def.inventory_image --or tiles[1]
texture = texture:gsub("%^", "\\^"):gsub(":", "\\:") .. "\\^[resize\\:150x150"
end
if texture then if is_cube(def.drawtype) then
sprite = sprite .. fmt(":0,%u=%s", c * px, texture) texture = get_cube(tiles)
c++ elseif texture then
if c == lim then break end texture = texture:gsub("%^", "\\^"):gsub(":", "\\:") .. "\\^[resize\\:150x150"
end
if texture then
sprite = sprite .. fmt(":0,%u=%s", c * px, texture)
c++
if c == lim then break end
end
end end
end end
sprite = sprite:gsub("WxH", px .. "x" .. px * c) if c > 1 then
sprite = sprite:gsub("WxH", px .. "x" .. px * c)
i3.groups[group].sprite = sprite i3.groups[group].sprite = sprite
i3.groups[group].count = c i3.groups[group].count = c
end
end end
local function get_item_usages(item, recipe, added) local function get_item_usages(item, recipe, added)