Compare commits

..

5 Commits
1.5.2 ... 1.5.3

Author SHA1 Message Date
d8e17687e1 A bit of cleaning 2021-12-25 17:24:30 +01:00
2fadcdefdd Fix variable name 2021-12-25 17:01:25 +01:00
c7f6e1db62 API: fix custom recipe registration 2021-12-24 00:43:38 +01:00
16a1865e11 More cleaning 2021-12-21 17:16:46 +01:00
748cc9a7a1 Small cleaning 2021-12-21 15:39:04 +01:00
5 changed files with 78 additions and 93 deletions

View File

@ -257,4 +257,4 @@ end
--i3.files.tests.tabs()
--i3.files.tests.operators()
--i3.files.tests.compression()
--i3.files.tests.custom_recipes(http)
--i3.files.tests.custom_recipes()

View File

@ -1,5 +1,5 @@
local make_fs = i3.files.gui()
local http = ...
local make_fs = i3.files.gui()
IMPORT("gmatch", "split")
IMPORT("S", "err", "fmt", "reg_items")
@ -22,7 +22,7 @@ end
function i3.register_craft(def)
local width, c = 0, 0
if true_str(def.url) then
if http and true_str(def.url) then
http.fetch({url = def.url}, function(result)
if result.succeeded then
local t = core.parse_json(result.data)
@ -51,7 +51,7 @@ function i3.register_craft(def)
def.result = nil
end
if not true_str(def.output) then
if not true_str(def.output) and not def.url then
return err "i3.register_craft: output missing"
end
@ -69,9 +69,7 @@ function i3.register_craft(def)
end
local cp = copy(def.grid)
sort(cp, function(a, b)
return #a > #b
end)
sort(cp, function(a, b) return #a > #b end)
width = #cp[1]
@ -86,26 +84,29 @@ function i3.register_craft(def)
def.items[c] = def.key[symbol]
end
else
local items, len = def.items, #def.items
local items = copy(def.items)
local lines = {}
def.items = {}
for i = 1, len do
local rlen = #split(items[i], ",")
for i = 1, #items do
lines[i] = split(items[i], ",", true)
if rlen > width then
width = rlen
if #lines[i] > width then
width = #lines[i]
end
end
for i = 1, len do
while #split(items[i], ",") < width do
items[i] = fmt("%s,", items[i])
for i = 1, #items do
while #lines[i] < width do
insert(lines[i], items[i])
end
end
for name in gmatch(concat(items, ","), "[%s%w_:]+") do
for _, line in ipairs(lines) do
for _, v in ipairs(line) do
c++
def.items[c] = clean_name(name)
def.items[c] = clean_name(v)
end
end
end

View File

@ -234,14 +234,14 @@ local function get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
local width = 8
local base_height = 4
local base_depth = depth == -1
local max_depth = -10
local max_depth = -7
local height = base_depth and (base_height - 1) or depth
local pos1 = vec_new(pos.x - width, pos.y + depth, pos.z - width)
local pos2 = vec_new(pos.x + width, pos.y + height, pos.z + width)
local vm = VoxelManip(pos1, pos2)
local emin, emax = vm:read_from_map(pos1, pos2)
local emin, emax = vm:get_emerged_area()
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
local data = vm:get_data()
@ -276,8 +276,9 @@ local function get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
if cubes < maxc and depth > max_depth then
-- if there's not enough map to preview, go deeper
depth -= 1
get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
else
return get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
end
local shift = -0.3 - high
for i = max_depth, 0 do
@ -294,7 +295,6 @@ local function get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
shift += (base_depth and 0.45 or 0.95)
fs("image", 2.7, Y + shift, 0.3, 0.3, PNG.flag)
end
end
local function get_waypoint_fs(fs, data, player, yextra, ctn_len)
@ -1093,8 +1093,7 @@ local function get_model_fs(fs, data, def, model_alias)
hex = "0" .. hex
end
_name = fmt("%s^[multiply:%s", v.name,
fmt("#%s%s", sub(hex, 3), sub(hex, 1, 2)))
_name = fmt("%s^[multiply:%s", v.name, fmt("#%s%s", sub(hex, 3), sub(hex, 1, 2)))
else
_name = fmt("%s^[multiply:%s", v.name, v.color)
end
@ -1201,7 +1200,7 @@ local function get_export_fs(fs, data, is_recipe, is_usage, max_stacks_rcp, max_
fmt("craft_%s", name), ES("Craft (×@1)", stack_fs))
end
local function get_rcp_extra(fs, player, data, panel, is_recipe, is_usage)
local function get_rcp_extra(fs, data, player, panel, is_recipe, is_usage)
fs"container[0,0.075]"
local rn = panel.rcp and #panel.rcp
@ -1270,7 +1269,7 @@ local function hide_items(player, data)
end
end
local function get_items_fs(fs, player, data, full_height)
local function get_items_fs(fs, data, player, full_height)
hide_items(player, data)
local items = data.alt_items or data.items or {}
@ -1278,6 +1277,8 @@ local function get_items_fs(fs, player, data, full_height)
local ipp = rows * lines
local size = 0.85
fs("bg9", data.inv_width + 0.1, 0, 7.9, full_height, PNG.bg_full, 10)
fs(fmt("box[%f,0.2;4.05,0.6;#bababa25]", data.inv_width + 0.3),
"set_focus[filter]",
fmt("field[%f,0.2;2.95,0.6;filter;;%s]", data.inv_width + 0.35, ESC(data.filter)),
@ -1363,43 +1364,23 @@ local function get_favs(fs, data)
end
end
local function get_panels(fs, player, data, full_height)
local _title = {name = "title", height = 1.4}
local _favs = {name = "favs", height = 2.23}
local _items = {name = "items", height = full_height}
local _recipes = {name = "recipes", rcp = data.recipes, height = 4.045}
local _usages = {name = "usages", rcp = data.usages, height = 4.045}
local panels
if data.query_item then
panels = {_title, _recipes, _usages, _favs}
else
panels = {_items}
end
for idx = 1, #panels do
local panel = panels[idx]
local function get_panels(fs, data, player)
local title = {name = "title", height = 1.4, func = get_header}
local favs = {name = "favs", height = 2.23, func = get_favs}
local recipes = {name = "recipes", rcp = data.recipes, height = 4.045, func = get_rcp_extra}
local usages = {name = "usages", rcp = data.usages, height = 4.045, func = get_rcp_extra}
local panels = {title, recipes, usages, favs}
data.yoffset = 0
if idx > 1 then
for _idx = idx - 1, 1, -1 do
data.yoffset = data.yoffset + panels[_idx].height + 0.1
end
for i, panel in ipairs(panels) do
if i > 1 then
data.yoffset += panels[i - 1].height + 0.1
end
fs("bg9", data.inv_width + 0.1, data.yoffset, 7.9, panel.height, PNG.bg_full, 10)
local is_recipe, is_usage = panel.name == "recipes", panel.name == "usages"
if is_recipe or is_usage then
get_rcp_extra(fs, player, data, panel, is_recipe, is_usage)
elseif panel.name == "items" then
get_items_fs(fs, player, data, full_height)
elseif panel.name == "title" then
get_header(fs, data)
elseif panel.name == "favs" then
get_favs(fs, data)
end
panel.func(fs, data, player, panel, is_recipe, is_usage)
end
end
@ -1504,7 +1485,11 @@ local function make_fs(player, data)
tab.formspec(player, data, fs)
end
get_panels(fs, player, data, full_height)
if data.query_item then
get_panels(fs, data, player)
else
get_items_fs(fs, data, player, full_height)
end
if #i3.tabs > 1 then
get_tabs_fs(fs, player, data, full_height)

View File

@ -34,7 +34,7 @@ local function init_hud(player)
},
}
if not i3.legacy_inventory then
if not i3.settings.legacy_inventory then
core.after(0, function()
player:hud_set_hotbar_itemcount(i3.settings.hotbar_len)
player:hud_set_hotbar_image"i3_hotbar.png"

View File

@ -38,6 +38,24 @@ i3.register_craft({
items = {"default:copper_ingot 7, default:tin_ingot, default:steel_ingot 2"},
})
i3.register_craft {
result = "default:tree",
items = {
"default:wood",
"",
"default:wood"
},
}
i3.register_craft {
result = "default:cobble 16",
items = {
"default:stone, default:stone",
"default:stone, , default:stone",
", default:stone, default:stone",
}
}
i3.register_craft({
grid = {
"X",
@ -311,22 +329,3 @@ i3.register_craft({
},
result = "default:mese 3",
})
i3.register_craft({
grid = {
"X #",
" ## ",
"X#X#",
"#X#X#",
"X X##X#X",
" ## ",
"#X#X#",
"#X#X#",
"X #",
},
key = {
['#'] = "default:wood",
['X'] = "default:glass",
},
result = "default:mese 3",
})