Skip to content

Commit 1bd936a

Browse files
cheapieJeija
authored andcommittedJan 2, 2017
Properly handle rotation of buttons / levers
Buttons and levers can now also be pointed upwards / downwards which will make them connect to corresponding up / down receivers. You will need to use the screwdriver for this. Receivers cannot be rotated using the screwdriver anymore.
1 parent 79edbed commit 1bd936a

File tree

4 files changed

+152
-34
lines changed

4 files changed

+152
-34
lines changed
 

Diff for: ‎mesecons/presets.lua

+10-3
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,19 @@ mesecon.rules.alldirs =
4141

4242
mesecon.rules.buttonlike_get = function(node)
4343
local rules = mesecon.rules.buttonlike
44-
if node.param2 == 2 then
44+
local dir = minetest.facedir_to_dir(node.param2)
45+
if dir.x == 1 then
46+
-- No action needed
47+
elseif dir.z == -1 then
4548
rules=mesecon.rotate_rules_left(rules)
46-
elseif node.param2 == 3 then
49+
elseif dir.x == -1 then
4750
rules=mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules))
48-
elseif node.param2 == 0 then
51+
elseif dir.z == 1 then
4952
rules=mesecon.rotate_rules_right(rules)
53+
elseif dir.y == -1 then
54+
rules=mesecon.rotate_rules_up(rules)
55+
elseif dir.y == 1 then
56+
rules=mesecon.rotate_rules_down(rules)
5057
end
5158
return rules
5259
end

