-
Notifications
You must be signed in to change notification settings - Fork 13
/
tools.lua
139 lines (128 loc) · 3.93 KB
/
tools.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 USES = 200 --how many times you can use the tool before it breaks.
local function in_creative(user)
local creative =
minetest.settings:get_bool("creative_mode") -- Global setting
if minetest.is_player(user) then -- Check user setting, too
creative = creative
or minetest.is_creative_enabled(user:get_player_name())
end
return creative
end
minetest.register_tool('ma_pops_furniture:hammer', {
description = 'Hammer',
inventory_image = 'mp_hammer.png',
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= 'node' then
return
end
local pos = pointed_thing.under
local node = minetest.get_node(pos)
local sofa_table = {
{'black'},
{'blue'},
{'brown'},
{'cyan'},
{'dark_green'},
{'dark_grey'},
{'green'},
{'grey'},
{'magenta'},
{'orange'},
{'pink'},
{'red'},
{'violet'},
{'white'},
{'yellow'},
}
for i in ipairs (sofa_table) do
local color = sofa_table[i][1]
if node.name == 'ma_pops_furniture:sofa_'..color then
minetest.set_node(pos,{name = 'ma_pops_furniture:sofa_r_'..color, param2=node.param2})
end
if node.name == 'ma_pops_furniture:sofa_r_'..color then
minetest.set_node(pos,{name = 'ma_pops_furniture:sofa_m_'..color, param2=node.param2})
end
if node.name == 'ma_pops_furniture:sofa_m_'..color then
minetest.set_node(pos,{name = 'ma_pops_furniture:sofa_l_'..color, param2=node.param2})
end
if node.name == 'ma_pops_furniture:sofa_l_'..color then
minetest.set_node(pos,{name = 'ma_pops_furniture:sofa_c_'..color, param2=node.param2})
end
if node.name == 'ma_pops_furniture:sofa_c_'..color then
minetest.set_node(pos,{name = 'ma_pops_furniture:sofa_'..color, param2=node.param2})
end
end
if not in_creative(user) then
itemstack:add_wear(65535 / (USES - 1))
end
return itemstack
end,
on_place = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= 'node' then
return
end
local pos = pointed_thing.under
local node = minetest.get_node(pos).name
local para = minetest.get_node(pos).param2
local newpara = para + 1
if newpara > 3 then
newpara = 0
end
minetest.set_node(pos,{name = ""..node, param2 = newpara})
if not in_creative(user) then
itemstack:add_wear(65535 / (USES - 1))
end
return itemstack
end,
})
minetest.register_tool('ma_pops_furniture:shears', {
description = 'Shears',
inventory_image = 'mp_shears.png',
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= 'node' then
return
end
local pos = pointed_thing.under
local node = minetest.get_node(pos)
local hedge_table = { --material
{'leaves'},
{'pine_needles'},
{'jungleleaves'},
{'aspen_leaves'},
{'acacia_leaves'}
}
for i in ipairs (hedge_table) do
local mat = hedge_table[i][1]
if node.name == 'ma_pops_furniture:hedge_'..mat then
minetest.set_node(pos,{name = 'ma_pops_furniture:hedge_t_'..mat, param2=node.param2})
end
if node.name == 'ma_pops_furniture:hedge_t_'..mat then
minetest.set_node(pos,{name = 'ma_pops_furniture:hedge_c_'..mat, param2=node.param2})
end
if node.name == 'ma_pops_furniture:hedge_c_'..mat then
minetest.set_node(pos,{name = 'ma_pops_furniture:hedge_'..mat, param2=node.param2})
end
end
if not in_creative(user) then
itemstack:add_wear(65535 / (USES - 1))
end
return itemstack
end,
on_place = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= 'node' then
return
end
local pos = pointed_thing.under
local node = minetest.get_node(pos).name
local para = minetest.get_node(pos).param2
local newpara = para + 1
if newpara > 3 then
newpara = 0
end
minetest.set_node(pos,{name = ""..node, param2 = newpara})
if not in_creative(user) then
itemstack:add_wear(65535 / (USES - 1))
end
return itemstack
end,
})