est31
2015-06-18 a793747d92d9b1d93153c7fb4e0c82fe90624c78
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)
4b1798 33         meta:set_string("infotext", S("@1 (@2 @3 -> @4 @5)", machine_name, technic.prettynum(input), from, technic.prettynum(input * remain), to))
563a4c 34     else
N 35         meta:set_string("infotext", S("%s Has Bad Cabling"):format(machine_name))
efd5ff 36         if to then
N 37             meta:set_int(to.."_EU_supply", 0)
38         end
39         if from then
40             meta:set_int(from.."_EU_demand", 0)
41         end
563a4c 42         return
N 43     end
44
45 end
46
ee0765 47 minetest.register_node("technic:supply_converter", {
be2f30 48     description = S("Supply Converter"),
ee0765 49     tiles  = {"technic_supply_converter_top.png", "technic_supply_converter_bottom.png",
S 50               "technic_supply_converter_side.png", "technic_supply_converter_side.png",
51               "technic_supply_converter_side.png", "technic_supply_converter_side.png"},
563a4c 52     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1},
ee0765 53     sounds = default.node_sound_wood_defaults(),
S 54     drawtype = "nodebox",
55     paramtype = "light",
56     node_box = {
57         type = "fixed",
58         fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
59     },
60     on_construct = function(pos)
a41390 61         local meta = minetest.get_meta(pos)
be2f30 62         meta:set_string("infotext", S("Supply Converter"))
ee0765 63         meta:set_float("active", false)
S 64     end,
563a4c 65     technic_run = run,
ee0765 66 })
ee5c6c 67
K 68 minetest.register_craft({
69     output = 'technic:supply_converter 1',
70     recipe = {
5e4a87 71         {'technic:fine_gold_wire',        'technic:rubber',         'technic:doped_silicon_wafer'},
4958a7 72         {'technic:mv_transformer',        'technic:machine_casing', 'technic:lv_transformer'},
e8a5a6 73         {'technic:mv_cable0',             'technic:rubber',         'technic:lv_cable0'},
ee5c6c 74     }
K 75 })
ee0765 76
S 77 for tier, machines in pairs(technic.machines) do
623fca 78     technic.register_machine(tier, "technic:supply_converter", technic.producer_receiver)
ee0765 79 end
S 80