Skip to content

Commit 4260e1f

Browse files
author
LNJ
committed
Fix inventory cubes; using fitting tiles now
1 parent bb9bbe2 commit 4260e1f

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

lua/helpers.lua

+22-18
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,31 @@ end
4545
function drawers.get_inv_image(name)
4646
local texture = "blank.png"
4747
local def = core.registered_items[name]
48-
if name ~= "air" and def then
49-
if def.inventory_image and #def.inventory_image > 0 then
50-
texture = def.inventory_image
51-
else
52-
if not def.tiles then return texture end
53-
54-
local c = #def.tiles or 0
55-
local x = {}
56-
for i, v in ipairs(def.tiles) do
57-
if type(v) == "table" then
58-
x[i] = v.name
59-
else
60-
x[i] = v
61-
end
62-
i = i + 1
48+
if not def then return end
49+
50+
if def.inventory_image and #def.inventory_image > 0 then
51+
texture = def.inventory_image
52+
else
53+
if not def.tiles then return texture end
54+
local tiles = table.copy(def.tiles)
55+
56+
for k,v in pairs(tiles) do
57+
if type(v) == "table" then
58+
tiles[k] = v.name
6359
end
64-
if not x[3] then x[3] = x[1] end
65-
if not x[4] then x[4] = x[3] end
66-
texture = core.inventorycube(x[1], x[3], x[4])
60+
end
61+
62+
-- tiles: up, down, right, left, back, front
63+
-- inventorycube: up, front, right
64+
if #tiles <= 2 then
65+
texture = core.inventorycube(tiles[1], tiles[1], tiles[1])
66+
elseif #tiles <= 5 then
67+
texture = core.inventorycube(tiles[1], tiles[3], tiles[3])
68+
else -- full tileset
69+
texture = core.inventorycube(tiles[1], tiles[6], tiles[3])
6770
end
6871
end
72+
6973
return texture
7074
end
7175

0 commit comments

Comments
 (0)