Vanessa Ezekowitz
2017-03-10 343c7946d9014bf111e25a7a225a1b6f5746992b
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
7 minetest.register_craft({
8     output = "technic:power_monitor",
9     recipe = {
10         {"",                 "",                       ""},
11         {"",                 "technic:machine_casing", "default:copper_ingot"},
12         {"technic:lv_cable", "technic:lv_cable",       "technic:lv_cable"}
13     }
14 })
15
16 minetest.register_node("technic:power_monitor",{
17     description = S("Power Monitor"),
343c79 18     tiles  = {
VE 19         "technic_power_monitor_sides.png",
20         "technic_power_monitor_bottom_back.png",
21         "technic_power_monitor_sides.png",
22         "technic_power_monitor_sides.png",
23         "technic_power_monitor_bottom_back.png",
24         "technic_power_monitor_front.png"
25     },
26     paramtype2 = "facedir",
088eea 27     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_all_tiers=1, technic_machine=1},
343c79 28     connect_sides = {"bottom", "back"},
088eea 29     sounds = default.node_sound_wood_defaults(),
CK 30     on_construct = function(pos)
31         local meta = minetest.get_meta(pos)
32         meta:set_string("infotext", S("Power Monitor"))
33     end,
34 })
35
36 minetest.register_abm({
37     nodenames = {"technic:power_monitor"},
38     label = "Power Monitor",
39     interval   = 1,
40     chance     = 1,
41     action = function(pos, node, active_object_count, active_object_count_wider)
42         local meta = minetest.get_meta(pos)
43         local network_hash = technic.cables[minetest.hash_node_position(pos)]
44         local network = network_hash and minetest.get_position_from_hash(network_hash)
45         local sw_pos = network and {x=network.x,y=network.y+1,z=network.z}
46         local timeout = 0
47         for tier in pairs(technic.machines) do
48             timeout = math.max(meta:get_int(tier.."_EU_timeout"),timeout)
49         end
50         if timeout > 0 and sw_pos and minetest.get_node(sw_pos).name == "technic:switching_station" then
51             local sw_meta = minetest.get_meta(sw_pos)
52             local supply = sw_meta:get_int("supply")
53             local demand = sw_meta:get_int("demand")
54             meta:set_string("infotext",
55                     S("Power Monitor. Supply: @1 Demand: @2",
56                     technic.pretty_num(supply), technic.pretty_num(demand)))
57         else
58             meta:set_string("infotext",S("Power Monitor Has No Network"))
59         end
60     end,
61 })
62
63 for tier in pairs(technic.machines) do
64     -- RE in order to use the "timeout" functions, although it consumes 0 power
65     technic.register_machine(tier, "technic:power_monitor", "RE")
66 end
67