ShadowNinja
2013-07-11 5d470cd753efe8f4640099165a7bfc0c6e181c35
commit | author | age
8e03d7 1 -- Solar panels are the building blocks of LV solar arrays
R 2 -- They can however also be used separately but with reduced efficiency due to the missing transformer.
3 -- Individual panels are 20% less efficient than when the panels are combined into full arrays.
82cba9 4 minetest.register_node("technic:solar_panel", {
R 5     tiles = {"technic_solar_panel_top.png", "technic_solar_panel_bottom.png", "technic_solar_panel_side.png",
6         "technic_solar_panel_side.png", "technic_solar_panel_side.png", "technic_solar_panel_side.png"},
7     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
8     sounds = default.node_sound_wood_defaults(),
9         description="Solar Panel",
10     active = false,
11     drawtype = "nodebox",
12     paramtype = "light",
13     is_ground_content = true,    
14     node_box = {
15             type = "fixed",
16             fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
17         },
18         selection_box = {
19             type = "fixed",
20             fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
21         },
22     on_construct = function(pos)
23         local meta = minetest.env:get_meta(pos)
ee5c6c 24         meta:set_int("technic_power_machine", 1)
K 25         meta:set_int("LV_EU_supply", 0)
26         meta:set_string("infotext", "LV Solar Panel")
82cba9 27     end,
R 28 })
29
30 minetest.register_craft({
31     output = 'technic:solar_panel 1',
32     recipe = {
33         {'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer','technic:doped_silicon_wafer'},
8e03d7 34         {'technic:doped_silicon_wafer', 'technic:lv_cable',           'technic:doped_silicon_wafer'},
82cba9 35         {'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer','technic:doped_silicon_wafer'},
R 36
37     }
38 })
39
40 minetest.register_abm(
41     {nodenames = {"technic:solar_panel"},
8e03d7 42     interval   = 1,
R 43     chance     = 1,
82cba9 44     action = function(pos, node, active_object_count, active_object_count_wider)
8e03d7 45         -- The action here is to make the solar panel prodice power
R 46         -- Power is dependent on the light level and the height above ground
47         -- 130m and above is optimal as it would be above cloud level.
48                 -- Height gives 1/4 of the effect, light 3/4. Max. effect is 26EU.
49                 -- There are many ways to cheat by using other light sources like lamps.
50                 -- As there is no way to determine if light is sunlight that is just a shame.
51                 -- To take care of some of it solar panels do not work outside daylight hours or if
52                 -- built below -10m
82cba9 53         local pos1={}
R 54         pos1.y=pos.y+1
55         pos1.x=pos.x
56         pos1.z=pos.z
57
58         local light = minetest.env:get_node_light(pos1, nil)
8e03d7 59         local time_of_day = minetest.env:get_timeofday()
82cba9 60         local meta = minetest.env:get_meta(pos)
R 61         if light == nil then light = 0 end
8e03d7 62         -- turn on panel only during day time and if sufficient light
R 63                 -- I know this is counter intuitive when cheating by using other light sources underground.
64         if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
65             local charge_to_give=math.floor(light*(light*0.0867+pos1.y/130*0.4333))
82cba9 66             if charge_to_give<0 then charge_to_give=0 end
8e03d7 67             if charge_to_give>26 then charge_to_give=26 end
R 68             meta:set_string("infotext", "Solar Panel is active ("..charge_to_give.."EU)")
ee5c6c 69             meta:set_int("LV_EU_supply", charge_to_give)
82cba9 70         else
R 71             meta:set_string("infotext", "Solar Panel is inactive");
ee5c6c 72             meta:set_int("LV_EU_supply", 0)
82cba9 73         end
R 74     end,
612349 75 }) 
R 76
ee5c6c 77 technic.register_LV_machine ("technic:solar_panel","PR")
19c9a0 78