ShadowNinja
2013-07-17 ee0765804c0a21deeb2f33c22ac1a36cb0db5f43
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
S 10 minetest.register_node("technic:supply_converter", {
11     description = "Supply Converter",
12     tiles  = {"technic_supply_converter_top.png", "technic_supply_converter_bottom.png",
13               "technic_supply_converter_side.png", "technic_supply_converter_side.png",
14               "technic_supply_converter_side.png", "technic_supply_converter_side.png"},
15     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
16     sounds = default.node_sound_wood_defaults(),
17     drawtype = "nodebox",
18     paramtype = "light",
19     node_box = {
20         type = "fixed",
21         fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
22     },
23     on_construct = function(pos)
24         local meta = minetest.env:get_meta(pos)
25         meta:set_string("infotext", "Supply Converter")
26         meta:set_float("active", false)
27     end,
28 })
ee5c6c 29
K 30 minetest.register_craft({
31     output = 'technic:supply_converter 1',
32     recipe = {
ee0765 33         {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
S 34         {'technic:mv_transformer',        'technic:mv_cable0',             'technic:lv_transformer'},
35         {'technic:mv_cable0',             'technic:rubber',                'technic:lv_cable0'},
ee5c6c 36     }
K 37 })
38
ee0765 39 minetest.register_abm({
S 40     nodenames = {"technic:supply_converter"},
41     interval   = 1,
42     chance     = 1,
43     action = function(pos, node, active_object_count, active_object_count_wider)
44         local demand = 10000
45         local remain = 0.9
46         -- Machine information
47         local machine_name  = "Supply Converter"
48         local meta          = minetest.get_meta(pos)
ee5c6c 49
ee0765 50         local pos_up        = {x=pos.x, y=pos.y+1, z=pos.z}
S 51         local pos_down      = {x=pos.x, y=pos.y-1, z=pos.z}
52         local name_up       = minetest.get_node(pos_up).name
53         local name_down     = minetest.get_node(pos_down).name
ee5c6c 54
ee0765 55         local from = technic.get_cable_tier(name_up)
S 56         local to   = technic.get_cable_tier(name_down)
ee5c6c 57
ee0765 58         if from and to then
S 59             technic.switching_station_timeout_count(pos, from)
60             local input = meta:get_int(from.."_EU_input")
61             meta:set_int(from.."_EU_demand", demand)
62             meta:set_int(from.."_EU_supply", 0)
63             meta:set_int(to.."_EU_demand", 0)
64             meta:set_int(to.."_EU_supply", input * remain)
65             meta:set_string("infotext", machine_name
66                 .." ("..input.." "..from.." -> "
67                 ..input * remain.." "..to..")")
68         else
69             meta:set_string("infotext", machine_name.." has bad cabling")
70             return
71         end
ee5c6c 72
K 73     end,
74 })
ee0765 75
S 76 for tier, machines in pairs(technic.machines) do
77     technic.register_machine(tier, "technic:supply_converter", technic.battery)
78 end
79