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