Vanessa Ezekowitz
2017-03-10 343c7946d9014bf111e25a7a225a1b6f5746992b
commit | author | age
ee0765 1 -- Solar panels are the building blocks of LV solar arrays
S 2 -- They can however also be used separately but with reduced efficiency due to the missing transformer.
3 -- Individual panels are less efficient than when the panels are combined into full arrays.
4
be2f30 5 local S = technic.getter
S 6
83c649 7
S 8 minetest.register_craft({
9     output = 'technic:solar_panel',
10     recipe = {
11         {'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer'},
12         {'technic:fine_silver_wire',    'technic:lv_cable',            'mesecons_materials:glue'},
13
14     }
15 })
16
17
563a4c 18 local run = function(pos, node)
N 19     -- The action here is to make the solar panel prodice power
20     -- Power is dependent on the light level and the height above ground
21     -- There are many ways to cheat by using other light sources like lamps.
22     -- As there is no way to determine if light is sunlight that is just a shame.
23     -- To take care of some of it solar panels do not work outside daylight hours or if
24     -- built below 0m
25     local pos1 = {x=pos.x, y=pos.y+1, z=pos.z}
26     local machine_name = S("Small Solar %s Generator"):format("LV")
27
28     local light = minetest.get_node_light(pos1, nil)
29     local time_of_day = minetest.get_timeofday()
30     local meta = minetest.get_meta(pos)
31     if light == nil then light = 0 end
32     -- turn on panel only during day time and if sufficient light
33         -- I know this is counter intuitive when cheating by using other light sources underground.
34     if light >= 12 and time_of_day >= 0.24 and time_of_day <= 0.76 and pos.y > -10 then
35         local charge_to_give = math.floor((light + pos1.y) * 3)
36         charge_to_give = math.max(charge_to_give, 0)
37         charge_to_give = math.min(charge_to_give, 200)
85a984 38         meta:set_string("infotext", S("@1 Active (@2 EU)", machine_name, technic.pretty_num(charge_to_give)))
563a4c 39         meta:set_int("LV_EU_supply", charge_to_give)
N 40     else
41         meta:set_string("infotext", S("%s Idle"):format(machine_name))
42         meta:set_int("LV_EU_supply", 0)
43     end
44 end
45
ee0765 46 minetest.register_node("technic:solar_panel", {
S 47     tiles = {"technic_solar_panel_top.png",  "technic_solar_panel_bottom.png", "technic_solar_panel_side.png",
48              "technic_solar_panel_side.png", "technic_solar_panel_side.png",   "technic_solar_panel_side.png"},
83c649 49     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
S 50         technic_machine=1, technic_lv=1},
51     connect_sides = {"bottom"},
ee0765 52     sounds = default.node_sound_wood_defaults(),
7c4b70 53         description = S("Small Solar %s Generator"):format("LV"),
ee0765 54     active = false,
S 55     drawtype = "nodebox",
56     paramtype = "light",
57     is_ground_content = true,    
58     node_box = {
59         type = "fixed",
60         fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
61     },
62     on_construct = function(pos)
63         local meta = minetest.get_meta(pos)
64         meta:set_int("LV_EU_supply", 0)
7c4b70 65         meta:set_string("infotext", S("Small Solar %s Generator"):format("LV"))
ee0765 66     end,
563a4c 67     technic_run = run,
ee0765 68 })
S 69
70 technic.register_machine("LV", "technic:solar_panel", technic.producer)
71