},
groups = {cracky=3, oddly_breakable_by_hand=1},
on_rotate = screwdriver.rotate_simple,
- after_place_node = function(pos, placer, _)
+ after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
local player_name = placer:get_player_name()
inv:set_size("mailbox", 6*4)
inv:set_size("drop", 1)
end,
- on_rightclick = function(pos, _, clicker, _)
+ on_rightclick = function(pos, _, clicker)
local meta = minetest.get_meta(pos)
local player = clicker:get_player_name()
local owner = meta:get_string("owner")
inv:remove_item("drop", stack)
inv:add_item("mailbox", stack)
- for i = 4, 2, -1 do
+ for i = 7, 2, -1 do
meta:set_string("giver"..i, meta:get_string("giver"..(i-1)))
meta:set_string("stack"..i, meta:get_string("stack"..(i-1)))
end
meta:set_string("stack1", stack_name)
end
end,
- allow_metadata_inventory_put = function(pos, listname, _, stack, _)
+ allow_metadata_inventory_put = function(pos, listname, _, stack, player)
+ local player_name = player:get_player_name()
if listname == "drop" then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
- if inv:room_for_item("mailbox", stack) then return -1 end
+ if inv:room_for_item("mailbox", stack) then
+ return -1
+ else
+ minetest.chat_send_player(player_name, "The mailbox is full")
+ end
end
+
return 0
end
})
+local function img_col(stack)
+ if not stack then return "" end
+ if stack.inventory_image ~= "" then
+ return stack.inventory_image:match("([%w_]+)%.png")..".png"
+ else
+ return stack.tiles[1]:match("([%w_]+)%.png")..".png"
+ end
+end
+
function mailbox.formspec(pos, owner, num)
- local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
local spos = pos.x..","..pos.y..","..pos.z
local meta = minetest.get_meta(pos)
- local giver = ""
+ local giver, img = "", ""
if num == 1 then
- for i = 1, 4 do
+ for i = 1, 7 do
if meta:get_string("giver"..i) ~= "" then
- giver = giver.."#FFFF00,"..meta:get_string("giver"..i)..",,\t"..meta:get_string("stack"..i)..","
+ giver = giver.."#FFFF00,"..meta:get_string("giver"..i):sub(1, 12)..
+ ","..i..",#FFFFFF,x "..meta:get_string("stack"..i):match("%s(%d+)")..","
+
+ img = img..i.."="..img_col(minetest.registered_items[
+ meta:get_string("stack"..i):match("([%w_:]+)")])..","
end
end
- return "size[11,9]"..xbg..default.get_hotbar_bg(1.5,5.25)..
- "label[0,0;Mailbox :]label[6,0;Last donators :]box[6,0.72;4.85,3.92;#555555]tablecolumns[color;text]tableoptions[background=#00000000;highlight=#00000000;border=false]table[6,0.77;4.85,4.4;givers;"..giver.."]list[nodemeta:"..spos..";mailbox;0,0.75;6,4;]list[current_player;main;1.5,5.25;8,4;]"
+
+ return [[ size[9.5,9]
+ label[0,0;Mailbox]
+ label[6,0;Last donators]
+ box[6,0.72;3.3,3.5;#555555]
+ listring[current_player;main]
+ list[current_player;main;0.75,5.25;8,4;]
+ tableoptions[background=#00000000;highlight=#00000000;border=false] ]]
+ .."tablecolumns[color;text;image,"..img.."0;color;text]"..
+ "table[6,0.75;3.3,4;givers;"..giver.."]"..
+ "list[nodemeta:"..spos..";mailbox;0,0.75;6,4;]"..
+ "listring[nodemeta:"..spos..";mailbox]"..
+ xbg..default.get_hotbar_bg(0.75,5.25)
else
- return "size[8,5]"..xbg..default.get_hotbar_bg(0,1.25)..
- "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;]"
+ return [[ size[8,5]
+ list[current_player;main;0,1.25;8,4;]
+ tablecolumns[color;text;color;text]
+ tableoptions[background=#00000000;highlight=#00000000;border=false] ]]
+ .."table[0,0;3,1;sendform;#FFFFFF,Send your goods to,,,#FFFF00,"..owner.."]"..
+ "list[nodemeta:"..spos..";drop;3.5,0;1,1;]"..
+ xbg..default.get_hotbar_bg(0,1.25)
end
end