diff options
author | Tim <t4im@users.noreply.github.com> | 2016-08-05 16:57:20 +0200 |
---|---|---|
committer | Tim <t4im@users.noreply.github.com> | 2016-08-05 17:00:16 +0200 |
commit | 51a00b957e81428aa5af1b0b5eddbfdd57729d77 (patch) | |
tree | 76050cf384a74bff4ee4f180ccbfcc88a336288f | |
parent | 18dd1207844cd0296a91288cc22ace9a04f39b77 (diff) |
Start item listing at index instead of skipping there.
Also fixes a linter warning.
-rw-r--r-- | .luacheckrc | 7 | ||||
-rw-r--r-- | init.lua | 20 |
2 files changed, 16 insertions, 11 deletions
diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..a21bce1 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,7 @@ +unused_args = false +allow_defined_top = true + +read_globals = { + "minetest", + "default", +} @@ -30,18 +30,16 @@ function craftguide:get_formspec(player_name, pagenum, recipe_num) "field[0.3,0.32;2.6,1;filter;;"..data.filter.."]".. default.gui_bg..default.gui_bg_img - local i, s = 0, 0 - for _, name in pairs(data.items) do - if s < (pagenum - 1) * npp then - s = s + 1 - else if i >= npp then break end - local X = i % 8 - local Y = ((i-X) / 8) + 1 + local first_item = (pagenum - 1) * npp + for i = first_item, first_item + npp - 1 do + local name = data.items[i + 1] + if not name then break end -- last page - formspec = formspec.."item_image_button["..X..","..Y..";1,1;".. - name..";"..name..";]" - i = i + 1 - end + local X = i % 8 + local Y = ((i % npp - X) / 8) + 1 + + formspec = formspec.."item_image_button["..X..","..Y..";1,1;".. + name..";"..name..";]" end if data.item and minetest.registered_items[data.item] then |