-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
139 lines (130 loc) · 4.34 KB
/
init.lua
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
local bookshelf_formspec =
"size[8,8]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[current_name;books;0,0.3;8,2]" ..
"list[current_name;protection;3.5,2.5;1,1]" ..
"list[current_player;main;0,3.85;8,1]" ..
"list[current_player;main;0,5.08;8,3;8]" ..
"listring[current_name;books]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0, 3.85)
minetest.override_item("default:bookshelf", {
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", bookshelf_formspec)
local inv = meta:get_inventory()
inv:set_size("books", 8*2)
inv:set_size("protection", 1)
end,
can_dig = function(pos, player)
local inv = minetest.get_meta(pos):get_inventory()
return (inv:is_empty("books") and inv:is_empty("protection"))
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local inv = minetest.get_meta(pos):get_inventory()
if inv:get_stack("protection", 1):get_name() == "protector:protect2" and
minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if from_list == "books" and to_list == "books" then
return count
else
return 0
end
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local inv = minetest.get_meta(pos):get_inventory()
if listname == "protection" and
stack:get_name() == "protector:protect2" and
inv:get_stack("protection", 1):is_empty() and
not minetest.is_protected(pos, player:get_player_name()) then
return 1
end
if inv:get_stack("protection", 1):get_name() == "protector:protect2" and
minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "books" and
minetest.get_item_group(stack:get_name(), "book") ~= 0 then
return stack:get_count()
else
return 0
end
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local inv = minetest.get_meta(pos):get_inventory()
if inv:get_stack("protection", 1):get_name() == "protector:protect2" and
minetest.is_protected(pos, player:get_player_name()) then
return 0
else
return stack:get_count()
end
end,
})
local vessels_shelf_formspec =
"size[8,8]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[current_name;vessels;0,0.3;8,2]" ..
"list[current_name;protection;3.5,2.5;1,1]" ..
"list[current_player;main;0,3.85;8,1]" ..
"list[current_player;main;0,5.08;8,3;8]" ..
"listring[current_name;vessels]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0, 3.85)
minetest.override_item("vessels:shelf", {
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", vessels_shelf_formspec)
local inv = meta:get_inventory()
inv:set_size("vessels", 8*2)
inv:set_size("protection", 1)
end,
can_dig = function(pos,player)
local inv = minetest.get_meta(pos):get_inventory()
return (inv:is_empty("vessels") and inv:is_empty("protection"))
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local inv = minetest.get_meta(pos):get_inventory()
if inv:get_stack("protection", 1):get_name() == "protector:protect2" and
minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if from_list == "vessels" and to_list == "vessels" then
return count
else
return 0
end
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local inv = minetest.get_meta(pos):get_inventory()
if listname == "protection" and
stack:get_name() == "protector:protect2" and
inv:get_stack("protection", 1):is_empty() and
not minetest.is_protected(pos, player:get_player_name()) then
return 1
end
if inv:get_stack("protection", 1):get_name() == "protector:protect2" and
minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "vessels" and
minetest.get_item_group(stack:get_name(), "vessel") ~= 0 then
return stack:get_count()
else
return 0
end
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local inv = minetest.get_meta(pos):get_inventory()
if inv:get_stack("protection", 1):get_name() == "protector:protect2" and
minetest.is_protected(pos, player:get_player_name()) then
return 0
else
return stack:get_count()
end
end,
})