commit | author | age
|
987cc5
|
1 |
-- See also technic/doc/api.md |
ee5c6c
|
2 |
|
468d79
|
3 |
technic.networks = {} |
d3f40e
|
4 |
technic.cables = {} |
be2f30
|
5 |
|
6abd85
|
6 |
local mesecons_path = minetest.get_modpath("mesecons") |
D |
7 |
local digilines_path = minetest.get_modpath("digilines") |
|
8 |
|
be2f30
|
9 |
local S = technic.getter |
468d79
|
10 |
|
54004f
|
11 |
local cable_entry = "^technic_cable_connection_overlay.png" |
VE |
12 |
|
ee0765
|
13 |
minetest.register_craft({ |
S |
14 |
output = "technic:switching_station", |
|
15 |
recipe = { |
83c649
|
16 |
{"", "technic:lv_transformer", ""}, |
S |
17 |
{"default:copper_ingot", "technic:machine_casing", "default:copper_ingot"}, |
|
18 |
{"technic:lv_cable", "technic:lv_cable", "technic:lv_cable"} |
ee0765
|
19 |
} |
S |
20 |
}) |
ee5c6c
|
21 |
|
338f3b
|
22 |
local mesecon_def |
D |
23 |
if mesecons_path then |
|
24 |
mesecon_def = {effector = { |
|
25 |
rules = mesecon.rules.default, |
|
26 |
}} |
|
27 |
end |
|
28 |
|
ee0765
|
29 |
minetest.register_node("technic:switching_station",{ |
be2f30
|
30 |
description = S("Switching Station"), |
54004f
|
31 |
tiles = { |
VE |
32 |
"technic_water_mill_top_active.png", |
|
33 |
"technic_water_mill_top_active.png"..cable_entry, |
|
34 |
"technic_water_mill_top_active.png", |
|
35 |
"technic_water_mill_top_active.png", |
|
36 |
"technic_water_mill_top_active.png", |
|
37 |
"technic_water_mill_top_active.png"}, |
83c649
|
38 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_all_tiers=1}, |
S |
39 |
connect_sides = {"bottom"}, |
ee0765
|
40 |
sounds = default.node_sound_wood_defaults(), |
S |
41 |
on_construct = function(pos) |
|
42 |
local meta = minetest.get_meta(pos) |
be2f30
|
43 |
meta:set_string("infotext", S("Switching Station")) |
563a4c
|
44 |
meta:set_string("active", 1) |
6abd85
|
45 |
meta:set_string("channel", "switching_station"..minetest.pos_to_string(pos)) |
D |
46 |
meta:set_string("formspec", "field[channel;Channel;${channel}]") |
ee0765
|
47 |
end, |
088eea
|
48 |
after_dig_node = function(pos) |
CK |
49 |
minetest.forceload_free_block(pos) |
|
50 |
pos.y = pos.y - 1 |
|
51 |
minetest.forceload_free_block(pos) |
|
52 |
end, |
6abd85
|
53 |
on_receive_fields = function(pos, formname, fields, sender) |
D |
54 |
if not fields.channel then |
|
55 |
return |
|
56 |
end |
|
57 |
local plname = sender:get_player_name() |
|
58 |
if minetest.is_protected(pos, plname) then |
|
59 |
minetest.record_protection_violation(pos, plname) |
|
60 |
return |
|
61 |
end |
|
62 |
local meta = minetest.get_meta(pos) |
|
63 |
meta:set_string("channel", fields.channel) |
|
64 |
end, |
338f3b
|
65 |
mesecons = mesecon_def, |
6abd85
|
66 |
digiline = { |
D |
67 |
receptor = {action = function() end}, |
|
68 |
effector = { |
|
69 |
action = function(pos, node, channel, msg) |
|
70 |
if msg ~= "GET" and msg ~= "get" then |
|
71 |
return |
|
72 |
end |
|
73 |
local meta = minetest.get_meta(pos) |
|
74 |
if channel ~= meta:get_string("channel") then |
|
75 |
return |
|
76 |
end |
|
77 |
digilines.receptor_send(pos, digilines.rules.default, channel, { |
|
78 |
supply = meta:get_int("supply"), |
|
79 |
demand = meta:get_int("demand") |
|
80 |
}) |
|
81 |
end |
|
82 |
}, |
|
83 |
}, |
ee0765
|
84 |
}) |
ee5c6c
|
85 |
|
K |
86 |
-------------------------------------------------- |
|
87 |
-- Functions to traverse the electrical network |
|
88 |
-------------------------------------------------- |
|
89 |
|
|
90 |
-- Add a wire node to the LV/MV/HV network |
d3f40e
|
91 |
local add_new_cable_node = function(nodes, pos, network_id) |
CK |
92 |
technic.cables[minetest.hash_node_position(pos)] = network_id |
ee0765
|
93 |
-- Ignore if the node has already been added |
S |
94 |
for i = 1, #nodes do |
|
95 |
if pos.x == nodes[i].x and |
|
96 |
pos.y == nodes[i].y and |
|
97 |
pos.z == nodes[i].z then |
|
98 |
return false |
|
99 |
end |
|
100 |
end |
|
101 |
table.insert(nodes, {x=pos.x, y=pos.y, z=pos.z, visited=1}) |
|
102 |
return true |
|
103 |
end |
ee5c6c
|
104 |
|
K |
105 |
-- Generic function to add found connected nodes to the right classification array |
d3f40e
|
106 |
local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, pos, machines, tier, sw_pos, from_below, network_id) |
c38da0
|
107 |
technic.get_or_load_node(pos) |
ee0765
|
108 |
local meta = minetest.get_meta(pos) |
S |
109 |
local name = minetest.get_node(pos).name |
|
110 |
|
|
111 |
if technic.is_tier_cable(name, tier) then |
d3f40e
|
112 |
add_new_cable_node(all_nodes, pos,network_id) |
ee0765
|
113 |
elseif machines[name] then |
S |
114 |
--dprint(name.." is a "..machines[name]) |
088eea
|
115 |
meta:set_string(tier.."_network",minetest.pos_to_string(sw_pos)) |
ee0765
|
116 |
if machines[name] == technic.producer then |
d3f40e
|
117 |
add_new_cable_node(PR_nodes, pos, network_id) |
ee0765
|
118 |
elseif machines[name] == technic.receiver then |
d3f40e
|
119 |
add_new_cable_node(RE_nodes, pos, network_id) |
623fca
|
120 |
elseif machines[name] == technic.producer_receiver then |
d3f40e
|
121 |
add_new_cable_node(PR_nodes, pos, network_id) |
CK |
122 |
add_new_cable_node(RE_nodes, pos, network_id) |
563a4c
|
123 |
elseif machines[name] == "SPECIAL" and |
9444ef
|
124 |
(pos.x ~= sw_pos.x or pos.y ~= sw_pos.y or pos.z ~= sw_pos.z) and |
E |
125 |
from_below then |
563a4c
|
126 |
-- Another switching station -> disable it |
d3f40e
|
127 |
add_new_cable_node(SP_nodes, pos, network_id) |
563a4c
|
128 |
meta:set_int("active", 0) |
ee0765
|
129 |
elseif machines[name] == technic.battery then |
d3f40e
|
130 |
add_new_cable_node(BA_nodes, pos, network_id) |
ee0765
|
131 |
end |
S |
132 |
|
|
133 |
meta:set_int(tier.."_EU_timeout", 2) -- Touch node |
|
134 |
end |
|
135 |
end |
ee5c6c
|
136 |
|
K |
137 |
-- Traverse a network given a list of machines and a cable type name |
d3f40e
|
138 |
local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, i, machines, tier, sw_pos, network_id) |
ee0765
|
139 |
local pos = all_nodes[i] |
S |
140 |
local positions = { |
|
141 |
{x=pos.x+1, y=pos.y, z=pos.z}, |
|
142 |
{x=pos.x-1, y=pos.y, z=pos.z}, |
|
143 |
{x=pos.x, y=pos.y+1, z=pos.z}, |
|
144 |
{x=pos.x, y=pos.y-1, z=pos.z}, |
|
145 |
{x=pos.x, y=pos.y, z=pos.z+1}, |
|
146 |
{x=pos.x, y=pos.y, z=pos.z-1}} |
|
147 |
--print("ON") |
|
148 |
for i, cur_pos in pairs(positions) do |
d3f40e
|
149 |
check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, cur_pos, machines, tier, sw_pos, i == 3, network_id) |
ee0765
|
150 |
end |
S |
151 |
end |
ee5c6c
|
152 |
|
f4ac2b
|
153 |
local touch_nodes = function(list, tier) |
N |
154 |
for _, pos in ipairs(list) do |
|
155 |
local meta = minetest.get_meta(pos) |
|
156 |
meta:set_int(tier.."_EU_timeout", 2) -- Touch node |
|
157 |
end |
|
158 |
end |
|
159 |
|
563a4c
|
160 |
local get_network = function(sw_pos, pos1, tier) |
12d29c
|
161 |
local cached = technic.networks[minetest.hash_node_position(pos1)] |
f4ac2b
|
162 |
if cached and cached.tier == tier then |
N |
163 |
touch_nodes(cached.PR_nodes, tier) |
|
164 |
touch_nodes(cached.BA_nodes, tier) |
|
165 |
touch_nodes(cached.RE_nodes, tier) |
563a4c
|
166 |
for _, pos in ipairs(cached.SP_nodes) do |
N |
167 |
local meta = minetest.get_meta(pos) |
|
168 |
meta:set_int("active", 0) |
|
169 |
meta:set_string("active_pos", minetest.serialize(sw_pos)) |
|
170 |
end |
f4ac2b
|
171 |
return cached.PR_nodes, cached.BA_nodes, cached.RE_nodes |
N |
172 |
end |
|
173 |
local i = 1 |
|
174 |
local PR_nodes = {} |
|
175 |
local BA_nodes = {} |
|
176 |
local RE_nodes = {} |
563a4c
|
177 |
local SP_nodes = {} |
f4ac2b
|
178 |
local all_nodes = {pos1} |
N |
179 |
repeat |
563a4c
|
180 |
traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, |
d3f40e
|
181 |
i, technic.machines[tier], tier, sw_pos, minetest.hash_node_position(pos1)) |
f4ac2b
|
182 |
i = i + 1 |
N |
183 |
until all_nodes[i] == nil |
563a4c
|
184 |
technic.networks[minetest.hash_node_position(pos1)] = {tier = tier, PR_nodes = PR_nodes, |
088eea
|
185 |
RE_nodes = RE_nodes, BA_nodes = BA_nodes, SP_nodes = SP_nodes, all_nodes = all_nodes} |
f4ac2b
|
186 |
return PR_nodes, BA_nodes, RE_nodes |
N |
187 |
end |
|
188 |
|
ee0765
|
189 |
----------------------------------------------- |
S |
190 |
-- The action code for the switching station -- |
|
191 |
----------------------------------------------- |
9d5bd9
|
192 |
|
VE |
193 |
technic.powerctrl_state = true |
|
194 |
|
|
195 |
minetest.register_chatcommand("powerctrl", { |
|
196 |
params = "state", |
|
197 |
description = "Enables or disables technic's switching station ABM", |
|
198 |
privs = { basic_privs = true }, |
|
199 |
func = function(name, state) |
|
200 |
if state == "on" then |
|
201 |
technic.powerctrl_state = true |
|
202 |
else |
|
203 |
technic.powerctrl_state = false |
|
204 |
end |
|
205 |
end |
|
206 |
}) |
|
207 |
|
ee0765
|
208 |
minetest.register_abm({ |
S |
209 |
nodenames = {"technic:switching_station"}, |
c6464d
|
210 |
label = "Switching Station", -- allows the mtt profiler to profile this abm individually |
ee5c6c
|
211 |
interval = 1, |
K |
212 |
chance = 1, |
|
213 |
action = function(pos, node, active_object_count, active_object_count_wider) |
9d5bd9
|
214 |
if not technic.powerctrl_state then return end |
ee0765
|
215 |
local meta = minetest.get_meta(pos) |
S |
216 |
local meta1 = nil |
|
217 |
local pos1 = {} |
|
218 |
local PR_EU = 0 -- EUs from PR nodes |
|
219 |
local BA_PR_EU = 0 -- EUs from BA nodes (discharching) |
|
220 |
local BA_RE_EU = 0 -- EUs to BA nodes (charging) |
|
221 |
local RE_EU = 0 -- EUs to RE nodes |
ee5c6c
|
222 |
|
ee0765
|
223 |
local tier = "" |
f4ac2b
|
224 |
local PR_nodes |
N |
225 |
local BA_nodes |
|
226 |
local RE_nodes |
be2f30
|
227 |
local machine_name = S("Switching Station") |
6abd85
|
228 |
|
ee0765
|
229 |
-- Which kind of network are we on: |
S |
230 |
pos1 = {x=pos.x, y=pos.y-1, z=pos.z} |
ee5c6c
|
231 |
|
088eea
|
232 |
--Disable if necessary |
CK |
233 |
if meta:get_int("active") ~= 1 then |
|
234 |
minetest.forceload_free_block(pos) |
|
235 |
minetest.forceload_free_block(pos1) |
|
236 |
meta:set_string("infotext",S("%s Already Present"):format(machine_name)) |
|
237 |
return |
|
238 |
end |
|
239 |
|
ee0765
|
240 |
local name = minetest.get_node(pos1).name |
S |
241 |
local tier = technic.get_cable_tier(name) |
|
242 |
if tier then |
088eea
|
243 |
-- Forceload switching station |
CK |
244 |
minetest.forceload_block(pos) |
|
245 |
minetest.forceload_block(pos1) |
563a4c
|
246 |
PR_nodes, BA_nodes, RE_nodes = get_network(pos, pos1, tier) |
ee0765
|
247 |
else |
S |
248 |
--dprint("Not connected to a network") |
be2f30
|
249 |
meta:set_string("infotext", S("%s Has No Network"):format(machine_name)) |
088eea
|
250 |
minetest.forceload_free_block(pos) |
CK |
251 |
minetest.forceload_free_block(pos1) |
ee0765
|
252 |
return |
S |
253 |
end |
6abd85
|
254 |
|
563a4c
|
255 |
-- Run all the nodes |
10307f
|
256 |
local function run_nodes(list, run_stage) |
563a4c
|
257 |
for _, pos2 in ipairs(list) do |
c38da0
|
258 |
technic.get_or_load_node(pos2) |
563a4c
|
259 |
local node2 = minetest.get_node(pos2) |
N |
260 |
local nodedef |
|
261 |
if node2 and node2.name then |
|
262 |
nodedef = minetest.registered_nodes[node2.name] |
|
263 |
end |
|
264 |
if nodedef and nodedef.technic_run then |
10307f
|
265 |
nodedef.technic_run(pos2, node2, run_stage) |
563a4c
|
266 |
end |
N |
267 |
end |
|
268 |
end |
6abd85
|
269 |
|
10307f
|
270 |
run_nodes(PR_nodes, technic.producer) |
M'P |
271 |
run_nodes(RE_nodes, technic.receiver) |
|
272 |
run_nodes(BA_nodes, technic.battery) |
ee5c6c
|
273 |
|
ee0765
|
274 |
-- Strings for the meta data |
S |
275 |
local eu_demand_str = tier.."_EU_demand" |
|
276 |
local eu_input_str = tier.."_EU_input" |
|
277 |
local eu_supply_str = tier.."_EU_supply" |
ee5c6c
|
278 |
|
7cfb38
|
279 |
-- Distribute charge equally across multiple batteries. |
KZ |
280 |
local charge_total = 0 |
|
281 |
local battery_count = 0 |
|
282 |
|
|
283 |
for n, pos1 in pairs(BA_nodes) do |
|
284 |
meta1 = minetest.get_meta(pos1) |
|
285 |
local charge = meta1:get_int("internal_EU_charge") |
|
286 |
|
|
287 |
if (meta1:get_int(eu_demand_str) ~= 0) then |
|
288 |
charge_total = charge_total + charge |
|
289 |
battery_count = battery_count + 1 |
|
290 |
end |
|
291 |
end |
|
292 |
|
|
293 |
local charge_distributed = math.floor(charge_total / battery_count) |
|
294 |
|
|
295 |
for n, pos1 in pairs(BA_nodes) do |
|
296 |
meta1 = minetest.get_meta(pos1) |
|
297 |
|
|
298 |
if (meta1:get_int(eu_demand_str) ~= 0) then |
|
299 |
meta1:set_int("internal_EU_charge", charge_distributed) |
|
300 |
end |
|
301 |
end |
|
302 |
|
ee0765
|
303 |
-- Get all the power from the PR nodes |
S |
304 |
local PR_eu_supply = 0 -- Total power |
|
305 |
for _, pos1 in pairs(PR_nodes) do |
|
306 |
meta1 = minetest.get_meta(pos1) |
|
307 |
PR_eu_supply = PR_eu_supply + meta1:get_int(eu_supply_str) |
|
308 |
end |
|
309 |
--dprint("Total PR supply:"..PR_eu_supply) |
ee5c6c
|
310 |
|
ee0765
|
311 |
-- Get all the demand from the RE nodes |
S |
312 |
local RE_eu_demand = 0 |
|
313 |
for _, pos1 in pairs(RE_nodes) do |
|
314 |
meta1 = minetest.get_meta(pos1) |
|
315 |
RE_eu_demand = RE_eu_demand + meta1:get_int(eu_demand_str) |
|
316 |
end |
|
317 |
--dprint("Total RE demand:"..RE_eu_demand) |
ee5c6c
|
318 |
|
ee0765
|
319 |
-- Get all the power from the BA nodes |
S |
320 |
local BA_eu_supply = 0 |
|
321 |
for _, pos1 in pairs(BA_nodes) do |
|
322 |
meta1 = minetest.get_meta(pos1) |
|
323 |
BA_eu_supply = BA_eu_supply + meta1:get_int(eu_supply_str) |
|
324 |
end |
|
325 |
--dprint("Total BA supply:"..BA_eu_supply) |
ee5c6c
|
326 |
|
ee0765
|
327 |
-- Get all the demand from the BA nodes |
S |
328 |
local BA_eu_demand = 0 |
|
329 |
for _, pos1 in pairs(BA_nodes) do |
|
330 |
meta1 = minetest.get_meta(pos1) |
|
331 |
BA_eu_demand = BA_eu_demand + meta1:get_int(eu_demand_str) |
|
332 |
end |
|
333 |
--dprint("Total BA demand:"..BA_eu_demand) |
ee5c6c
|
334 |
|
ee0765
|
335 |
meta:set_string("infotext", |
4b1798
|
336 |
S("@1. Supply: @2 Demand: @3", |
85a984
|
337 |
machine_name, technic.pretty_num(PR_eu_supply), technic.pretty_num(RE_eu_demand))) |
ee5c6c
|
338 |
|
6abd85
|
339 |
-- If mesecon signal and power supply or demand changed then |
D |
340 |
-- send them via digilines. |
|
341 |
if mesecons_path and digilines_path and mesecon.is_powered(pos) then |
|
342 |
if PR_eu_supply ~= meta:get_int("supply") or |
|
343 |
RE_eu_demand ~= meta:get_int("demand") then |
|
344 |
local channel = meta:get_string("channel") |
|
345 |
digilines.receptor_send(pos, digilines.rules.default, channel, { |
|
346 |
supply = PR_eu_supply, |
|
347 |
demand = RE_eu_demand |
|
348 |
}) |
|
349 |
end |
|
350 |
end |
|
351 |
|
088eea
|
352 |
-- Data that will be used by the power monitor |
CK |
353 |
meta:set_int("supply",PR_eu_supply) |
|
354 |
meta:set_int("demand",RE_eu_demand) |
|
355 |
|
ee0765
|
356 |
-- If the PR supply is enough for the RE demand supply them all |
S |
357 |
if PR_eu_supply >= RE_eu_demand then |
|
358 |
--dprint("PR_eu_supply"..PR_eu_supply.." >= RE_eu_demand"..RE_eu_demand) |
|
359 |
for _, pos1 in pairs(RE_nodes) do |
|
360 |
meta1 = minetest.get_meta(pos1) |
|
361 |
local eu_demand = meta1:get_int(eu_demand_str) |
|
362 |
meta1:set_int(eu_input_str, eu_demand) |
|
363 |
end |
|
364 |
-- We have a surplus, so distribute the rest equally to the BA nodes |
|
365 |
-- Let's calculate the factor of the demand |
|
366 |
PR_eu_supply = PR_eu_supply - RE_eu_demand |
|
367 |
local charge_factor = 0 -- Assume all batteries fully charged |
|
368 |
if BA_eu_demand > 0 then |
|
369 |
charge_factor = PR_eu_supply / BA_eu_demand |
|
370 |
end |
|
371 |
for n, pos1 in pairs(BA_nodes) do |
|
372 |
meta1 = minetest.get_meta(pos1) |
|
373 |
local eu_demand = meta1:get_int(eu_demand_str) |
|
374 |
meta1:set_int(eu_input_str, math.floor(eu_demand * charge_factor)) |
|
375 |
--dprint("Charging battery:"..math.floor(eu_demand*charge_factor)) |
|
376 |
end |
|
377 |
return |
|
378 |
end |
ee5c6c
|
379 |
|
ee0765
|
380 |
-- If the PR supply is not enough for the RE demand we will discharge the batteries too |
S |
381 |
if PR_eu_supply + BA_eu_supply >= RE_eu_demand then |
|
382 |
--dprint("PR_eu_supply "..PR_eu_supply.."+BA_eu_supply "..BA_eu_supply.." >= RE_eu_demand"..RE_eu_demand) |
|
383 |
for _, pos1 in pairs(RE_nodes) do |
|
384 |
meta1 = minetest.get_meta(pos1) |
|
385 |
local eu_demand = meta1:get_int(eu_demand_str) |
|
386 |
meta1:set_int(eu_input_str, eu_demand) |
|
387 |
end |
|
388 |
-- We have a deficit, so distribute to the BA nodes |
|
389 |
-- Let's calculate the factor of the supply |
|
390 |
local charge_factor = 0 -- Assume all batteries depleted |
|
391 |
if BA_eu_supply > 0 then |
|
392 |
charge_factor = (PR_eu_supply - RE_eu_demand) / BA_eu_supply |
|
393 |
end |
|
394 |
for n,pos1 in pairs(BA_nodes) do |
|
395 |
meta1 = minetest.get_meta(pos1) |
ee5c6c
|
396 |
local eu_supply = meta1:get_int(eu_supply_str) |
ee0765
|
397 |
meta1:set_int(eu_input_str, math.floor(eu_supply * charge_factor)) |
S |
398 |
--dprint("Discharging battery:"..math.floor(eu_supply*charge_factor)) |
|
399 |
end |
|
400 |
return |
|
401 |
end |
ee5c6c
|
402 |
|
ee0765
|
403 |
-- If the PR+BA supply is not enough for the RE demand: Power only the batteries |
S |
404 |
local charge_factor = 0 -- Assume all batteries fully charged |
|
405 |
if BA_eu_demand > 0 then |
|
406 |
charge_factor = PR_eu_supply / BA_eu_demand |
|
407 |
end |
|
408 |
for n, pos1 in pairs(BA_nodes) do |
|
409 |
meta1 = minetest.get_meta(pos1) |
|
410 |
local eu_demand = meta1:get_int(eu_demand_str) |
|
411 |
meta1:set_int(eu_input_str, math.floor(eu_demand * charge_factor)) |
|
412 |
end |
|
413 |
for n, pos1 in pairs(RE_nodes) do |
|
414 |
meta1 = minetest.get_meta(pos1) |
|
415 |
meta1:set_int(eu_input_str, 0) |
|
416 |
end |
6abd85
|
417 |
|
ee5c6c
|
418 |
end, |
K |
419 |
}) |
ee0765
|
420 |
|
563a4c
|
421 |
-- Timeout ABM |
N |
422 |
-- Timeout for a node in case it was disconnected from the network |
|
423 |
-- A node must be touched by the station continuously in order to function |
|
424 |
local function switching_station_timeout_count(pos, tier) |
|
425 |
local meta = minetest.get_meta(pos) |
|
426 |
local timeout = meta:get_int(tier.."_EU_timeout") |
|
427 |
if timeout <= 0 then |
4ac36e
|
428 |
meta:set_int(tier.."_EU_input", 0) -- Not needed anymore <-- actually, it is for supply converter |
563a4c
|
429 |
return true |
N |
430 |
else |
|
431 |
meta:set_int(tier.."_EU_timeout", timeout - 1) |
|
432 |
return false |
|
433 |
end |
|
434 |
end |
|
435 |
minetest.register_abm({ |
78f16c
|
436 |
label = "Machines: timeout check", |
563a4c
|
437 |
nodenames = {"group:technic_machine"}, |
N |
438 |
interval = 1, |
|
439 |
chance = 1, |
|
440 |
action = function(pos, node, active_object_count, active_object_count_wider) |
088eea
|
441 |
local meta = minetest.get_meta(pos) |
563a4c
|
442 |
for tier, machines in pairs(technic.machines) do |
N |
443 |
if machines[node.name] and switching_station_timeout_count(pos, tier) then |
|
444 |
local nodedef = minetest.registered_nodes[node.name] |
|
445 |
if nodedef and nodedef.technic_disabled_machine_name then |
|
446 |
node.name = nodedef.technic_disabled_machine_name |
|
447 |
minetest.swap_node(pos, node) |
1c617f
|
448 |
elseif nodedef and nodedef.technic_on_disable then |
N |
449 |
nodedef.technic_on_disable(pos, node) |
563a4c
|
450 |
end |
N |
451 |
if nodedef then |
|
452 |
local meta = minetest.get_meta(pos) |
|
453 |
meta:set_string("infotext", S("%s Has No Network"):format(nodedef.description)) |
|
454 |
end |
|
455 |
end |
|
456 |
end |
|
457 |
end, |
|
458 |
}) |
|
459 |
|
088eea
|
460 |
--Re-enable disabled switching station if necessary, similar to the timeout above |
CK |
461 |
minetest.register_abm({ |
78f16c
|
462 |
label = "Machines: re-enable check", |
088eea
|
463 |
nodenames = {"technic:switching_station"}, |
CK |
464 |
interval = 1, |
|
465 |
chance = 1, |
|
466 |
action = function(pos, node, active_object_count, active_object_count_wider) |
|
467 |
local meta = minetest.get_meta(pos) |
|
468 |
local pos1 = {x=pos.x,y=pos.y-1,z=pos.z} |
|
469 |
local tier = technic.get_cable_tier(minetest.get_node(pos1).name) |
|
470 |
if not tier then return end |
|
471 |
if switching_station_timeout_count(pos, tier) then |
|
472 |
local meta = minetest.get_meta(pos) |
|
473 |
meta:set_int("active",1) |
|
474 |
end |
|
475 |
end, |
|
476 |
}) |
|
477 |
|
ee0765
|
478 |
for tier, machines in pairs(technic.machines) do |
S |
479 |
-- SPECIAL will not be traversed |
|
480 |
technic.register_machine(tier, "technic:switching_station", "SPECIAL") |
|
481 |
end |
|
482 |
|