Skip to content

Commit 75cfac3

Browse files
committed
add signs_lib placement rules
only works on signs_lib commit dcdee222 or later.
1 parent d5fe933 commit 75cfac3

7 files changed

+266
-5
lines changed

depends.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ screwdriver
44
mesecons?
55
mesecons_mvps?
66
digilines?
7+
signs_lib?

devices.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,9 @@ minetest.register_node(nodename_sp_empty, {
706706
end,
707707
selection_box = sp_cbox,
708708
collision_box = sp_cbox,
709-
on_rotate = pipeworks.fix_after_rotation
709+
on_rotate = pipeworks.fix_after_rotation,
710+
check_for_pole = pipeworks.check_for_vert_pipe,
711+
check_for_horiz_pole = pipeworks.check_for_horiz_pipe
710712
})
711713

712714
local nodename_sp_loaded = "pipeworks:straight_pipe_loaded"
@@ -727,7 +729,9 @@ minetest.register_node(nodename_sp_loaded, {
727729
selection_box = sp_cbox,
728730
collision_box = sp_cbox,
729731
drop = "pipeworks:straight_pipe_empty",
730-
on_rotate = pipeworks.fix_after_rotation
732+
on_rotate = pipeworks.fix_after_rotation,
733+
check_for_pole = pipeworks.check_for_vert_pipe,
734+
check_for_horiz_pole = pipeworks.check_for_horiz_pipe
731735
})
732736

733737
new_flow_logic_register.directional_horizonal_rotate(nodename_sp_empty, true)

init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ if pipeworks.toggles.finite_water == nil then
102102
dofile(pipeworks.modpath.."/autodetect-finite-water.lua")
103103
end
104104

105+
if minetest.get_modpath("signs_lib") then
106+
dofile(pipeworks.modpath.."/signs_compat.lua")
107+
end
108+
105109
dofile(pipeworks.modpath.."/common.lua")
106110
dofile(pipeworks.modpath.."/models.lua")
107111
dofile(pipeworks.modpath.."/autoplace_pipes.lua")

pipes.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ for index, connects in ipairs(cconnects) do
8282
after_dig_node = function(pos)
8383
pipeworks.scan_for_pipe_objects(pos)
8484
end,
85-
on_rotate = false
85+
on_rotate = false,
86+
check_for_pole = pipeworks.check_for_vert_pipe,
87+
check_for_horiz_pole = pipeworks.check_for_horiz_pipe,
88+
pipenumber = index
8689
})
8790

8891
local pgroups = {snappy = 3, pipe = 1, not_in_creative_inventory = 1}
@@ -114,7 +117,10 @@ for index, connects in ipairs(cconnects) do
114117
after_dig_node = function(pos)
115118
pipeworks.scan_for_pipe_objects(pos)
116119
end,
117-
on_rotate = false
120+
on_rotate = false,
121+
check_for_pole = pipeworks.check_for_vert_pipe,
122+
check_for_horiz_pole = pipeworks.check_for_horiz_pipe,
123+
pipenumber = index
118124
})
119125

120126
local emptypipe = "pipeworks:pipe_"..index.."_empty"

