summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJP Guerrero <jeanpatrick.guerrero@gmail.com>2016-12-13 19:48:25 +0100
committerJP Guerrero <jeanpatrick.guerrero@gmail.com>2016-12-13 19:54:20 +0100
commit6c9e2b385a60e4f88dea9fde9aaca93cff6d1fe2 (patch)
treeeb482d34cefedf0b5b9895d435fb1536edc026ea
parent25f4b5d3f16d9c7b9e7458deddafc3e586cde9bf (diff)
Fail gracefully if recipe is greater than 3x3
-rw-r--r--init.lua10
1 files changed, 7 insertions, 3 deletions
diff --git a/init.lua b/init.lua
index 15b1769..0842944 100644
--- a/init.lua
+++ b/init.lua
@@ -90,7 +90,11 @@ function craftguide:get_recipe(player_name, tooltip_l, item, recipe_num, recipes
-- https://github.com/kilbith/xdecor/blob/master/handlers/helpers.lua#L1
local rows = ceil(table.maxn(items) / width)
- for i, v in pairs(items) do
+ if #items > 9 then
+ formspec = formspec.."label["..(offset_X)..","..(iY+2)..
+ ";Recipe is too big to\nbe displayed ("..
+ width.."x"..rows..")]"
+ else for i, v in pairs(items) do
local X = (i-1) % width + offset_X
local Y = ceil(i / width + ((iY + 2) - min(2, rows)))
local groups = extract_groups(v)
@@ -100,12 +104,12 @@ function craftguide:get_recipe(player_name, tooltip_l, item, recipe_num, recipes
formspec = formspec.."item_image_button["..X..","..Y..";1,1;"..
item..";"..item..";"..label.."]"..tooltip
+ end
end
-
local output = recipes[recipe_num].output
return formspec.."image["..(offset_X-1)..","..(iY+2)..
".12;0.9,0.7;craftguide_arrow.png]"..
- "item_image_button["..(offset_X-2)..","..(iY+2)..";1,1;"..
+ "item_image_button["..(offset_X-2)..","..(iY+2)..";1,1;"..
output..";"..item..";]"..tooltip_l
end