Vanessa Ezekowitz
2014-07-23 29c7ff5228864bcf5456f391b122c9eb477c754b
commit | author | age
ee5c6c 1 -- The supply converter is a generic device which can convert from
K 2 -- LV to MV and back, and HV to MV and back.
3 -- The machine is configured by the wiring below and above it.
4 --
5 -- It works like this:
ee0765 6 --   The top side is setup as the receiver side, the bottom as the producer side.
S 7 --   Once the receiver side is powered it will deliver power to the other side.
ee5c6c 8 --   Unused power is wasted just like any other producer!
ee0765 9
be2f30 10 local S = technic.getter
S 11
563a4c 12 local run = function(pos, node)
N 13     local demand = 10000
14     local remain = 0.9
15     -- Machine information
16     local machine_name  = S("Supply Converter")
17     local meta          = minetest.get_meta(pos)
18
19     local pos_up        = {x=pos.x, y=pos.y+1, z=pos.z}
20     local pos_down      = {x=pos.x, y=pos.y-1, z=pos.z}
21     local name_up       = minetest.get_node(pos_up).name
22     local name_down     = minetest.get_node(pos_down).name
23
24     local from = technic.get_cable_tier(name_up)
25     local to   = technic.get_cable_tier(name_down)
26
27     if from and to then
28         local input = meta:get_int(from.."_EU_input")
29         meta:set_int(from.."_EU_demand", demand)
30         meta:set_int(from.."_EU_supply", 0)
31         meta:set_int(to.."_EU_demand", 0)
32         meta:set_int(to.."_EU_supply", input * remain)
33         meta:set_string("infotext", machine_name
34             .." ("..input.." "..from.." -> "
35             ..input * remain.." "..to..")")
36     else
37         meta:set_string("infotext", S("%s Has Bad Cabling"):format(machine_name))
efd5ff 38         if to then
N 39             meta:set_int(to.."_EU_supply", 0)
40         end
41         if from then
42             meta:set_int(from.."_EU_demand", 0)
43         end
563a4c 44         return
N 45     end
46
47 end
48
ee0765 49 minetest.register_node("technic:supply_converter", {
be2f30 50     description = S("Supply Converter"),
ee0765 51     tiles  = {"technic_supply_converter_top.png", "technic_supply_converter_bottom.png",
S 52               "technic_supply_converter_side.png", "technic_supply_converter_side.png",
53               "technic_supply_converter_side.png", "technic_supply_converter_side.png"},
563a4c 54     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1},
ee0765 55     sounds = default.node_sound_wood_defaults(),
S 56     drawtype = "nodebox",
57     paramtype = "light",
58     node_box = {
59         type = "fixed",
60         fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
61     },
62     on_construct = function(pos)
63         local meta = minetest.env:get_meta(pos)
be2f30 64         meta:set_string("infotext", S("Supply Converter"))
ee0765 65         meta:set_float("active", false)
S 66     end,
563a4c 67     technic_run = run,
ee0765 68 })
ee5c6c 69
K 70 minetest.register_craft({
71     output = 'technic:supply_converter 1',
72     recipe = {
5e4a87 73         {'technic:fine_gold_wire',        'technic:rubber',         'technic:doped_silicon_wafer'},
4958a7 74         {'technic:mv_transformer',        'technic:machine_casing', 'technic:lv_transformer'},
e8a5a6 75         {'technic:mv_cable0',             'technic:rubber',         'technic:lv_cable0'},
ee5c6c 76     }
K 77 })
ee0765 78
S 79 for tier, machines in pairs(technic.machines) do
623fca 80     technic.register_machine(tier, "technic:supply_converter", technic.producer_receiver)
ee0765 81 end
S 82