routing_tubes.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ if pipeworks.enable_one_way_tube then
162162
after_place_node = pipeworks.after_place,
163163
after_dig_node = pipeworks.after_dig,
164164
on_rotate = pipeworks.on_rotate,
165+
check_for_pole = pipeworks.check_for_vert_tube,
166+
check_for_horiz_pole = pipeworks.check_for_horiz_tube
165167
})
166168
minetest.register_craft({
167169
output = "pipeworks:one_way_tube 2",

signs_compat.lua

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
-- This file adds placement rules for signs_lib, if present
2+
3+
local spv = {
4+
[4] = true,
5+
[6] = true,
6+
[8] = true,
7+
[10] = true,
8+
[13] = true,
9+
[15] = true,
10+
[17] = true,
11+
[19] = true
12+
}
13+
14+
local sphns = {
15+
[1] = true,
16+
[3] = true,
17+
[5] = true,
18+
[7] = true,
19+
[9] = true,
20+
[11] = true,
21+
[21] = true,
22+
[23] = true
23+
}
24+
25+
local sphew = {
26+
[0] = true,
27+
[2] = true,
28+
[12] = true,
29+
[14] = true,
30+
[16] = true,
31+
[18] = true,
32+
[20] = true,
33+
[22] = true
34+
}
35+
36+
local owtv = {
37+
[5] = true,
38+
[7] = true,
39+
[9] = true,
40+
[11] = true,
41+
[12] = true,
42+
[14] = true,
43+
[16] = true,
44+
[18] = true
45+
}
46+
47+
local owtns = {
48+
[0] = true,
49+
[2] = true,
50+
[4] = true,
51+
[6] = true,
52+
[8] = true,
53+
[10] = true,
54+
[20] = true,
55+
[22] = true
56+
}
57+
58+
local owtew = {
59+
[1] = true,
60+
[3] = true,
61+
[13] = true,
62+
[15] = true,
63+
[17] = true,
64+
[19] = true,
65+
[21] = true,
66+
[23] = true
67+
}
68+
69+
local vert_n = {
70+
[3] = {[5] = true},
71+
[6] = {[9] = true, [12] = true, [16] = true},
72+
[7] = {[9] = true, [11] = true},
73+
}
74+
75+
local vert_e = {
76+
[3] = {[5] = true},
77+
[6] = {[5] = true, [9] = true, [16] = true},
78+
[7] = {[7] = true, [11] = true},
79+
}
80+
81+
local vert_s = {
82+
[3] = {[5] = true},
83+
[6] = {[5] = true, [12] = true, [16] = true},
84+
[7] = {[5] = true, [7] = true},
85+
}
86+
87+
local vert_w = {
88+
[3] = {[5] = true},
89+
[6] = {[5] = true, [9] = true, [12] = true},
90+
[7] = {[5] = true, [9] = true},
91+
}
92+
93+
local horiz_n = {
94+
[3] = {[0] = true},
95+
[6] = {[0] = true, [4] = true, [20] = true},
96+
[7] = {[2] = true, [10] = true},
97+
[8] = {[0] = true},
98+
[9] = {[2] = true},
99+
}
100+
101+
local horiz_e = {
102+
[3] = {[1] = true},
103+
[6] = {[1] = true, [17] = true, [21] = true},
104+
[7] = {[3] = true, [19] = true},
105+
[8] = {[1] = true},
106+
[9] = {[3] = true},
107+
}
108+
109+
local horiz_s = {
110+
[3] = {[0] = true},
111+
[6] = {[0] = true, [8] = true, [20] = true},
112+
[7] = {[0] = true, [4] = true},
113+
[8] = {[0] = true},
114+
[9] = {[0] = true},
115+
}
116+
117+
local horiz_w = {
118+
[3] = {[1] = true},
119+
[6] = {[1] = true, [13] = true, [21] = true},
120+
[7] = {[1] = true, [13] = true},
121+
[8] = {[1] = true},
122+
[9] = {[1] = true},
123+
}
124+
125+
local function get_sign_dir(node, def)
126+
if (node.param2 == 4 and def.paramtype2 == "wallmounted")
127+
or (node.param2 == 0 and def.paramtype2 ~= "wallmounted") then
128+
return {["N"] = true}
129+
elseif (node.param2 == 2 and def.paramtype2 == "wallmounted")
130+
or (node.param2 == 1 and def.paramtype2 ~= "wallmounted") then
131+
return {["E"] = true}
132+
elseif (node.param2 == 5 and def.paramtype2 == "wallmounted")
133+
or (node.param2 == 2 and def.paramtype2 ~= "wallmounted") then
134+
return {["S"] = true}
135+
elseif node.param2 == 3 then
136+
return {["W"] = true}
137+
end
138+
return {}
139+
end
140+
141+
--[[
142+
In the functions below:
143+
144+
pos: the (real) position of the placed sign
145+
node: the sign node itself
146+
def: its definition
147+
148+
ppos: the position of the pointed node (pipe/tube)
149+
pnode: the node itself
150+
pdef: its definition
151+
152+
--]]
153+
154+
155+
-- pipes
156+
157+
function pipeworks.check_for_vert_pipe(pos, node, def, ppos, pnode, pdef)
158+
local signdir = get_sign_dir(node, def)
159+
local pipenumber = pdef.pipenumber
160+
local pipedir = pnode.param2
161+
if string.find(pnode.name, "straight_pipe") and spv[pipedir] then
162+
return true
163+
elseif signdir["N"] and vert_n[pipenumber] and vert_n[pipenumber][pipedir] then
164+
return true
165+
elseif signdir["E"] and vert_e[pipenumber] and vert_e[pipenumber][pipedir] then
166+
return true
167+
elseif signdir["S"] and vert_s[pipenumber] and vert_s[pipenumber][pipedir] then
168+
return true
169+
elseif signdir["W"] and vert_w[pipenumber] and vert_w[pipenumber][pipedir] then
170+
return true
171+
end
172+
end
173+
174+
function pipeworks.check_for_horiz_pipe(pos, node, def, ppos, pnode, pdef)
175+
local signdir = get_sign_dir(node, def)
176+
local pipenumber = pdef.pipenumber
177+
local pipedir = pnode.param2
178+
if string.find(pnode.name, "straight_pipe") then
179+
if (signdir["N"] or signdir["S"]) and sphns[pipedir] then
180+
return true
181+
elseif (signdir["E"] or signdir["W"]) and sphew[pipedir] then
182+
return true
183+
end
184+
elseif signdir["N"] and horiz_n[pipenumber] and horiz_n[pipenumber][pipedir] then
185+
return true
186+
elseif signdir["E"] and horiz_e[pipenumber] and horiz_e[pipenumber][pipedir] then
187+
return true
188+
elseif signdir["S"] and horiz_s[pipenumber] and horiz_s[pipenumber][pipedir] then
189+
return true
190+
elseif signdir["W"] and horiz_w[pipenumber] and horiz_w[pipenumber][pipedir] then
191+
return true
192+
end
193+
end
194+
195+
-- tubes
196+
197+
function pipeworks.check_for_vert_tube(pos, node, def, ppos, pnode, pdef)
198+
local signdir = get_sign_dir(node, def)
199+
local tubenumber = pdef.tubenumber
200+
local tubedir = pnode.param2
201+
if pnode.name == "pipeworks:one_way_tube" and owtv[tubedir] then
202+
return true
203+
elseif tubenumber == 2 and (tubedir == 5 or tubedir == 7) then -- it's a stub pointing up or down
204+
return true
205+
elseif signdir["N"] and vert_n[tubenumber] and vert_n[tubenumber][tubedir] then
206+
return true
207+
elseif signdir["E"] and vert_e[tubenumber] and vert_e[tubenumber][tubedir] then
208+
return true
209+
elseif signdir["S"] and vert_s[tubenumber] and vert_s[tubenumber][tubedir] then
210+
return true
211+
elseif signdir["W"] and vert_w[tubenumber] and vert_w[tubenumber][tubedir] then
212+
return true
213+
end
214+
end
215+
216+
function pipeworks.check_for_horiz_tube(pos, node, def, ppos, pnode, pdef)
217+
local signdir = get_sign_dir(node, def)
218+
local tubenumber = pdef.tubenumber
219+
local tubedir = pnode.param2
220+
if tubenumber == 2 then -- it'a a stub pointing sideways
221+
if (tubedir == 0 or tubedir == 2) and (signdir["N"] or signdir["S"]) then
222+
return true
223+
elseif (tubedir == 1 or tubedir == 3) and (signdir["E"] or signdir["W"]) then
224+
return true
225+
end
226+
elseif pnode.name == "pipeworks:one_way_tube" then
227+
if (signdir["N"] or signdir["S"]) and owtns[tubedir] then
228+
return true
229+
elseif (signdir["E"] or signdir["W"]) and owtew[tubedir] then
230+
return true
231+
end
232+
elseif signdir["N"] and horiz_n[tubenumber] and horiz_n[tubenumber][tubedir] then
233+
return true
234+
elseif signdir["E"] and horiz_e[tubenumber] and horiz_e[tubenumber][tubedir] then
235+
return true
236+
elseif signdir["S"] and horiz_s[tubenumber] and horiz_s[tubenumber][tubedir] then
237+
return true
238+
elseif signdir["W"] and horiz_w[tubenumber] and horiz_w[tubenumber][tubedir] then
239+
return true
240+
end
241+
end

tube_registration.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
116116
end
117117
minetest.swap_node(pos, {name = "pipeworks:broken_tube_1"})
118118
pipeworks.scan_for_tube_objects(pos)
119-
end
119+
end,
120+
check_for_pole = pipeworks.check_for_vert_tube,
121+
check_for_horiz_pole = pipeworks.check_for_horiz_tube,
122+
tubenumber = tonumber(tname)
120123
}
121124
if style == "6d" then
122125
nodedef.paramtype2 = "facedir"

0 commit comments

Comments
 (0)