Carter Kolwey
2017-02-28 5e19514c60bd46a939beeeddde1125f137c486fb
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)
85a984 33         meta:set_string("infotext", S("@1 (@2 @3 -> @4 @5)", machine_name, technic.pretty_num(input), from, technic.pretty_num(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"},
83c649 52     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
S 53         technic_machine=1, technic_all_tiers=1},
54     connect_sides = {"top", "bottom"},
ee0765 55     sounds = default.node_sound_wood_defaults(),
S 56     on_construct = function(pos)
a41390 57         local meta = minetest.get_meta(pos)
be2f30 58         meta:set_string("infotext", S("Supply Converter"))
ee0765 59         meta:set_float("active", false)
S 60     end,
563a4c 61     technic_run = run,
ee0765 62 })
ee5c6c 63
K 64 minetest.register_craft({
65     output = 'technic:supply_converter 1',
66     recipe = {
83c649 67         {'technic:fine_gold_wire', 'technic:rubber',         'technic:doped_silicon_wafer'},
S 68         {'technic:mv_transformer', 'technic:machine_casing', 'technic:lv_transformer'},
69         {'technic:mv_cable',       'technic:rubber',         'technic:lv_cable'},
ee5c6c 70     }
K 71 })
ee0765 72
S 73 for tier, machines in pairs(technic.machines) do
623fca 74     technic.register_machine(tier, "technic:supply_converter", technic.producer_receiver)
ee0765 75 end
S 76