diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 8ddc90c1d..321cc9aa3 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -1,15 +1,32 @@ -local string = string -local table = table - -local sf = string.format +local minetest, string, table = + minetest, string, table mcl_formspec = {} +local mcl_formspec = mcl_formspec + +local F = minetest.formspec_escape +local C = minetest.colorize + +-------------------------------------------------------------------------------- +-- Label -- +-------------------------------------------------------------------------------- mcl_formspec.label_color = "#313131" - mcl_formspec.label_size = tonumber(minetest.settings:get("mcl_label_font_size")) or 24 +-- NOTE: labels are vertically aligned to "center" (which is also affected by padding of the font) in the new coordinate system. +mcl_formspec.label_height = 0.625 +mcl_formspec.label_y_offset = 0.25 * mcl_formspec.label_height -- offset to counter the font padding. +mcl_formspec.label_style = string.format("style_type[label;font_size=%f]", mcl_formspec.label_size) +mcl_formspec.label_style_reset = "style_type[label;font=;font_size=;noclip=]" -mcl_formspec.apply_label_size = sf("style_type[label;font_size=%s]", mcl_formspec.label_size) +function mcl_formspec.create_label(x, y, text) + return table.concat{ + "label[", + x - mcl_formspec.itemslot_bu, ",", y + mcl_formspec.label_y_offset, ";", + F(C(mcl_formspec.label_color, text)), + "]", + } +end function mcl_formspec.get_itemslot_bg(x, y, w, h) local out = "" @@ -21,23 +38,109 @@ function mcl_formspec.get_itemslot_bg(x, y, w, h) return out end +-------------------------------------------------------------------------------- +-- Itemslot -- +-------------------------------------------------------------------------------- + --This function will replace mcl_formspec.get_itemslot_bg then every formspec will be upgrade to version 4 -local function get_slot(x, y, size) - local t = "image["..x-size..","..y-size..";".. 1+(size*2)..",".. 1+(size*2)..";mcl_formspec_itemslot.png]" - return t +-- Roughly 8 pixels (outer itemslot) out of 64 pixels. +mcl_formspec.itemslot_border_size = 0.0625 +mcl_formspec.itemslot_spacing_size = 0 + +-- resize factor for roughly 56 pixels (inner itemslot) to become 64 pixels (which is 1 formspec unit). +function mcl_formspec.get_factor(border) + local border = border or mcl_formspec.itemslot_border_size + return 1 / (1 - 2 * border) -- assuming default border values, 64 / 56 +end +mcl_formspec.itemslot_bu = mcl_formspec.get_factor(mcl_formspec.itemslot_border_size) * mcl_formspec.itemslot_border_size -- border unit + +function mcl_formspec.get_between(border, spacing, factor) + local border = border or mcl_formspec.itemslot_border_size + local spacing = spacing or mcl_formspec.itemslot_spacing_size + local factor = factor or mcl_formspec.get_factor(border) + return spacing + 2 * factor * border end -mcl_formspec.itemslot_border_size = 0.05 +function mcl_formspec.itemslot_unit(n, border, spacing, factor) + local n = n or 1 + local border = border or mcl_formspec.itemslot_border_size + local spacing = spacing or mcl_formspec.itemslot_spacing_size + local factor = factor or mcl_formspec.get_factor(border) + return n + n * mcl_formspec.get_between(border, spacing, factor) +end +mcl_formspec.itemslot_iu = mcl_formspec.itemslot_unit() -- itemslot unit -function mcl_formspec.get_itemslot_bg_v4(x, y, w, h, size) - if not size then - size = mcl_formspec.itemslot_border_size +function mcl_formspec.get_itemslot_style(border, spacing) + local border = border or mcl_formspec.itemslot_border_size + local spacing = spacing or mcl_formspec.itemslot_spacing_size + return table.concat{ + "style_type[list;", + "spacing=", mcl_formspec.get_between(border, spacing), + "]", + } +end +mcl_formspec.itemslot_style_reset = "style_type[list;noclip=;size=;spacing=]" +mcl_formspec.itemslot_style = mcl_formspec.get_itemslot_style() + +local function create_itemslot_bg(i, j, x, y, iu, bu, factor) + local img_x = x + i * iu - bu + local img_y = y + j * iu - bu + return table.concat{ + "image[", + img_x, ",", img_y, ";", + factor, ",", factor, ";", + "mcl_formspec_itemslot.png", + "]", + } +end + +function mcl_formspec.create_itemslot_bg(x, y, w, h, def) + -- Optional params: def + -- Params: + -- (x, y, w, h, def*) + -- def params: + -- { + -- < iu = ..., bu = ... >* + -- < border = ..., spacing = ..., factor = ..., >* + -- } + -- or { + -- < iu = ..., bu = ... >* + -- border = nil, spacing = nil, < factor = ..., >* + -- } + -- * indicates that the argument (or set of arguments) may be nil. + local iu, bu, border, spacing, factor + if def then + if def.border and def.spacing and def.factor then + iu = mcl_formspec.itemslot_unit(1, border, spacing, factor) + bu = factor * border + else + iu = def.iu or mcl_formspec.itemslot_iu + bu = def.bu or mcl_formspec.itemslot_bu + end + border = def.border or mcl_formspec.itemslot_border_size + spacing = def.spacing or mcl_formspec.itemslot_spacing_size + factor = def.factor or mcl_formspec.get_factor(border, spacing) + else + iu = mcl_formspec.itemslot_iu + bu = mcl_formspec.itemslot_bu + border = mcl_formspec.itemslot_border_size + spacing = mcl_formspec.itemslot_spacing_size + factor = mcl_formspec.get_factor(border, spacing) end + local out = "" for i = 0, w - 1, 1 do for j = 0, h - 1, 1 do - out = out .. get_slot(x+i+(i*0.25), y+j+(j*0.25), size) + out = out .. create_itemslot_bg(i, j, x, y, iu, bu, factor) end end return out -end \ No newline at end of file +end + +-------------------------------------------------------------------------------- +-- Miscellaneous -- +-------------------------------------------------------------------------------- + +mcl_formspec.margin = 0.078125 +mcl_formspec.padding = 0.5 +mcl_formspec.padding_slim = 0.25 diff --git a/mods/HUD/mcl_formspec/textures/mcl_formspec_itemslot.png b/mods/HUD/mcl_formspec/textures/mcl_formspec_itemslot.png index 84958ecd4..94deca755 100644 Binary files a/mods/HUD/mcl_formspec/textures/mcl_formspec_itemslot.png and b/mods/HUD/mcl_formspec/textures/mcl_formspec_itemslot.png differ diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index ee30c1b20..8d8c19b14 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -1,16 +1,18 @@ +local minetest, math, table, mcl_armor, mcl_formspec, mcl_player = + minetest, math, table, mcl_armor, mcl_formspec, mcl_player + +mcl_inventory = {} +local mcl_inventory = mcl_inventory + local S = minetest.get_translator(minetest.get_current_modname()) local F = minetest.formspec_escape local C = minetest.colorize -local table = table - -mcl_inventory = {} - --local mod_player = minetest.get_modpath("mcl_player") --local mod_craftguide = minetest.get_modpath("mcl_craftguide") -- Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left -function return_item(itemstack, dropper, pos, inv) +local function return_item(itemstack, dropper, pos, inv) if dropper:is_player() then -- Return to main inventory if inv:room_for_item("main", itemstack) then @@ -38,7 +40,7 @@ function return_item(itemstack, dropper, pos, inv) end -- Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left -function return_fields(player, name) +local function return_fields(player, name) local inv = player:get_inventory() local list = inv:get_list(name) if not list then return end @@ -49,6 +51,162 @@ function return_fields(player, name) end end +function mcl_inventory.formspec_armor(x, y, extra) + -- extra params: + -- { inv=... } + local iu = mcl_formspec.itemslot_iu + + local formspec = table.concat{ + mcl_formspec.create_itemslot_bg(x, y, 1, 4), + "list[current_player;armor;", + x, ",", y, ";", + "1,4;", + "]", + } + + local armor_slots = {"helmet", "chestplate", "leggings", "boots"} + for a=1,4 do + if extra.inv:get_stack("armor", a+1):is_empty() then + formspec = table.concat{ + formspec, + "image[", + x, ",", y + (a - 1) * iu, ";", + "1,1;mcl_inventory_empty_armor_slot_", armor_slots[a], ".png", + "]" + } + end + end + + return formspec +end + +mcl_inventory.FORMSPEC_PLAYER_PREVIEW_WIDTH_FACTOR = 102 / 108 -- eyeballed value +function mcl_inventory.formspec_player_preview(x, y, extra) + -- extra params: + -- { player=... } + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local width = mcl_inventory.FORMSPEC_PLAYER_PREVIEW_WIDTH_FACTOR * 3 * iu + local height = 4 * iu + local formspec = table.concat{ + "background9[", + x - bu, ",", y - bu, ";", + width, ",", height, ";", + "mcl_inventory_player_preview_box9.png;false;3", + "]", + } + if minetest.settings:get_bool("3d_player_preview", true) then + formspec = table.concat{ + formspec, + -- TODO: model is sometimes offsetted to the right due to an engine bug(or possibly a model bug). + mcl_player.get_player_formspec_model(extra.player, x - bu, y - bu, width, height, "") + } + else + formspec = table.concat{ + formspec, + -- TODO: better image size+centered. Or better, remove it. see #1869 + "image[", x, ",", y, ";", width, ",", height, ";", mcl_player.player_get_preview(extra.player), "]", + } + end + + return formspec +end + +function mcl_inventory.formspec_left_hand(x, y, extra) + -- extra params: + -- { inv=... } + -- TODO: implement left hand + -- NOTE: we're probably not using armor index #4, change as necessary. + if true then return "" end + + -- Left hand slot formspec + local formspec = table.concat{ + -- left hand presupport + mcl_formspec.create_itemslot_bg(x, y, 1, 1), + "list[current_player;armor;", + x, ",", y, ";", + "1,1;4", + "]", + + } + + if extra.inv:get_stack("armor", 5):is_empty() then + formspec = table.concat{ + formspec, + "image[", + x, ",", y, ";", + "1,1;mcl_inventory_empty_armor_slot_shield.png", + "]" + } + end + + return formspec +end + +function mcl_inventory.formspec_crafting(x, y, extra) + -- Optional params: extra + -- extra params: + -- { * } + local margin = mcl_formspec.margin + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local length = 2 * iu + local arrow_x = x + length + margin + local arrow_y = y + iu / 2 + local output_x = arrow_x + 1 + margin + bu + local formspec = table.concat{ + (extra and extra.label_y) and mcl_formspec.create_label(x, extra.label_y, S("Crafting")) or "", + mcl_formspec.create_itemslot_bg(x, y, 2, 2), + "list[current_player;craft;", + x, ",", y, ";", + "2,2", + "]", + + "image[", + arrow_x, ",", arrow_y, ";", + "1,1;crafting_formspec_arrow.png", + "]", + + mcl_formspec.create_itemslot_bg(output_x, arrow_y, 1, 1), + "list[current_player;craftpreview;", + output_x, ",", arrow_y, ";", + "1,1;", + "]", + } + + return formspec +end + +function mcl_inventory.formspec_inventory(x, y, extra) + -- Optional params: extra + -- extra params: + -- { * * } + local iu = mcl_formspec.itemslot_iu + local formspec = table.concat{ + (extra and extra.label_y) and mcl_formspec.create_label(x, extra.label_y, S("Inventory")) or "", + mcl_formspec.create_itemslot_bg(x, y, 9, 3), + "list[current_player;main;", + x, ",", y, ";", + "9,3;9", + "]", + } + + if extra and extra.hotbar_y then + formspec = table.concat{ + formspec, + mcl_formspec.create_itemslot_bg(x, extra.hotbar_y, 9, 1), + "list[current_player;main;", + x, ",", extra.hotbar_y, ";", + "9,1;", + "]", + } + end + + return formspec +end + local function set_inventory(player, armor_change_only) if minetest.is_creative_enabled(player:get_player_name()) then if armor_change_only then @@ -59,84 +217,68 @@ local function set_inventory(player, armor_change_only) end return end + local inv = player:get_inventory() inv:set_width("craft", 2) inv:set_size("craft", 4) - -- Show armor and player image - local player_preview - if minetest.settings:get_bool("3d_player_preview", true) then - player_preview = mcl_player.get_player_formspec_model(player, 1.625, 0.375, 3.5, 4.75, "") - else - player_preview = "image[1.625,0.375;3.5,4.75;"..mcl_player.player_get_preview(player).."]" - end - --player_preview = "image[1.625,0.375;3.5,4.75;"..mcl_player.player_get_preview(player).."]" - - local armor_slots = {"helmet", "chestplate", "leggings", "boots"} - local armor_slot_imgs = "" - for a=1,4 do - if inv:get_stack("armor", a+1):is_empty() then - armor_slot_imgs = armor_slot_imgs .. "image[0.375,".. 0.375 + (a-1) + (a-1)* 0.25 ..";1,1;mcl_inventory_empty_armor_slot_"..armor_slots[a]..".png]" - end - end - - --"label[0.375,5.575;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", + local padding = mcl_formspec.padding + local padding_slim = mcl_formspec.padding_slim + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + local label_height = mcl_formspec.label_height local form = table.concat({ "formspec_version[4]", - "size[11.75,10.9]", - mcl_formspec.apply_label_size, - mcl_formspec.get_itemslot_bg_v4(0.375, 0.375, 1, 1), - mcl_formspec.get_itemslot_bg_v4(0.375, 1.625, 1, 1), - mcl_formspec.get_itemslot_bg_v4(0.375, 2.875, 1, 1), - mcl_formspec.get_itemslot_bg_v4(0.375, 4.125, 1, 1), - armor_slot_imgs, - "list[current_player;armor;0.375,0.375;1,1;1]", - "list[current_player;armor;0.375,1.625;1,1;2]", - "list[current_player;armor;0.375,2.875;1,1;3]", - "list[current_player;armor;0.375,4.125;1,1;4]", + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 2 * padding_slim + 8 * iu - 2 * bu, "]", - --TMP FAKE PLAYER PREVIEW - "box[1.625,0.375;3.5,4.75;"..mcl_formspec.label_color.."]", - player_preview, + mcl_formspec.label_style, + mcl_formspec.itemslot_style, - --left hand presupport - --mcl_formspec.get_itemslot_bg_v4(5.375, 4.125, 1, 1), - --"list[current_player;armor;5.375,4.125;1,1;4]", + mcl_inventory.formspec_armor(padding, padding, { inv = inv }), + mcl_inventory.formspec_player_preview( + padding + iu, + padding, + { player = player } + ), + mcl_inventory.formspec_left_hand( + padding + iu + mcl_inventory.FORMSPEC_PLAYER_PREVIEW_WIDTH_FACTOR * 3 * iu, + padding + 3 * iu, + { inv = inv } + ), - --buttons + mcl_inventory.formspec_crafting( + padding + 5 * iu, + padding + label_height, + { label_y = padding } + ), - --skins - "image_button[5.375,4.125;1,1;mcl_skins_button.png;__mcl_skins;]", - "tooltip[__mcl_skins;"..F(S("Select player skin")).."]", + -- mcl_inventory.formspec_buttons() - --crafting guide button - "image_button[7.25,4.125;1,1;craftguide_book.png;__mcl_craftguide;]", - "tooltip[__mcl_craftguide;"..F(S("Recipe book")).."]", + mcl_inventory.formspec_inventory( + padding, + padding + padding_slim + 4 * iu, + { hotbar_y = padding + 2 * padding_slim + 7 * iu } + ), - --achievements button - "image_button[9.125,4.125;1,1;mcl_achievements_button.png;__mcl_achievements;]", - "tooltip[__mcl_achievements;"..F(S("Achievements")).."]", + -- TODO: skins button + -- "image_button[5.375,4.125;1,1;mcl_skins_button.png;__mcl_skins;]", + -- "tooltip[__mcl_skins;"..F(S("Select player skin")).."]", - --help button - "image_button[10.375,4.125;1,1;doc_button_icon_lores.png;__mcl_doc;]", - "tooltip[__mcl_doc;"..F(S("Help")).."]", + -- TODO: crafting guide button + -- "image_button[7.25,4.125;1,1;craftguide_book.png;__mcl_craftguide;]", + -- "tooltip[__mcl_craftguide;"..F(S("Recipe book")).."]", - "label[6.625,0.375;"..F(C(mcl_formspec.label_color, S("Crafting"))).."]", + -- TODO: achievements button + -- "image_button[9.125,4.125;1,1;mcl_achievements_button.png;__mcl_achievements;]", + -- "tooltip[__mcl_achievements;"..F(S("Achievements")).."]", - --crafting interface - mcl_formspec.get_itemslot_bg_v4(6.625, 0.75, 2, 2), - "list[current_player;craft;6.625,0.75;2,2]", - "image[9.125,1.375;1,1;crafting_formspec_arrow.png]", - mcl_formspec.get_itemslot_bg_v4(10.375, 1.375, 1, 1), - "list[current_player;craftpreview;10.375,1.375;1,1;]", + -- TODO: help button + -- "image_button[10.375,4.125;1,1;doc_button_icon_lores.png;__mcl_doc;]", + -- "tooltip[__mcl_doc;"..F(S("Help")).."]", --player inventory - mcl_formspec.get_itemslot_bg_v4(0.375, 5.575, 9, 3), - mcl_formspec.get_itemslot_bg_v4(0.375, 9.525, 9, 1), - "list[current_player;main;0.375,5.575;9,3;9]", - "list[current_player;main;0.375,9.525;9,1;]", --for shortcuts "listring[current_player;main]", @@ -146,48 +288,6 @@ local function set_inventory(player, armor_change_only) "listring[current_player;main]", }) - local form2 = "size[9,8.75]".. - --"background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png]".. - player_preview.. - --armor - "list[current_player;armor;0,0;1,1;1]".. - "list[current_player;armor;0,1;1,1;2]".. - "list[current_player;armor;0,2;1,1;3]".. - "list[current_player;armor;0,3;1,1;4]".. - mcl_formspec.get_itemslot_bg(0,0,1,1).. - mcl_formspec.get_itemslot_bg(0,1,1,1).. - mcl_formspec.get_itemslot_bg(0,2,1,1).. - mcl_formspec.get_itemslot_bg(0,3,1,1).. - --armor_slot_imgs.. - -- craft and inventory - "label[0,4;"..F(C("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - "list[current_player;main;0,7.74;9,1;]".. - "label[4,0.5;"..F(C("#313131", S("Crafting"))).."]".. - "list[current_player;craft;4,1;2,2]".. - "list[current_player;craftpreview;7,1.5;1,1;]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - mcl_formspec.get_itemslot_bg(4,1,2,2).. - mcl_formspec.get_itemslot_bg(7,1.5,1,1).. - -- crafting guide button - "image_button[4.5,3;1,1;craftguide_book.png;__mcl_craftguide;]".. - "tooltip[__mcl_craftguide;"..F(S("Recipe book")).."]".. - -- help button - "image_button[8,3;1,1;doc_button_icon_lores.png;__mcl_doc;]".. - "tooltip[__mcl_doc;"..F(S("Help")).."]".. - -- skins button - "image_button[3,3;1,1;mcl_skins_button.png;__mcl_skins;]".. - "tooltip[__mcl_skins;"..F(S("Select player skin")).."]".. - -- achievements button - "image_button[7,3;1,1;mcl_achievements_button.png;__mcl_achievements;]".. - "tooltip[__mcl_achievements;"..F(S("Achievements")).."]".. - -- for shortcuts - "listring[current_player;main]".. - "listring[current_player;armor]".. - "listring[current_player;main]" .. - "listring[current_player;craft]" .. - "listring[current_player;main]" player:set_inventory_formspec(form) end @@ -250,4 +350,3 @@ end) if minetest.is_creative_enabled("") then dofile(minetest.get_modpath(minetest.get_current_modname()).."/creative.lua") end - diff --git a/mods/HUD/mcl_inventory/textures/mcl_inventory_empty_armor_slot_boots.png b/mods/HUD/mcl_inventory/textures/mcl_inventory_empty_armor_slot_boots.png index cb9f2bec3..ecb10d0fe 100644 Binary files a/mods/HUD/mcl_inventory/textures/mcl_inventory_empty_armor_slot_boots.png and b/mods/HUD/mcl_inventory/textures/mcl_inventory_empty_armor_slot_boots.png differ diff --git a/mods/HUD/mcl_inventory/textures/mcl_inventory_player_preview_box9.png b/mods/HUD/mcl_inventory/textures/mcl_inventory_player_preview_box9.png new file mode 100644 index 000000000..30e5d17fe Binary files /dev/null and b/mods/HUD/mcl_inventory/textures/mcl_inventory_player_preview_box9.png differ diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index 10d07ec7c..fc7a717a0 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -1,11 +1,12 @@ +local minetest, math, string, table, mcl_formspec, mcl_util = + minetest, math, string, table, mcl_formspec, mcl_util + +mcl_chests = {} +local mcl_chests = mcl_chests + local S = minetest.get_translator(minetest.get_current_modname()) local F = minetest.formspec_escape local C = minetest.colorize - -local string = string -local table = table -local math = math - local sf = string.format local mod_doc = minetest.get_modpath("doc") @@ -253,6 +254,21 @@ local function player_chest_close(player) open_chests[name] = nil end +function mcl_chests.formspec_storage(x, y, extra) + -- extra params: + -- { list_inv=..., * } + local formspec = table.concat{ + (extra.label_y and extra.label_text) and mcl_formspec.create_label(x, extra.label_y, extra.label_text) or "", + mcl_formspec.create_itemslot_bg(x, y, 9, 3), + "list[", extra.list_inv, ";", + x, ",", y, ";", + "9,3;", + "]", + } + + return formspec +end + -- This is a helper function to register both chests and trapped chests. Trapped chests will make use of the additional parameters local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tiles_table, hidden, mesecons, on_rightclick_addendum, on_rightclick_addendum_left, on_rightclick_addendum_right, drop, canonical_basename) -- START OF register_chest FUNCTION BODY @@ -482,27 +498,34 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile name = S("Chest") end + local padding = mcl_formspec.padding + local padding_slim = mcl_formspec.padding_slim + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local label_height = mcl_formspec.label_height + + local storage_list_inv = sf("nodemeta:%d,%d,%d;main", pos.x, pos.y, pos.z) minetest.show_formspec(clicker:get_player_name(), sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), table.concat({ "formspec_version[4]", - "size[11.75,10.425]", - mcl_formspec.apply_label_size, + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 2 * label_height + 7 * iu + 2 * padding_slim - 2 * bu, "]", + mcl_formspec.label_style, + mcl_formspec.itemslot_style, - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + mcl_chests.formspec_storage(padding, padding + label_height, { + list_inv = storage_list_inv, + label_y = padding, + label_text = name, + }), - mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), - sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos.x, pos.y, pos.z), + mcl_inventory.formspec_inventory(padding, padding + 2 * label_height + 3 * iu + padding_slim, { + hotbar_y = padding + 2 * label_height + 6 * iu + 2 * padding_slim, + label_y = padding + label_height + 3 * iu + padding_slim + }), - "label[0.375,4.7;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - - mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), - "list[current_player;main;0.375,5.1;9,3;9]", - - mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), - "list[current_player;main;0.375,9.05;9,1;]", - - sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), + "listring[", storage_list_inv, "]", "listring[current_player;main]", }) ) @@ -642,37 +665,47 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile name = S("Large Chest") end + local padding = mcl_formspec.padding + local padding_slim = mcl_formspec.padding_slim + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local label_height = mcl_formspec.label_height + + local storage_list_inv_workaround = sf("nodemeta:%d,%d,%d;input", pos.x, pos.y, pos.z) + local storage_list_inv = sf("nodemeta:%d,%d,%d;main", pos.x, pos.y, pos.z) + local storage_list_inv_other = sf("nodemeta:%d,%d,%d;main", pos_other.x, pos_other.y, pos_other.z) minetest.show_formspec(clicker:get_player_name(), sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), table.concat({ "formspec_version[4]", - "size[11.75,14.15]", - mcl_formspec.apply_label_size, + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 2 * label_height + 10 * iu + 2 * padding_slim - 2 * bu, "]", - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + mcl_formspec.label_style, + mcl_formspec.itemslot_style, - mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), - sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos.x, pos.y, pos.z), + mcl_chests.formspec_storage(padding, padding + label_height, { + list_inv = storage_list_inv, + label_y = padding, + label_text = name, + }), + mcl_chests.formspec_storage(padding, padding + label_height + 3 * iu, { + list_inv = storage_list_inv_other, + }), - mcl_formspec.get_itemslot_bg_v4(0.375, 4.5, 9, 3), - sf("list[nodemeta:%s,%s,%s;main;0.375,4.5;9,3;]", pos_other.x, pos_other.y, pos_other.z), + mcl_inventory.formspec_inventory(padding, padding + 2 * label_height + 6 * iu + padding_slim, { + hotbar_y = padding + 2 * label_height + 9 * iu + 2 * padding_slim, + label_y = padding + label_height + 6 * iu + padding_slim + }), - "label[0.375,8.45;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - - mcl_formspec.get_itemslot_bg_v4(0.375, 8.825, 9, 3), - "list[current_player;main;0.375,8.825;9,3;9]", - - mcl_formspec.get_itemslot_bg_v4(0.375, 12.775, 9, 1), - "list[current_player;main;0.375,12.775;9,1;]", - - --BEGIN OF LISTRING WORKAROUND + -- BEGIN listring workaround "listring[current_player;main]", - sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z), - --END OF LISTRING WORKAROUND - "listring[current_player;main]".. - sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), + "listring[", storage_list_inv_workaround, "]", + -- END listring workaround "listring[current_player;main]", - sf("listring[nodemeta:%s,%s,%s;main]", pos_other.x, pos_other.y, pos_other.z), + "listring[", storage_list_inv, "]", + "listring[current_player;main]", + "listring[", storage_list_inv_other, "]", }) ) @@ -785,53 +818,63 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile _mcl_blast_resistance = 2.5, _mcl_hardness = 2.5, - on_rightclick = function(pos, node, clicker) - local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right") + on_rightclick = function(pos_other, node, clicker) + local pos = mcl_util.get_double_container_neighbor_pos(pos_other, node.param2, "right") if minetest.registered_nodes[minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name].groups.opaque == 1 or minetest.registered_nodes[minetest.get_node({x = pos_other.x, y = pos_other.y + 1, z = pos_other.z}).name].groups.opaque == 1 then -- won't open if there is no space from the top return false end - local name = minetest.get_meta(pos_other):get_string("name") + local name = minetest.get_meta(pos):get_string("name") if name == "" then - name = minetest.get_meta(pos):get_string("name") + name = minetest.get_meta(pos_other):get_string("name") end if name == "" then name = S("Large Chest") end + local padding = mcl_formspec.padding + local padding_slim = mcl_formspec.padding_slim + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local label_height = mcl_formspec.label_height + + local storage_list_inv_workaround = sf("nodemeta:%d,%d,%d;input", pos.x, pos.y, pos.z) + local storage_list_inv = sf("nodemeta:%d,%d,%d;main", pos.x, pos.y, pos.z) + local storage_list_inv_other = sf("nodemeta:%d,%d,%d;main", pos_other.x, pos_other.y, pos_other.z) minetest.show_formspec(clicker:get_player_name(), - sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), + sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos_other.x, pos_other.y, pos_other.z), table.concat({ "formspec_version[4]", - "size[11.75,14.15]", - mcl_formspec.apply_label_size, + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 2 * label_height + 10 * iu + 2 * padding_slim - 2 * bu, "]", - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + mcl_formspec.label_style, + mcl_formspec.itemslot_style, - mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), - sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos_other.x, pos_other.y, pos_other.z), + mcl_chests.formspec_storage(padding, padding + label_height, { + list_inv = storage_list_inv, + label_y = padding, + label_text = name, + }), + mcl_chests.formspec_storage(padding, padding + label_height + 3 * iu, { + list_inv = storage_list_inv_other, + }), - mcl_formspec.get_itemslot_bg_v4(0.375, 4.5, 9, 3), - sf("list[nodemeta:%s,%s,%s;main;0.375,4.5;9,3;]", pos.x, pos.y, pos.z), + mcl_inventory.formspec_inventory(padding, padding + 2 * label_height + 6 * iu + padding_slim, { + hotbar_y = padding + 2 * label_height + 9 * iu + 2 * padding_slim, + label_y = padding + label_height + 6 * iu + padding_slim + }), - "label[0.375,8.45;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - - mcl_formspec.get_itemslot_bg_v4(0.375, 8.825, 9, 3), - "list[current_player;main;0.375,8.825;9,3;9]", - - mcl_formspec.get_itemslot_bg_v4(0.375, 12.775, 9, 1), - "list[current_player;main;0.375,12.775;9,1;]", - - --BEGIN OF LISTRING WORKAROUND + -- BEGIN listring workaround "listring[current_player;main]", - sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z), - --END OF LISTRING WORKAROUND - "listring[current_player;main]".. - sf("listring[nodemeta:%s,%s,%s;main]", pos_other.x, pos_other.y, pos_other.z), + "listring[", storage_list_inv_workaround, "]", + -- END listring workaround "listring[current_player;main]", - sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), + "listring[", storage_list_inv, "]", + "listring[current_player;main]", + "listring[", storage_list_inv_other, "]", }) ) @@ -1032,27 +1075,6 @@ minetest.register_node("mcl_chests:ender_chest", { end, }) -local formspec_ender_chest = table.concat({ - "formspec_version[4]", - "size[11.75,10.425]", - mcl_formspec.apply_label_size, - - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, S("Ender Chest"))).."]", - - mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), - "list[current_player;enderchest;0.375,0.75;9,3;]", - - "label[0.375,4.7;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - - mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), - "list[current_player;main;0.375,5.1;9,3;9]", - - mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), - "list[current_player;main;0.375,9.05;9,1;]", - - "listring[current_player;enderchest]", - "listring[current_player;main]", -}) minetest.register_node("mcl_chests:ender_chest_small", { @@ -1091,7 +1113,39 @@ minetest.register_node("mcl_chests:ender_chest_small", { -- won't open if there is no space from the top return false end - minetest.show_formspec(clicker:get_player_name(), "mcl_chests:ender_chest_"..clicker:get_player_name(), formspec_ender_chest) + + local padding = mcl_formspec.padding + local padding_slim = mcl_formspec.padding_slim + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local label_height = mcl_formspec.label_height + + minetest.show_formspec(clicker:get_player_name(), + "mcl_chests:ender_chest_"..clicker:get_player_name(), + table.concat{ + "formspec_version[4]", + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 2 * label_height + 7 * iu + 2 * padding_slim - 2 * bu, "]", + + mcl_formspec.label_style, + mcl_formspec.itemslot_style, + + mcl_chests.formspec_storage(padding, padding + label_height, { + list_inv = "current_player;enderchest", + label_y = padding, + label_text = S("Ender Chest"), + }), + + mcl_inventory.formspec_inventory(padding, padding + 2 * label_height + 3 * iu + padding_slim, { + hotbar_y = padding + 2 * label_height + 6 * iu + 2 * padding_slim, + label_y = padding + label_height + 3 * iu + padding_slim + }), + + "listring[current_player;enderchest]", + "listring[current_player;main]", + } + ) + player_chest_open(clicker, pos, "mcl_chests:ender_chest_small", {"mcl_chests_ender.png"}, node.param2, false, "mcl_chests_enderchest", "mcl_chests_chest") end, on_receive_fields = function(pos, formname, fields, sender) @@ -1165,27 +1219,34 @@ local function formspec_shulker_box(name) name = S("Shulker Box") end - return table.concat({ + local padding = mcl_formspec.padding + local padding_slim = mcl_formspec.padding_slim + local bu = mcl_formspec.itemslot_bu + local iu = mcl_formspec.itemslot_iu + + local label_height = mcl_formspec.label_height + + return table.concat{ "formspec_version[4]", - "size[11.75,10.425]", - mcl_formspec.apply_label_size, + "size[", 2 * padding + 9 * iu - 2 * bu, ",", 2 * padding + 2 * label_height + 7 * iu + 2 * padding_slim - 2 * bu, "]", - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + mcl_formspec.label_style, + mcl_formspec.itemslot_style, - mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), - "list[context;main;0.375,0.75;9,3;]", + mcl_chests.formspec_storage(padding, padding + label_height, { + list_inv = "context;main", + label_y = padding, + label_text = name, + }), - "label[0.375,4.7;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - - mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), - "list[current_player;main;0.375,5.1;9,3;9]", - - mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), - "list[current_player;main;0.375,9.05;9,1;]", + mcl_inventory.formspec_inventory(padding, padding + 2 * label_height + 3 * iu + padding_slim, { + hotbar_y = padding + 2 * label_height + 6 * iu + 2 * padding_slim, + label_y = padding + label_height + 3 * iu + padding_slim + }), "listring[context;main]", "listring[current_player;main]", - }) + } end local function set_shulkerbox_meta(nmeta, imeta)