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