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 |
technic_power_machine=1, |
|
12 |
internal_EU_buffer=0; |
8e03d7
|
13 |
internal_EU_buffer_size=160; |
82cba9
|
14 |
drawtype = "nodebox", |
R |
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 |
selection_box = { |
|
22 |
type = "fixed", |
|
23 |
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, |
|
24 |
}, |
|
25 |
on_construct = function(pos) |
|
26 |
local meta = minetest.env:get_meta(pos) |
|
27 |
meta:set_float("technic_power_machine", 1) |
|
28 |
meta:set_float("internal_EU_buffer", 0) |
8e03d7
|
29 |
meta:set_float("internal_EU_buffer_size", 160) |
82cba9
|
30 |
|
R |
31 |
meta:set_string("infotext", "Solar Panel") |
|
32 |
meta:set_float("active", false) |
|
33 |
end, |
|
34 |
}) |
|
35 |
|
|
36 |
minetest.register_craft({ |
|
37 |
output = 'technic:solar_panel 1', |
|
38 |
recipe = { |
|
39 |
{'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer','technic:doped_silicon_wafer'}, |
8e03d7
|
40 |
{'technic:doped_silicon_wafer', 'technic:lv_cable', 'technic:doped_silicon_wafer'}, |
82cba9
|
41 |
{'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer','technic:doped_silicon_wafer'}, |
R |
42 |
|
|
43 |
} |
|
44 |
}) |
|
45 |
|
|
46 |
minetest.register_abm( |
|
47 |
{nodenames = {"technic:solar_panel"}, |
8e03d7
|
48 |
interval = 1, |
R |
49 |
chance = 1, |
82cba9
|
50 |
action = function(pos, node, active_object_count, active_object_count_wider) |
8e03d7
|
51 |
-- The action here is to make the solar panel prodice power |
R |
52 |
-- Power is dependent on the light level and the height above ground |
|
53 |
-- 130m and above is optimal as it would be above cloud level. |
|
54 |
-- Height gives 1/4 of the effect, light 3/4. Max. effect is 26EU. |
|
55 |
-- There are many ways to cheat by using other light sources like lamps. |
|
56 |
-- As there is no way to determine if light is sunlight that is just a shame. |
|
57 |
-- To take care of some of it solar panels do not work outside daylight hours or if |
|
58 |
-- built below -10m |
82cba9
|
59 |
local pos1={} |
R |
60 |
pos1.y=pos.y+1 |
|
61 |
pos1.x=pos.x |
|
62 |
pos1.z=pos.z |
|
63 |
|
|
64 |
local light = minetest.env:get_node_light(pos1, nil) |
8e03d7
|
65 |
local time_of_day = minetest.env:get_timeofday() |
82cba9
|
66 |
local meta = minetest.env:get_meta(pos) |
R |
67 |
if light == nil then light = 0 end |
8e03d7
|
68 |
-- turn on panel only during day time and if sufficient light |
R |
69 |
-- I know this is counter intuitive when cheating by using other light sources underground. |
|
70 |
if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then |
82cba9
|
71 |
local internal_EU_buffer=meta:get_float("internal_EU_buffer") |
R |
72 |
local internal_EU_buffer_size=meta:get_float("internal_EU_buffer_size") |
8e03d7
|
73 |
local charge_to_give=math.floor(light*(light*0.0867+pos1.y/130*0.4333)) |
82cba9
|
74 |
if charge_to_give<0 then charge_to_give=0 end |
8e03d7
|
75 |
if charge_to_give>26 then charge_to_give=26 end |
82cba9
|
76 |
if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then |
8e03d7
|
77 |
charge_to_give=internal_EU_buffer_size-internal_EU_buffer |
82cba9
|
78 |
end |
8e03d7
|
79 |
meta:set_string("infotext", "Solar Panel is active ("..charge_to_give.."EU)") |
R |
80 |
meta:set_float("active",1) |
82cba9
|
81 |
internal_EU_buffer=internal_EU_buffer+charge_to_give |
R |
82 |
meta:set_float("internal_EU_buffer",internal_EU_buffer) |
|
83 |
|
|
84 |
else |
|
85 |
meta:set_string("infotext", "Solar Panel is inactive"); |
|
86 |
meta:set_float("active",0) |
|
87 |
end |
|
88 |
end, |
612349
|
89 |
}) |
R |
90 |
|
|
91 |
register_LV_machine ("technic:solar_panel","PR") |