Diff for: ‎mesecons_button/init.lua

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ minetest.register_node("mesecons_button:button_off", {
2626
paramtype2 = "facedir",
2727
legacy_wallmounted = true,
2828
walkable = false,
29+
on_rotate = mesecon.buttonlike_onrotate,
2930
sunlight_propagates = true,
3031
selection_box = {
3132
type = "fixed",
@@ -67,6 +68,7 @@ minetest.register_node("mesecons_button:button_on", {
6768
paramtype2 = "facedir",
6869
legacy_wallmounted = true,
6970
walkable = false,
71+
on_rotate = false,
7072
light_source = default.LIGHT_MAX-7,
7173
sunlight_propagates = true,
7274
selection_box = {

Diff for: ‎mesecons_receiver/init.lua

+138-31
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
1-
rcvboxes = {
1+
local rcvboxes = {
22
{ -3/16, -3/16, -8/16 , 3/16, 3/16 , -13/32 }, -- the smaller bump
33
{ -1/32, -1/32, -3/2 , 1/32, 1/32 , -1/2 }, -- the wire through the block
44
{ -2/32, -1/2 , -.5 , 2/32, 0 , -.5002+3/32 }, -- the vertical wire bit
55
{ -2/32, -1/2 , -7/16+0.002 , 2/32, -14/32, 16/32+0.001 } -- the horizontal wire
66
}
77

8+
local down_rcvboxes = {
9+
{-6/16, -8/16, -6/16, 6/16, -7/16, 6/16}, -- Top plate
10+
{-2/16, -6/16, -2/16, 2/16, -7/16, 2/16}, -- Bump
11+
{-1/16, -8/16, -1/16, 1/16, -24/16, 1/16}, -- Wire through the block
12+
{-1/16, -8/16, 6/16, 1/16, -7/16, 8/16}, -- Plate extension (North)
13+
{-1/16, -8/16, -6/16, 1/16, -7/16, -8/16}, -- Plate extension (South)
14+
{-8/16, -8/16, 1/16, -6/16, -7/16, -1/16}, -- Plate extension (West)
15+
{6/16, -8/16, 1/16, 8/16, -7/16, -1/16}, -- Plate extension (East)
16+
}
17+
18+
local up_rcvboxes = {
19+
{-6/16, -8/16, -6/16, 6/16, -7/16, 6/16}, -- Top plate
20+
{-2/16, -6/16, -2/16, 2/16, -7/16, 2/16}, -- Bump
21+
{-1/16, -6/16, -1/16, 1/16, 24/16, 1/16}, -- Wire through the block
22+
{-1/16, -8/16, 6/16, 1/16, -7/16, 8/16}, -- Plate extension (North)
23+
{-1/16, -8/16, -6/16, 1/16, -7/16, -8/16}, -- Plate extension (South)
24+
{-8/16, -8/16, 1/16, -6/16, -7/16, -1/16}, -- Plate extension (West)
25+
{6/16, -8/16, 1/16, 8/16, -7/16, -1/16}, -- Plate extension (East)
26+
}
27+
828
local receiver_get_rules = function (node)
929
local rules = { {x = 1, y = 0, z = 0},
1030
{x = -2, y = 0, z = 0}}
@@ -18,8 +38,38 @@ local receiver_get_rules = function (node)
1838
return rules
1939
end
2040

21-
minetest.register_node("mesecons_receiver:receiver_on", {
41+
mesecon.register_node("mesecons_receiver:receiver", {
2242
drawtype = "nodebox",
43+
paramtype = "light",
44+
paramtype2 = "facedir",
45+
sunlight_propagates = true,
46+
walkable = false,
47+
on_rotate = false,
48+
selection_box = {
49+
type = "fixed",
50+
fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 }
51+
},
52+
node_box = {
53+
type = "fixed",
54+
fixed = rcvboxes
55+
},
56+
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
57+
drop = "mesecons:wire_00000000_off",
58+
}, {
59+
tiles = {
60+
"receiver_top_off.png",
61+
"receiver_bottom_off.png",
62+
"receiver_lr_off.png",
63+
"receiver_lr_off.png",
64+
"receiver_fb_off.png",
65+
"receiver_fb_off.png",
66+
},
67+
mesecons = {conductor = {
68+
state = mesecon.state.off,
69+
rules = receiver_get_rules,
70+
onstate = "mesecons_receiver:receiver_on"
71+
}}
72+
}, {
2373
tiles = {
2474
"receiver_top_on.png",
2575
"receiver_bottom_on.png",
@@ -28,83 +78,133 @@ minetest.register_node("mesecons_receiver:receiver_on", {
2878
"receiver_fb_on.png",
2979
"receiver_fb_on.png",
3080
},
81+
mesecons = {conductor = {
82+
state = mesecon.state.on,
83+
rules = receiver_get_rules,
84+
offstate = "mesecons_receiver:receiver_off"
85+
}}
86+
})
87+
88+
mesecon.register_node("mesecons_receiver:receiver_up", {
89+
drawtype = "nodebox",
3190
paramtype = "light",
3291
paramtype2 = "facedir",
3392
sunlight_propagates = true,
3493
walkable = false,
94+
on_rotate = false,
3595
selection_box = {
3696
type = "fixed",
37-
fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 }
97+
fixed = up_rcvboxes
3898
},
3999
node_box = {
40100
type = "fixed",
41-
fixed = rcvboxes
101+
fixed = up_rcvboxes
42102
},
43103
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
44104
drop = "mesecons:wire_00000000_off",
105+
}, {
106+
tiles = {"mesecons_wire_off.png"},
107+
mesecons = {conductor = {
108+
state = mesecon.state.off,
109+
rules = {{x=1, y=0, z=0},
110+
{x=-1, y=0, z=0},
111+
{x=0, y=0, z=1},
112+
{x=0, y=0, z=-1},
113+
{x=0, y=1, z=0},
114+
{x=0, y=2, z=0}},
115+
onstate = "mesecons_receiver:receiver_up_on"
116+
}}
117+
}, {
118+
tiles = {"mesecons_wire_on.png"},
45119
mesecons = {conductor = {
46120
state = mesecon.state.on,
47-
rules = receiver_get_rules,
48-
offstate = "mesecons_receiver:receiver_off"
121+
rules = {{x=1, y=0, z=0},
122+
{x=-1, y=0, z=0},
123+
{x=0, y=0, z=1},
124+
{x=0, y=0, z=-1},
125+
{x=0, y=1, z=0},
126+
{x=0, y=2, z=0}},
127+
offstate = "mesecons_receiver:receiver_up_off"
49128
}}
50129
})
51130

52-
minetest.register_node("mesecons_receiver:receiver_off", {
131+
mesecon.register_node("mesecons_receiver:receiver_down", {
53132
drawtype = "nodebox",
54-
description = "You hacker you",
55-
tiles = {
56-
"receiver_top_off.png",
57-
"receiver_bottom_off.png",
58-
"receiver_lr_off.png",
59-
"receiver_lr_off.png",
60-
"receiver_fb_off.png",
61-
"receiver_fb_off.png",
62-
},
63133
paramtype = "light",
64134
paramtype2 = "facedir",
65135
sunlight_propagates = true,
66136
walkable = false,
137+
on_rotate = false,
67138
selection_box = {
68139
type = "fixed",
69-
fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 }
140+
fixed = down_rcvboxes
70141
},
71142
node_box = {
72143
type = "fixed",
73-
fixed = rcvboxes
144+
fixed = down_rcvboxes
74145
},
75146
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
76147
drop = "mesecons:wire_00000000_off",
148+
}, {
149+
tiles = {"mesecons_wire_off.png"},
77150
mesecons = {conductor = {
78151
state = mesecon.state.off,
79-
rules = receiver_get_rules,
80-
onstate = "mesecons_receiver:receiver_on"
152+
rules = {{x=1,y=0, z=0},
153+
{x=-1,y=0, z=0},
154+
{x=0, y=0, z=1},
155+
{x=0, y=0, z=-1},
156+
{x=0, y=-2,z=0}},
157+
onstate = "mesecons_receiver:receiver_down_on"
158+
}}
159+
}, {
160+
tiles = {"mesecons_wire_on.png"},
161+
mesecons = {conductor = {
162+
state = mesecon.state.on,
163+
rules = {{x=1,y=0, z=0},
164+
{x=-1,y=0, z=0},
165+
{x=0, y=0, z=1},
166+
{x=0, y=0, z=-1},
167+
{x=0, y=-2,z=0}},
168+
offstate = "mesecons_receiver:receiver_down_off"
81169
}}
82170
})
83171

84172
function mesecon.receiver_get_pos_from_rcpt(pos, param2)
85173
local rules = {{x = 2, y = 0, z = 0}}
86174
if param2 == nil then param2 = minetest.get_node(pos).param2 end
87-
if param2 == 2 then
175+
local rcvtype = "mesecons_receiver:receiver_off"
176+
local dir = minetest.facedir_to_dir(param2)
177+
178+
if dir.x == 1 then
179+
-- No action needed
180+
elseif dir.z == -1 then
88181
rules = mesecon.rotate_rules_left(rules)
89-
elseif param2 == 3 then
182+
elseif dir.x == -1 then
90183
rules = mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules))
91-
elseif param2 == 0 then
184+
elseif dir.z == 1 then
92185
rules = mesecon.rotate_rules_right(rules)
186+
elseif dir.y == -1 then
187+
rules = mesecon.rotate_rules_up(rules)
188+
rcvtype = "mesecons_receiver:receiver_up_off"
189+
elseif dir.y == 1 then
190+
rules = mesecon.rotate_rules_down(rules)
191+
rcvtype = "mesecons_receiver:receiver_down_off"
93192
end
94193
local np = { x = pos.x + rules[1].x,
95194
y = pos.y + rules[1].y,
96195
z = pos.z + rules[1].z}
97-
return np
196+
return np, rcvtype
98197
end
99198

100199
function mesecon.receiver_place(rcpt_pos)
101200
local node = minetest.get_node(rcpt_pos)
102-
local pos = mesecon.receiver_get_pos_from_rcpt(rcpt_pos, node.param2)
201+
local pos, rcvtype = mesecon.receiver_get_pos_from_rcpt(rcpt_pos, node.param2)
103202
local nn = minetest.get_node(pos)
203+
local param2 = minetest.dir_to_facedir(minetest.facedir_to_dir(node.param2))
104204

105205
if string.find(nn.name, "mesecons:wire_") ~= nil then
106206
minetest.dig_node(pos)
107-
minetest.set_node(pos, {name = "mesecons_receiver:receiver_off", param2 = node.param2})
207+
minetest.set_node(pos, {name = rcvtype, param2 = param2})
108208
mesecon.on_placenode(pos, nn)
109209
end
110210
end
@@ -133,11 +233,13 @@ minetest.register_on_dignode(function(pos, node)
133233
end)
134234

135235
minetest.register_on_placenode(function (pos, node)
136-
if string.find(node.name, "mesecons:wire_") ~=nil then
137-
local rules = { {x = 2, y = 0, z = 0},
138-
{x =-2, y = 0, z = 0},
139-
{x = 0, y = 0, z = 2},
140-
{x = 0, y = 0, z =-2}}
236+
if string.find(node.name, "mesecons:wire_") ~= nil then
237+
local rules = { {x = 2, y = 0, z = 0},
238+
{x =-2, y = 0, z = 0},
239+
{x = 0, y = 0, z = 2},
240+
{x = 0, y = 0, z =-2},
241+
{x = 0, y = 2, z = 0},
242+
{x = 0, y = -2, z = 0}}
141243
local i = 1
142244
while rules[i] ~= nil do
143245
local np = { x = pos.x + rules[i].x,
@@ -150,3 +252,8 @@ minetest.register_on_placenode(function (pos, node)
150252
end
151253
end
152254
end)
255+
256+
function mesecon.buttonlike_onrotate(pos, node)
257+
minetest.after(0, mesecon.receiver_remove, pos, node)
258+
minetest.after(0, mesecon.receiver_place, pos)
259+
end

Diff for: ‎mesecons_walllever/init.lua

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mesecon.register_node("mesecons_walllever:wall_lever", {
3131
"jeija_wall_lever_back_edges.png"
3232
},
3333
mesh="jeija_wall_lever_off.obj",
34+
on_rotate = mesecon.buttonlike_onrotate,
3435
mesecons = {receptor = {
3536
rules = mesecon.rules.buttonlike_get,
3637
state = mesecon.state.off
@@ -44,6 +45,7 @@ mesecon.register_node("mesecons_walllever:wall_lever", {
4445
"jeija_wall_lever_back_edges.png"
4546
},
4647
mesh="jeija_wall_lever_on.obj",
48+
on_rotate = false,
4749
mesecons = {receptor = {
4850
rules = mesecon.rules.buttonlike_get,
4951
state = mesecon.state.on

0 commit comments

Comments
 (0)
Please sign in to comment.