forked from Bremaweb/landrush
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshared_inbox.lua
More file actions
131 lines (122 loc) · 3.97 KB
/
shared_inbox.lua
File metadata and controls
131 lines (122 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
-- Adapted from homedcor modpack inbox licensed under gpl version 3 by VanessaE.
-- Modified by mootpoint and Foz license gpl version 3
-- textures: CC-by-SA 3.0 or higher
if minetest.get_modpath('inbox') then
screwdriver = screwdriver or {}
local function take_fs(pos)
local spos = pos.x .. ',' .. pos.y .. ',' ..pos.z
local formspec =
'size[8,9]'..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
'list[nodemeta:' .. spos .. ';main;0,0.3;8,4;]' ..
'list[current_player;main;0,4.85;8,1;]' ..
'list[current_player;main;0,6.08;8,3;8]' ..
'listring[nodemeta:' .. spos .. ';main]' ..
'listring[current_player;main]' ..
default.get_hotbar_bg(0,4.85)
return formspec
end
local function give_fs(pos)
local spos = pos.x .. ',' .. pos.y .. ',' ..pos.z
local formspec =
'size[8,9]'..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
'list[nodemeta:'.. spos .. ';drop;3.5,2;1,1;]'..
'list[current_player;main;0,4.85;8,1;]' ..
'list[current_player;main;0,6.08;8,3;8]' ..
'listring[nodemeta:' .. spos .. ';drop]' ..
'listring[current_player;main]' ..
default.get_hotbar_bg(0,4.85)
return formspec
end
local mb_cbox = {
type = 'fixed',
fixed = { -5/16, -8/16, -8/16, 5/16, 2/16, 8/16 }
}
minetest.register_node(':landrush:shared_mailbox', {
paramtype = 'light',
drawtype = 'mesh',
mesh = 'inbox_mailbox.obj',
description = 'Shared Mailbox',
tiles = {
'landrush_shared_inbox_flag.png',
'landrush_shared_inbox_box.png',
'inbox_grey_metal.png',
},
inventory_image = 'landrush_shared_mailbox_inv.png',
selection_box = mb_cbox,
collision_box = mb_cbox,
paramtype2 = 'facedir',
groups = {choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
on_rotate = screwdriver.rotate_simple,
after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos)
meta:set_string('infotext', 'Shared Mailbox')
local inv = meta:get_inventory()
inv:set_size('main', 8*4)
inv:set_size('drop', 1)
end,
on_rightclick = function(pos, node, clicker, itemstack)
local name = clicker:get_player_name()
if clicker:get_player_control().aux1 or
minetest.is_protected(pos, name) then
minetest.show_formspec(name, 'landrush:shared_inbox', give_fs(pos))
else
minetest.show_formspec(name, 'landrush:shared_inbox', take_fs(pos))
end
return itemstack
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty('main')
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if listname == 'drop' then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:room_for_item('main', stack) then
return -1
end
end
return 0
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:remove_item('drop', stack)
inv:add_item('main', stack)
local name = player:get_player_name()
local stuff = stack:get_count()..' '..stack:get_name()
local action = ' puts '..stuff..' in shared inbox at '
local location = minetest.pos_to_string(pos)
minetest.log('action',name..action..location)
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
local name = player:get_player_name()
local stuff = stack:get_count()..' '..stack:get_name()
local action = ' takes '..stuff..' from shared inbox at '
local location = minetest.pos_to_string(pos)
minetest.log('action',name..action..location)
end,
})
minetest.register_craft({
output ='landrush:shared_mailbox',
recipe = {
{'', 'inbox:empty', ''},
{'', 'inbox:empty', ''},
{'', '', ''}
}
})
end