Repository navigation
Expand file tree
/
Copy pathcontainer.lua
More file actions
190 lines (170 loc) · 6.78 KB
/
Copy pathcontainer.lua
File metadata and controls
190 lines (170 loc) · 6.78 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
function ct.make_open_formspec(reinf, group, name, pos)
local F = minetest.formspec_escape
local chest_title = name or "Chest"
if reinf then
local resource_limit = ct.reinforcement_types[reinf.material].value
chest_title = "Locked " .. chest_title .. " (group: '" .. F(group.name) .. "', "
.. tostring(reinf.material) .. ", " .. tostring(reinf.value) .. "/"
.. tostring(resource_limit) .. ")"
end
local spos = pos.x .. "," .. pos.y .. "," .. pos.z
local open = {
"size[8,9.5]",
"label[0,0;", chest_title, "]",
-- default.gui_bg ,
-- default.gui_bg_img ,
-- default.gui_slots ,
"list[nodemeta:"..spos..";main;0,0.7;8,4;]",
-- invisible tmp invlist to facilitate shift-clicking to player inv
-- "list[nodemeta:"..spos..";tmp;0,0;0,0;]",
-- "listring[]",
sfinv.get_inventory_area_formspec(5.2),
"listring[nodemeta:"..spos..";main]",
"listring[current_player;router]",
"listring[current_player;main2]",
"listring[nodemeta:"..spos..";main]",
"listring[current_player;main]",
-- default.get_hotbar_bg(0,4.85)
}
return table.concat(open, "")
end
function ct.override_on_construct(def)
def.on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("owner", "")
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
inv:set_size("tmp", 1)
end
return def
end
function ct.wrap_allow_metadata_inventory_move(def)
local old_allow_metadata_inventory_move = def.allow_metadata_inventory_move
or function(pos, from_list, from_index, to_list, to_index, count, player)
return count
end
def.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if from_list == "main" and to_list == "tmp" then
local inv = minetest.get_meta(pos):get_inventory()
local stack = inv:get_stack("main", from_index)
local stack_count = stack:take_item(count)
local pinv = player:get_inventory()
if not pinv:room_for_item("main", stack_count)
and not pinv:room_for_item("main2", stack_count)
then
return 0
end
end
if not ct.has_locked_chest_privilege(pos, player) then
minetest.log("action", player:get_player_name()..
" tried to move in a locked chest at "..
minetest.pos_to_string(pos))
return 0
end
return old_allow_metadata_inventory_move(
pos, from_list, from_index, to_list, to_index, count, player
)
end
return def
end
function ct.wrap_allow_metadata_inventory_put(def)
local old_allow_metadata_inventory_put = def.allow_metadata_inventory_put
or function(pos, listname, index, stack, player)
return stack:get_count()
end
def.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if not ct.has_locked_chest_privilege(pos, player) then
minetest.log("action", player:get_player_name()..
" tried to put into a locked chest at "..
minetest.pos_to_string(pos))
return 0
end
return old_allow_metadata_inventory_put(pos, listname, index, stack, player)
end
return def
end
function ct.wrap_allow_metadata_inventory_take(def)
local old_allow_metadata_inventory_take = def.allow_metadata_inventory_take
or function(pos, listname, index, stack, player)
return stack:get_count()
end
def.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if not ct.has_locked_chest_privilege(pos, player) then
minetest.log("action", player:get_player_name()..
" tried to take from a locked chest at "..
minetest.pos_to_string(pos))
return 0
end
return old_allow_metadata_inventory_take(pos, listname, index, stack, player)
end
return def
end
function ct.override_on_metadata_inventory_move(def)
local old_on_metadata_inventory_move = def.on_metadata_inventory_move
def.on_metadata_inventory_move =
function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("verbose",
player:get_player_name() .. " moves stuff in locked chest at "
.. minetest.pos_to_string(pos)
)
if old_on_metadata_inventory_move then
return old_on_metadata_inventory_move(
pos, from_list, from_index, to_list, to_index, count, player
)
end
end
end
function ct.override_on_metadata_inventory_take_put(def)
local old_on_metadata_inventory_put = def.on_metadata_inventory_put
def.on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("verbose",
player:get_player_name() .. " puts stuff in locked chest at "
.. minetest.pos_to_string(pos)
)
if old_on_metadata_inventory_put then
old_on_metadata_inventory_put(pos, listname, index, stack, player)
end
end
local old_on_metadata_inventory_take = def.on_metadata_inventory_take
def.on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("verbose",
player:get_player_name() .. " takes stuff from locked chest at "
.. minetest.pos_to_string(pos)
)
if old_on_metadata_inventory_take then
old_on_metadata_inventory_take(pos, listname, index, stack, player)
end
end
end
function ct.override_on_rightclick(def)
local old_on_rightclick = def.on_rightclick
def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local node_description = core.registered_nodes[node.name].description
local has_privilege, reinf, group
= ct.has_locked_chest_privilege(pos, clicker, node_description)
if not has_privilege then
return
end
local pname = clicker:get_player_name()
local formspec = ct.make_open_formspec(reinf, group, node_description, pos)
minetest.show_formspec(pname, "citadella:chest", formspec)
if old_on_rightclick then
old_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
end
end
return def
end
function ct.override_definition(olddef)
local def = table.copy(olddef)
ct.override_on_construct(def)
ct.wrap_allow_metadata_inventory_move(def)
ct.wrap_allow_metadata_inventory_put(def)
ct.wrap_allow_metadata_inventory_take(def)
ct.override_on_metadata_inventory_move(def)
ct.override_on_metadata_inventory_take_put(def)
ct.override_on_rightclick(def)
return def
end