ender chest formspec v4

This commit is contained in:
AFCMS 2021-09-17 23:58:58 +02:00
parent 767c904258
commit f20fbfb95a
No known key found for this signature in database
GPG key ID: 8720389A25B652E3
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 = {}
mcl_formspec.label_color = "#313131"
function mcl_formspec.get_itemslot_bg(x, y, w, h) function mcl_formspec.get_itemslot_bg(x, y, w, h)
local out = "" local out = ""
for i = 0, w - 1, 1 do for i = 0, w - 1, 1 do
@ -11,13 +18,22 @@ function mcl_formspec.get_itemslot_bg(x, y, w, h)
end end
--This function will replace mcl_formspec.get_itemslot_bg then every formspec will be upgrade to version 4 --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 = "" local out = ""
for i = 0, w - 1, 1 do for i = 0, w - 1, 1 do
for j = 0, h - 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
end end
return out return out
end end

View file

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