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