commit | author | age
|
ee0765
|
1 |
|
be2f30
|
2 |
local S = technic.getter |
S |
3 |
|
ee0765
|
4 |
function technic.register_solar_array(data) |
S |
5 |
local tier = data.tier |
|
6 |
local ltier = string.lower(tier) |
be2f30
|
7 |
|
563a4c
|
8 |
local run = function(pos, node) |
N |
9 |
-- The action here is to make the solar array produce power |
|
10 |
-- Power is dependent on the light level and the height above ground |
|
11 |
-- There are many ways to cheat by using other light sources like lamps. |
|
12 |
-- As there is no way to determine if light is sunlight that is just a shame. |
|
13 |
-- To take care of some of it solar panels do not work outside daylight hours or if |
|
14 |
-- built below 0m |
|
15 |
local pos1 = {} |
|
16 |
local machine_name = S("Arrayed Solar %s Generator"):format(tier) |
|
17 |
pos1.y = pos.y + 1 |
|
18 |
pos1.x = pos.x |
|
19 |
pos1.z = pos.z |
161568
|
20 |
|
E |
21 |
technic.get_or_load_node(pos1) |
563a4c
|
22 |
local light = minetest.get_node_light(pos1, nil) |
N |
23 |
local time_of_day = minetest.get_timeofday() |
|
24 |
local meta = minetest.get_meta(pos) |
|
25 |
light = light or 0 |
|
26 |
|
|
27 |
-- turn on array only during day time and if sufficient light |
|
28 |
-- I know this is counter intuitive when cheating by using other light sources. |
|
29 |
if light >= 12 and time_of_day >= 0.24 and time_of_day <= 0.76 and pos.y > 0 then |
|
30 |
local charge_to_give = math.floor((light + pos.y) * data.power) |
|
31 |
charge_to_give = math.max(charge_to_give, 0) |
|
32 |
charge_to_give = math.min(charge_to_give, data.power * 50) |
41f175
|
33 |
meta:set_string("infotext", S("@1 Active (@2)", machine_name, |
H |
34 |
technic.EU_string(charge_to_give))) |
563a4c
|
35 |
meta:set_int(tier.."_EU_supply", charge_to_give) |
N |
36 |
else |
|
37 |
meta:set_string("infotext", S("%s Idle"):format(machine_name)) |
|
38 |
meta:set_int(tier.."_EU_supply", 0) |
|
39 |
end |
|
40 |
end |
41f175
|
41 |
|
ee0765
|
42 |
minetest.register_node("technic:solar_array_"..ltier, { |
S |
43 |
tiles = {"technic_"..ltier.."_solar_array_top.png", "technic_"..ltier.."_solar_array_bottom.png", |
|
44 |
"technic_"..ltier.."_solar_array_side.png", "technic_"..ltier.."_solar_array_side.png", |
|
45 |
"technic_"..ltier.."_solar_array_side.png", "technic_"..ltier.."_solar_array_side.png"}, |
83c649
|
46 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1, ["technic_"..ltier]=1}, |
S |
47 |
connect_sides = {"bottom"}, |
ee0765
|
48 |
sounds = default.node_sound_wood_defaults(), |
7c4b70
|
49 |
description = S("Arrayed Solar %s Generator"):format(tier), |
ee0765
|
50 |
active = false, |
S |
51 |
drawtype = "nodebox", |
|
52 |
paramtype = "light", |
|
53 |
node_box = { |
|
54 |
type = "fixed", |
|
55 |
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, |
|
56 |
}, |
|
57 |
on_construct = function(pos) |
|
58 |
local meta = minetest.get_meta(pos) |
|
59 |
meta:set_int(tier.."_EU_supply", 0) |
|
60 |
end, |
563a4c
|
61 |
technic_run = run, |
ee0765
|
62 |
}) |
S |
63 |
|
|
64 |
technic.register_machine(tier, "technic:solar_array_"..ltier, technic.producer) |
|
65 |
end |
|
66 |
|