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