forked from everamzah/backpacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
191 lines (178 loc) · 6.29 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
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
191
local backpacks = {}
backpacks.form = "size[8,7]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[current_name;main;0,0.3;8,2]" ..
"list[current_player;main;0,2.85;8,1]" ..
"list[current_player;main;0,4.08;8,3;8]" ..
"listring[current_name;main]" ..
"listring[current_player;main]"
backpacks.on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Backpack")
meta:set_string("formspec", backpacks.form)
local inv = meta:get_inventory()
inv:set_size("main", 8*2)
end
backpacks.after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
local stuff = minetest.deserialize(itemstack:get_metadata())
if stuff then
meta:from_table(stuff)
end
itemstack:take_item()
end
backpacks.on_dig = function(pos, node, digger)
if minetest.is_protected(pos, digger:get_player_name()) then
return false
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local list = {}
for i, stack in ipairs(inv:get_list("main")) do
if stack:get_name() == "" then
list[i] = ""
else
list[i] = stack:to_string()
end
end
local new_list = {inventory = {main = list},
fields = {infotext = "Backpack", formspec = backpacks.form}}
local new_list_as_string = minetest.serialize(new_list)
local new = ItemStack(node)
new:set_metadata(new_list_as_string)
minetest.remove_node(pos)
local player_inv = digger:get_inventory()
if player_inv:room_for_item("main", new) then
player_inv:add_item("main", new)
else
minetest.add_item(pos, new)
end
end
backpacks.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if not string.match(stack:get_name(), "backpacks:backpack_") then
return stack:get_count()
else
return 0
end
end
-- Wool backpacks
local function register_wool_backpack(colour,colourname)
minetest.register_node("backpacks:backpack_wool_"..colour, {
description = colourname.." Wool Backpack",
tiles = {
"wool_"..colour..".png^backpacks_backpack_topbottom.png", -- Top
"wool_"..colour..".png^backpacks_backpack_topbottom.png", -- Bottom
"wool_"..colour..".png^backpacks_backpack_sides.png", -- Right Side
"wool_"..colour..".png^backpacks_backpack_sides.png", -- Left Side
"wool_"..colour..".png^backpacks_backpack_back.png", -- Back
"wool_"..colour..".png^backpacks_backpack_front.png" -- Front
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
node_box = {
type = "fixed",
fixed = {
{-0.4375, -0.5, -0.375, 0.4375, 0.5, 0.375},
{0.125, -0.375, 0.4375, 0.375, 0.3125, 0.5},
{-0.375, -0.375, 0.4375, -0.125, 0.3125, 0.5},
{0.125, 0.1875, 0.375, 0.375, 0.375, 0.4375},
{-0.375, 0.1875, 0.375, -0.125, 0.375, 0.4375},
{0.125, -0.375, 0.375, 0.375, -0.25, 0.4375},
{-0.375, -0.375, 0.375, -0.125, -0.25, 0.4375},
{-0.3125, -0.375, -0.4375, 0.3125, 0.1875, -0.375},
{-0.25, -0.3125, -0.5, 0.25, 0.125, -0.4375},
}
},
groups = {dig_immediate = 3, oddly_diggable_by_hand = 3, backpack = 1},
stack_max = 1,
on_construct = backpacks.on_construct,
after_place_node = backpacks.after_place_node,
on_dig = backpacks.on_dig,
allow_metadata_inventory_put = backpacks.allow_metadata_inventory_put,
})
minetest.register_craft({
output = "backpacks:backpack_wool_"..colour,
recipe = {
{"wool:"..colour, "wool:"..colour, "wool:"..colour},
{"wool:"..colour, "", "wool:"..colour},
{"wool:"..colour, "wool:"..colour, "wool:"..colour},
}
})
end
minetest.register_craft({
output = "backpacks:backpack_wool_brown",
recipe = {
{"group:wool", "group:wool", "group:wool"},
{"group:wool", "", "group:wool"},
{"group:wool", "group:wool", "group:wool"},
}
})
local wooldyes = {
{code = "white", name = "White"},
{code = "grey", name = "Grey"},
{code = "black", name = "Black"},
{code = "red", name = "Red"},
{code = "yellow", name = "Yellow"},
{code = "green", name = "Green"},
{code = "cyan", name = "Cyan"},
{code = "blue", name = "Blue"},
{code = "magenta", name = "Magenta"},
{code = "orange", name = "Orange"},
{code = "violet", name = "Violet"},
{code = "brown", name = "Brown"},
{code = "pink", name = "Pink"},
{code = "dark_grey", name = "Dark Grey"},
{code = "dark_green", name = "Dark Green"},
}
for _,colourdesc in pairs(wooldyes) do
register_wool_backpack(colourdesc.code,colourdesc.name)
end
minetest.register_alias("backpacks:backpack_wool", "backpacks:backpack_wool_brown")
-- Leather backpack
minetest.register_node("backpacks:backpack_leather", {
description = "Leather Backpack",
tiles = {
"backpacks_leather.png^backpacks_backpack_topbottom.png", -- Top
"backpacks_leather.png^backpacks_backpack_topbottom.png", -- Bottom
"backpacks_leather.png^backpacks_backpack_sides.png", -- Right Side
"backpacks_leather.png^backpacks_backpack_sides.png", -- Left Side
"backpacks_leather.png^backpacks_backpack_back.png", -- Back
"backpacks_leather.png^backpacks_backpack_front.png" -- Front
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
node_box = {
type = "fixed",
fixed = {
{-0.4375, -0.5, -0.375, 0.4375, 0.5, 0.375},
{0.125, -0.375, 0.4375, 0.375, 0.3125, 0.5},
{-0.375, -0.375, 0.4375, -0.125, 0.3125, 0.5},
{0.125, 0.1875, 0.375, 0.375, 0.375, 0.4375},
{-0.375, 0.1875, 0.375, -0.125, 0.375, 0.4375},
{0.125, -0.375, 0.375, 0.375, -0.25, 0.4375},
{-0.375, -0.375, 0.375, -0.125, -0.25, 0.4375},
{-0.3125, -0.375, -0.4375, 0.3125, 0.1875, -0.375},
{-0.25, -0.3125, -0.5, 0.25, 0.125, -0.4375},
}
},
groups = {dig_immediate = 3, oddly_diggable_by_hand = 3, backpack = 1},
stack_max = 1,
on_construct = backpacks.on_construct,
after_place_node = backpacks.after_place_node,
on_dig = backpacks.on_dig,
allow_metadata_inventory_put = backpacks.allow_metadata_inventory_put,
})
if minetest.global_exists("mobs") and ( mobs.redo or mobs.mod == 'redo') then
minetest.register_craft({
output = "backpacks:backpack_leather",
recipe = {
{"mobs:leather", "mobs:leather", "mobs:leather"},
{"mobs:leather", "", "mobs:leather"},
{"mobs:leather", "mobs:leather", "mobs:leather"},
}
})
end