coil
2019-08-26 d119a6748264a4f9825eebdd4ddeb2421cc4784a
commit | author | age
088eea 1 -- POWER MONITOR
CK 2 -- The power monitor can be used to monitor how much power is available on a network,
3 -- similarly to the old "slave" switching stations.
4
5 local S = technic.getter
6
54004f 7 local cable_entry = "^technic_cable_connection_overlay.png"
VE 8
088eea 9 minetest.register_craft({
CK 10     output = "technic:power_monitor",
11     recipe = {
12         {"",                 "",                       ""},
13         {"",                 "technic:machine_casing", "default:copper_ingot"},
14         {"technic:lv_cable", "technic:lv_cable",       "technic:lv_cable"}
15     }
16 })
17
18 minetest.register_node("technic:power_monitor",{
19     description = S("Power Monitor"),
343c79 20     tiles  = {
VE 21         "technic_power_monitor_sides.png",
54004f 22         "technic_power_monitor_sides.png"..cable_entry,
343c79 23         "technic_power_monitor_sides.png",
VE 24         "technic_power_monitor_sides.png",
54004f 25         "technic_power_monitor_sides.png"..cable_entry,
343c79 26         "technic_power_monitor_front.png"
VE 27     },
28     paramtype2 = "facedir",
088eea 29     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_all_tiers=1, technic_machine=1},
343c79 30     connect_sides = {"bottom", "back"},
088eea 31     sounds = default.node_sound_wood_defaults(),
CK 32     on_construct = function(pos)
33         local meta = minetest.get_meta(pos)
34         meta:set_string("infotext", S("Power Monitor"))
35     end,
36 })
37
38 minetest.register_abm({
39     nodenames = {"technic:power_monitor"},
78f16c 40     label = "Machines: run power monitor",
088eea 41     interval   = 1,
CK 42     chance     = 1,
43     action = function(pos, node, active_object_count, active_object_count_wider)
44         local meta = minetest.get_meta(pos)
45         local network_hash = technic.cables[minetest.hash_node_position(pos)]
46         local network = network_hash and minetest.get_position_from_hash(network_hash)
47         local sw_pos = network and {x=network.x,y=network.y+1,z=network.z}
48         local timeout = 0
49         for tier in pairs(technic.machines) do
50             timeout = math.max(meta:get_int(tier.."_EU_timeout"),timeout)
51         end
52         if timeout > 0 and sw_pos and minetest.get_node(sw_pos).name == "technic:switching_station" then
53             local sw_meta = minetest.get_meta(sw_pos)
54             local supply = sw_meta:get_int("supply")
55             local demand = sw_meta:get_int("demand")
56             meta:set_string("infotext",
57                     S("Power Monitor. Supply: @1 Demand: @2",
41f175 58                     technic.EU_string(supply), technic.EU_string(demand)))
088eea 59         else
CK 60             meta:set_string("infotext",S("Power Monitor Has No Network"))
61         end
62     end,
63 })
64
65 for tier in pairs(technic.machines) do
66     -- RE in order to use the "timeout" functions, although it consumes 0 power
67     technic.register_machine(tier, "technic:power_monitor", "RE")
68 end
69