2020-03-24 18:48:14 +01:00
|
|
|
mcl_formspec = {}
|
|
|
|
|
2021-09-17 23:58:58 +02:00
|
|
|
mcl_formspec.label_color = "#313131"
|
|
|
|
|
2022-10-08 00:15:38 +02:00
|
|
|
---Get the background of inventory slots (formspec version = 1)
|
2022-09-09 20:42:28 +02:00
|
|
|
---@param x number
|
|
|
|
---@param y number
|
|
|
|
---@param w number
|
|
|
|
---@param h number
|
|
|
|
---@return string
|
2020-03-24 18:48:14 +01:00
|
|
|
function mcl_formspec.get_itemslot_bg(x, y, w, h)
|
|
|
|
local out = ""
|
|
|
|
for i = 0, w - 1, 1 do
|
|
|
|
for j = 0, h - 1, 1 do
|
2022-09-09 18:59:12 +02:00
|
|
|
out = out .. "image[" .. x + i .. "," .. y + j .. ";1,1;mcl_formspec_itemslot.png]"
|
2020-03-24 18:48:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return out
|
|
|
|
end
|
2021-04-25 23:35:27 +02:00
|
|
|
|
2022-09-09 18:59:12 +02:00
|
|
|
---This function will replace mcl_formspec.get_itemslot_bg then every formspec will be upgrade to version 4
|
|
|
|
---@param x number
|
|
|
|
---@param y number
|
|
|
|
---@param size number
|
2022-10-08 00:02:35 +02:00
|
|
|
---@param texture? string
|
2022-09-09 18:59:12 +02:00
|
|
|
---@return string
|
2022-10-08 00:02:35 +02:00
|
|
|
---@nodiscard
|
|
|
|
local function get_slot(x, y, size, texture)
|
2022-09-09 18:59:12 +02:00
|
|
|
local t = "image[" .. x - size .. "," .. y - size .. ";" .. 1 + (size * 2) ..
|
2022-10-08 00:02:35 +02:00
|
|
|
"," .. 1 + (size * 2) .. ";" .. (texture and texture or "mcl_formspec_itemslot.png") .. "]"
|
2021-09-17 23:58:58 +02:00
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
|
|
|
mcl_formspec.itemslot_border_size = 0.05
|
|
|
|
|
2022-10-08 00:15:38 +02:00
|
|
|
---Get the background of inventory slots (formspec version > 1)
|
2022-09-09 18:59:12 +02:00
|
|
|
---@param x number
|
|
|
|
---@param y number
|
|
|
|
---@param w integer
|
|
|
|
---@param h integer
|
2022-10-08 00:02:35 +02:00
|
|
|
---@param size? number Optional size of the slot border (default: 0.05)
|
|
|
|
---@param texture? string Optional texture to replace the default one
|
2022-09-09 18:59:12 +02:00
|
|
|
---@return string
|
2022-10-08 00:02:35 +02:00
|
|
|
---@nodiscard
|
|
|
|
function mcl_formspec.get_itemslot_bg_v4(x, y, w, h, size, texture)
|
2021-09-17 23:58:58 +02:00
|
|
|
if not size then
|
|
|
|
size = mcl_formspec.itemslot_border_size
|
|
|
|
end
|
2021-04-25 23:35:27 +02:00
|
|
|
local out = ""
|
|
|
|
for i = 0, w - 1, 1 do
|
|
|
|
for j = 0, h - 1, 1 do
|
2022-10-08 00:02:35 +02:00
|
|
|
out = out .. get_slot(x + i + (i * 0.25), y + j + (j * 0.25), size, texture)
|
2021-04-25 23:35:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return out
|
2022-09-09 18:59:12 +02:00
|
|
|
end
|