1 xdecor.register("mailbox", {
2 description = "Mailbox",
4 "xdecor_mailbox_top.png", "xdecor_mailbox_bottom.png",
5 "xdecor_mailbox_side.png", "xdecor_mailbox_side.png",
6 "xdecor_mailbox.png", "xdecor_mailbox.png",
9 after_place_node = function(pos, placer, itemstack)
10 local meta = minetest.get_meta(pos)
11 local owner = placer:get_player_name()
13 meta:set_string("owner", owner)
14 meta:set_string("infotext", owner.."'s Mailbox")
16 local inv = meta:get_inventory()
17 inv:set_size("main", 8*4)
18 inv:set_size("drop", 1)
20 on_rightclick = function(pos, node, clicker, itemstack)
21 local meta = minetest.get_meta(pos)
22 local player = clicker:get_player_name()
23 local owner = meta:get_string("owner")
25 if owner == player then
26 minetest.show_formspec(player, "default:chest_locked",
27 xdecor.get_mailbox_formspec(pos))
28 else minetest.show_formspec(player, "default:chest_locked",
29 xdecor.get_mailbox_insert_formspec(pos))
32 can_dig = function(pos, player)
33 local meta = minetest.get_meta(pos)
34 local owner = meta:get_string("owner")
35 local inv = meta:get_inventory()
37 return player:get_player_name() == owner and inv:is_empty("main")
39 on_metadata_inventory_put = function(pos, listname, index, stack, player)
40 local meta = minetest.get_meta(pos)
41 local inv = meta:get_inventory()
43 if listname == "drop" and inv:room_for_item("main", stack) then
44 inv:remove_item("drop", stack)
45 inv:add_item("main", stack)
48 allow_metadata_inventory_put = function(pos, listname, index, stack, player)
49 if listname == "main" then return 0 end
50 if listname == "drop" then
51 local meta = minetest.get_meta(pos)
52 local inv = meta:get_inventory()
54 if inv:room_for_item("main", stack) then return -1
60 function xdecor.get_mailbox_formspec(pos)
61 local spos = pos.x..","..pos.y..","..pos.z
63 "size[8,9]"..xdecor.fancy_gui..
64 "label[0,0;You received...]"..
65 "list[nodemeta:"..spos..";main;0,0.75;8,4;]"..
66 "list[current_player;main;0,5.25;8,4;]"
70 function xdecor.get_mailbox_insert_formspec(pos)
71 local spos = pos.x..","..pos.y..","..pos.z
73 "size[8,5]"..xdecor.fancy_gui..
74 "label[0,0;Send your goods...]"..
75 "list[nodemeta:"..spos..";drop;3.5,0;1,1;]"..
76 "list[current_player;main;0,1.25;8,4;]"