From 8a57da4bba88090adce38b897590d666303a468e Mon Sep 17 00:00:00 2001 From: k Date: Sun, 3 May 2020 15:29:38 +0200 Subject: [PATCH] Method to generate two different formspec layouts, big and small --- utils/formspec.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 utils/formspec.lua diff --git a/utils/formspec.lua b/utils/formspec.lua new file mode 100644 index 0000000..57a7156 --- /dev/null +++ b/utils/formspec.lua @@ -0,0 +1,38 @@ +function generate(size) + if size == "small" then + cfg = { + window_width = 8, + window_height = 9, + chest_width = 8, + chest_height = 4, + } + elseif size == "big" then + cfg = { + window_width = 14, + window_height = 10, + chest_width = 14, + chest_height = 5, + } + end + -- calc padding to vertically align center the chest and the player's inventory + local player_inv_y_orig = cfg.chest_height + 0.85 + local player_inv_x_orig = (cfg.window_width - 8) / 2 -- 8=player_inv_width + return "size[" .. + cfg.window_width .. "," .. cfg.window_height .. "]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "list[current_name;main;0,0.3;" .. + cfg.chest_width .. "," .. cfg.chest_height .. ";]" .. + "list[current_player;main;" .. + player_inv_x_orig .. "," .. player_inv_y_orig .. + ";8,1;]" .. + "list[current_player;main;" .. + player_inv_x_orig .. "," .. (player_inv_y_orig + 1.15) .. + ";8,3;8]" .. + "listring[current_name;main]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(player_inv_x_orig, player_inv_y_orig) +end + +return generate