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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
local vbox = {
type = "fixed",
fixed = {-1/16, -.5, -1/16, 1/16, .5, 1/16}
}
local tbox = {
type = "fixed",
fixed = {{-.5, -.5, -.5, .5, -.5 + 1/16, .5}}
}
local bbox = {
type = "fixed",
fixed = {{ -.5, -.5 , -.5, .5, -.5+1/16, .5},
{-1/16, -.5+1/16, -1/16, 1/16, .5 , 1/16}}
}
local vrules =
{{x = 0, y = 1, z = 0},
{x = 0, y =-1, z = 0}}
local trules =
{{x = 1, y = 0, z = 0},
{x =-1, y = 0, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z =-1},
{x = 0, y =-1, z = 0}}
local brules =
{{x = 1, y = 0, z = 0},
{x =-1, y = 0, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z =-1},
{x = 0, y = 1, z = 0}}
local vertical_updatepos = function (pos)
local node = minetest.env:get_node(pos)
if minetest.registered_nodes[node.name].is_vertical_conductor then
local node_above = minetest.env:get_node(mesecon:addPosRule(pos, vrules[1]))
local node_below = minetest.env:get_node(mesecon:addPosRule(pos, vrules[2]))
local namestate = minetest.registered_nodes[node.name].vertical_conductor_state
-- above and below: vertical mesecon
if minetest.registered_nodes[node_above.name].is_vertical_conductor
and minetest.registered_nodes[node_below.name].is_vertical_conductor then
minetest.env:add_node (pos,
{name = "mesecons_extrawires:vertical_"..namestate})
-- above only: bottom
elseif minetest.registered_nodes[node_above.name].is_vertical_conductor
and not minetest.registered_nodes[node_below.name].is_vertical_conductor then
minetest.env:add_node (pos,
{name = "mesecons_extrawires:vertical_bottom_"..namestate})
-- below only: top
elseif not minetest.registered_nodes[node_above.name].is_vertical_conductor
and minetest.registered_nodes[node_below.name].is_vertical_conductor then
minetest.env:add_node (pos,
{name = "mesecons_extrawires:vertical_top_"..namestate})
else -- no vertical wire above, no vertical wire below: use default wire
minetest.env:add_node (pos,
{name = "mesecons_extrawires:vertical_"..namestate})
end
end
end
local vertical_update = function (pos, node)
vertical_updatepos(pos) -- this one
vertical_updatepos(mesecon:addPosRule(pos, vrules[1])) -- above
vertical_updatepos(mesecon:addPosRule(pos, vrules[2])) -- below
end
-- Vertical wire
minetest.register_node("mesecons_extrawires:vertical_on", {
description = "Vertical mesecon",
drawtype = "nodebox",
tiles = {"wires_vertical_on.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = vbox,
node_box = vbox,
is_vertical_conductor = true,
vertical_conductor_state = "on",
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_off",
rules = vrules
}},
drop = {"mesecons_extrawires:vertical_off"},
after_place_node = vertical_update,
after_dig_node = vertical_update
})
minetest.register_node("mesecons_extrawires:vertical_off", {
description = "Vertical mesecon",
drawtype = "nodebox",
tiles = {"wires_vertical_off.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
groups = {dig_immediate = 3},
selection_box = vbox,
node_box = vbox,
is_vertical_conductor = true,
vertical_conductor_state = "off",
mesecons = {conductor = {
state = mesecon.state.off,
onstate = "mesecons_extrawires:vertical_on",
rules = vrules
}},
after_place_node = vertical_update,
after_dig_node = vertical_update
})
-- Vertical wire top
minetest.register_node("mesecons_extrawires:vertical_top_on", {
description = "Vertical mesecon",
drawtype = "nodebox",
tiles = {"wires_full_on.png","wires_full_on.png","wires_vertical_on.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = tbox,
node_box = tbox,
is_vertical_conductor = true,
vertical_conductor_state = "on",
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_top_off",
rules = trules
}},
drop = {"mesecons_extrawires:vertical_off"},
after_place_node = vertical_update,
after_dig_node = vertical_update
})
minetest.register_node("mesecons_extrawires:vertical_top_off", {
description = "Vertical mesecon",
drawtype = "nodebox",
tiles = {"wires_full_off.png","wires_full_off.png","wires_vertical_off.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = tbox,
node_box = tbox,
is_vertical_conductor = true,
vertical_conductor_state = "off",
mesecons = {conductor = {
state = mesecon.state.off,
onstate = "mesecons_extrawires:vertical_top_on",
rules = trules
}},
drop = {"mesecons_extrawires:vertical_off"},
after_place_node = vertical_update,
after_dig_node = vertical_update
})
-- Vertical wire bottom
minetest.register_node("mesecons_extrawires:vertical_bottom_on", {
description = "Vertical mesecon",
drawtype = "nodebox",
tiles = {"wires_full_on.png","wires_full_on.png","wires_vertical_on.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
vertical_conductor_state = "on",
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = bbox,
node_box = bbox,
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_bottom_off",
rules = brules
}},
drop = {"mesecons_extrawires:vertical_off"},
after_place_node = vertical_update,
after_dig_node = vertical_update
})
minetest.register_node("mesecons_extrawires:vertical_bottom_off", {
description = "Vertical mesecon",
drawtype = "nodebox",
tiles = {"wires_full_off.png","wires_full_off.png","wires_vertical_off.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = bbox,
node_box = bbox,
is_vertical_conductor = true,
vertical_conductor_state = "off",
mesecons = {conductor = {
state = mesecon.state.off,
onstate = "mesecons_extrawires:vertical_bottom_on",
rules = brules
}},
drop = {"mesecons_extrawires:vertical_off"},
after_place_node = vertical_update,
after_dig_node = vertical_update
})
minetest.register_craft({
output = "mesecons_extrawires:vertical_off 3",
recipe = {
{"mesecons:wire_00000000_off"},
{"mesecons:wire_00000000_off"},
{"mesecons:wire_00000000_off"}
}
})
minetest.register_craft({
output = "mesecons:wire_00000000_off",
recipe = {{"mesecons_extrawires:vertical_off"}}
})
|