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