34 lines
789 B
Lua

local Util = {}
function Util.toHexChar(v)
return ("0123456789ABCDEF"):sub(v, v)
end
function Util.fromHexChar(c)
local index = ({("0123456789ABCDEF"):find(c)})[1]
if index ~= nil then
return index - 1
end
return nil
end
function Util.boundCheck(x, y, w, h)
if x < 1 or x > w or y < 1 or y > h then
error(("Index out of range: (%d %d) is not within ([1,%d], [1,%d])"):format(x, y, w, h))
end
end
-- Workaround for a bug in CC: Tweaked causing inventory.getItemLimit() to return nil immediately after item transfers
function Util.getItemLimit(inv, slot, maxTries)
local i = 1
while not maxTries or i <= maxTries do
local result = inv.getItemLimit(slot)
if result ~= nil then
return result
end
i = i + 1
end
return nil
end
return Util