Optimize some formspecs triggering

This commit is contained in:
jp 2015-08-22 22:06:36 +02:00
parent c35ed36b53
commit 2dc1d7f429
4 changed files with 30 additions and 23 deletions

View File

@ -3,13 +3,18 @@ local enchanting = {}
function enchanting.construct(pos)
local meta = minetest.get_meta(pos)
local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
meta:set_string("formspec", "size[8,7;]"..xbg..
local concat = table.concat
local f = {"size[8,7;]"..xbg..
"label[0.85,-0.15;Enchant]".."image[0.6,0.2;2,2;xdecor_enchbook.png]"..
"list[current_name;tool;0.5,2;1,1;]"..
"list[current_name;mese;1.5,2;1,1;]".."image[1.5,2;1,1;mese_layout.png]"..
"image_button[2.75,0;5,1.5;ench_bg.png;durable;Durable]"..
"image_button[2.75,1.5;5,1.5;ench_bg.png;fast;Fast]"..
"list[current_player;main;0,3.3;8,4;]")
"list[current_player;main;0,3.3;8,4;]"}
local formspec = concat(f)
meta:set_string("formspec", formspec)
meta:set_string("infotext", "Enchantment Table")
local inv = meta:get_inventory()

View File

@ -3,14 +3,18 @@ local hive = {}
function hive.construct(pos)
local meta = minetest.get_meta(pos)
local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
local concat = table.concat
meta:set_string("formspec", "size[8,5;]"..xbg..
local f = {"size[8,5;]"..xbg..
"label[1.35,0;Bees are making honey\nwith pollen around...]"..
"image[0.2,-0.1;1,1;flowers_dandelion_white.png]"..
"image[7,0.1;1,1;flowers_viola.png]"..
"image[6,0;1,1;xdecor_bee.png]"..
"list[current_name;honey;5,0;1,1;]"..
"list[current_player;main;0,1.35;8,4;]")
"list[current_player;main;0,1.35;8,4;]"}
local formspec = concat(f)
meta:set_string("formspec", formspec)
meta:set_string("infotext", "Artificial Hive")
local inv = meta:get_inventory()
inv:set_size("honey", 1)

View File

@ -1,4 +1,6 @@
local mailbox = {}
local concat = table.concat
local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
xdecor.register("mailbox", {
description = "Mailbox",
@ -25,9 +27,8 @@ xdecor.register("mailbox", {
local owner = meta:get_string("owner")
if owner == player then
minetest.show_formspec(player, "default:chest_locked",
mailbox.get_formspec(pos))
else minetest.show_formspec(player, "default:chest_locked",
minetest.show_formspec(player, "", mailbox.get_formspec(pos))
else minetest.show_formspec(player, "",
mailbox.get_insert_formspec(pos, owner))
end
end,
@ -59,24 +60,22 @@ xdecor.register("mailbox", {
end
})
local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
function mailbox.get_formspec(pos)
local spos = pos.x..","..pos.y..","..pos.z
local formspec =
"size[8,9]"..xbg..
local f = {"size[8,9]"..xbg..
"label[0,0;You received...]"..
"list[nodemeta:"..spos..";main;0,0.75;8,4;]"..
"list[current_player;main;0,5.25;8,4;]"
"list[current_player;main;0,5.25;8,4;]"}
local formspec = concat(f)
return formspec
end
function mailbox.get_insert_formspec(pos, owner)
local spos = pos.x..","..pos.y..","..pos.z
local formspec =
"size[8,5]"..xbg..
local f = {"size[8,5]"..xbg..
"label[0.5,0;Send your goods\nto "..owner.." :]"..
"list[nodemeta:"..spos..";drop;3.5,0;1,1;]"..
"list[current_player;main;0,1.25;8,4;]"
"list[current_player;main;0,1.25;8,4;]"}
local formspec = concat(f)
return formspec
end

View File

@ -4,8 +4,8 @@ local concat = table.concat
local material = {
"cloud", -- Only used for the formspec display.
"wood", "junglewood", "pinewood", "acacia_wood",
"tree", "jungletree", "pinetree", "acacia_tree",
"wood", "junglewood", "pine_wood", "acacia_wood",
"tree", "jungletree", "pine_tree", "acacia_tree",
"cobble", "mossycobble", "desert_cobble",
"stone", "sandstone", "desert_stone", "obsidian",
"stonebrick", "sandstonebrick", "desert_stonebrick", "obsidianbrick",
@ -98,6 +98,7 @@ function worktable.construct(pos)
end
function worktable.fields(pos, _, fields, sender)
local player = sender:get_player_name()
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local inputstack = inv:get_stack("input", 1)
@ -120,13 +121,11 @@ function worktable.fields(pos, _, fields, sender)
inv:set_stack("input", 1, inputstack)
end
end
if fields["storage"] then
local player = sender:get_player_name()
minetest.show_formspec(player, "xdecor:worktable", worktable.storage(pos))
if fields.storage then
minetest.show_formspec(player, "", worktable.storage(pos))
end
if fields["craft"] then
local player = sender:get_player_name()
minetest.show_formspec(player, "xdecor:worktable", worktable.crafting(pos))
if fields.craft then
minetest.show_formspec(player, "", worktable.crafting(pos))
end
end