ender chest formspec v4

This commit is contained in:
AFCMS 2021-09-17 23:58:58 +02:00
parent 0c7243609f
commit 0baef425d5
3 changed files with 71 additions and 23 deletions

View File

@ -0,0 +1,20 @@
Formspecs are an important part of game and mod development.
This guide will learn you rules about creation of formspecs for the MineClone2 game.
First of all, MineClone2 aims to support ONLY last formspec version. Many utility functions will not work with formspec v1 or v2.
Label font size should be 25 to be minecraft like. We arent modifying formspec prepend in order to not break existing mods.
Just use this code to apply it to your formspec:
```lua
"style_type[label;font_size=25]",
```
The typical width of an inventory formspec is `0.375 + 9 + (9 * 0.25) + 0.375 = 12`
Margins is 0.375
Space between 1st inventory line and the rest of inventory is 0.4
Labels should have 0.375 space above if there is no other stuff above and 0.45 between content
+ 0.375 under

View File

@ -1,5 +1,12 @@
local string = string
local table = table
local sf = string.format
mcl_formspec = {}
mcl_formspec.label_color = "#313131"
function mcl_formspec.get_itemslot_bg(x, y, w, h)
local out = ""
for i = 0, w - 1, 1 do
@ -11,13 +18,22 @@ function mcl_formspec.get_itemslot_bg(x, y, w, h)
end
--This function will replace mcl_formspec.get_itemslot_bg then every formspec will be upgrade to version 4
function mcl_formspec.get_itemslot_bg_v4(x, y, w, h)
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
end
mcl_formspec.itemslot_border_size = 0.05
function mcl_formspec.get_itemslot_bg_v4(x, y, w, h, size)
if not size then
size = mcl_formspec.itemslot_border_size
end
local out = ""
for i = 0, w - 1, 1 do
for j = 0, h - 1, 1 do
out = out .."image["..x+i+(i*0.25)..","..y+j+(j*0.25)..";1,1;mcl_formspec_itemslot.png]"
out = out .. get_slot(x+i+(i*0.25), y+j+(j*0.25), size)
end
end
return out
end
end

View File

@ -1,4 +1,6 @@
local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape
local C = minetest.colorize
local mod_doc = minetest.get_modpath("doc")
-- Chest Entity
@ -476,10 +478,10 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile
minetest.show_formspec(clicker:get_player_name(),
"mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z,
"size[9,8.75]"..
"label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", name)).."]"..
"label[0,0;"..F(minetest.colorize("#313131", name)).."]"..
"list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,0.5,9,3)..
"label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]"..
"label[0,4.0;"..F(minetest.colorize("#313131", S("Inventory"))).."]"..
"list[current_player;main;0,4.5;9,3;9]"..
mcl_formspec.get_itemslot_bg(0,4.5,9,3)..
"list[current_player;main;0,7.74;9,1;]"..
@ -625,12 +627,12 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile
minetest.show_formspec(clicker:get_player_name(),
"mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z,
"size[9,11.5]"..
"label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", name)).."]"..
"label[0,0;"..F(minetest.colorize("#313131", name)).."]"..
"list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,0.5,9,3)..
"list[nodemeta:"..pos_other.x..","..pos_other.y..","..pos_other.z..";main;0,3.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,3.5,9,3)..
"label[0,7;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]"..
"label[0,7;"..F(minetest.colorize("#313131", S("Inventory"))).."]"..
"list[current_player;main;0,7.5;9,3;9]"..
mcl_formspec.get_itemslot_bg(0,7.5,9,3)..
"list[current_player;main;0,10.75;9,1;]"..
@ -773,12 +775,12 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile
"mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z,
"size[9,11.5]"..
"label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", name)).."]"..
"label[0,0;"..F(minetest.colorize("#313131", name)).."]"..
"list[nodemeta:"..pos_other.x..","..pos_other.y..","..pos_other.z..";main;0,0.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,0.5,9,3)..
"list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,3.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,3.5,9,3)..
"label[0,7;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]"..
"label[0,7;"..F(minetest.colorize("#313131", S("Inventory"))).."]"..
"list[current_player;main;0,7.5;9,3;9]"..
mcl_formspec.get_itemslot_bg(0,7.5,9,3)..
"list[current_player;main;0,10.75;9,1;]"..
@ -985,17 +987,27 @@ minetest.register_node("mcl_chests:ender_chest", {
end,
})
local formspec_ender_chest = "size[9,8.75]"..
"label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Ender Chest"))).."]"..
"list[current_player;enderchest;0,0.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,0.5,9,3)..
"label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]"..
"list[current_player;main;0,4.5;9,3;9]"..
mcl_formspec.get_itemslot_bg(0,4.5,9,3)..
"list[current_player;main;0,7.74;9,1;]"..
mcl_formspec.get_itemslot_bg(0,7.74,9,1)..
"listring[current_player;enderchest]"..
"listring[current_player;main]"
local formspec_ender_chest = table.concat({
"formspec_version[4]",
"size[12,10.375]",
"style_type[label;font_size=25]",
"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, 9, 1),
"list[current_player;main;0.375,9;9,1;]",
"listring[current_player;enderchest]",
"listring[current_player;main]",
})
minetest.register_node("mcl_chests:ender_chest_small", {
@ -1107,10 +1119,10 @@ local function formspec_shulker_box(name)
name = S("Shulker Box")
end
return "size[9,8.75]"..
"label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", name)).."]"..
"label[0,0;"..F(minetest.colorize("#313131", name)).."]"..
"list[context;main;0,0.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,0.5,9,3)..
"label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]"..
"label[0,4.0;"..F(minetest.colorize("#313131", S("Inventory"))).."]"..
"list[current_player;main;0,4.5;9,3;9]"..
mcl_formspec.get_itemslot_bg(0,4.5,9,3)..
"list[current_player;main;0,7.74;9,1;]"..