commit | author | age
|
54529c
|
1 |
minetest.register_node("technic:solar_panel", { |
MK |
2 |
tiles = {"technic_solar_panel_top.png", "technic_solar_panel_side.png", "technic_solar_panel_side.png", |
|
3 |
"technic_solar_panel_side.png", "technic_solar_panel_side.png", "technic_solar_panel_side.png"}, |
|
4 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, |
|
5 |
sounds = default.node_sound_wood_defaults(), |
|
6 |
description="Solar Panel", |
|
7 |
active = false, |
|
8 |
technic_power_machine=1, |
|
9 |
internal_EU_buffer=0; |
|
10 |
internal_EU_buffer_size=1000; |
|
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) |
|
24 |
meta:set_float("technic_power_machine", 1) |
|
25 |
meta:set_float("internal_EU_buffer", 0) |
|
26 |
meta:set_float("internal_EU_buffer_size", 1000) |
|
27 |
|
|
28 |
meta:set_string("infotext", "Solar Panel") |
|
29 |
meta:set_float("active", false) |
|
30 |
end, |
|
31 |
}) |
|
32 |
|
|
33 |
minetest.register_craft({ |
|
34 |
output = 'technic:solar_panel 1', |
|
35 |
recipe = { |
4c9976
|
36 |
{'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer','technic:doped_silicon_wafer'}, |
MK |
37 |
{'technic:doped_silicon_wafer', 'moreores:copper_ingot','technic:doped_silicon_wafer'}, |
|
38 |
{'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer','technic:doped_silicon_wafer'}, |
54529c
|
39 |
|
MK |
40 |
} |
|
41 |
}) |
|
42 |
|
|
43 |
minetest.register_abm( |
|
44 |
{nodenames = {"technic:solar_panel"}, |
|
45 |
interval = 1, |
|
46 |
chance = 1, |
|
47 |
action = function(pos, node, active_object_count, active_object_count_wider) |
|
48 |
|
|
49 |
local pos1={} |
|
50 |
pos1.y=pos.y+1 |
|
51 |
pos1.x=pos.x |
|
52 |
pos1.z=pos.z |
|
53 |
|
|
54 |
local light = minetest.env:get_node_light(pos1, nil) |
|
55 |
local meta = minetest.env:get_meta(pos) |
|
56 |
if light == nil then light = 0 end |
|
57 |
if light >= 12 then |
|
58 |
meta:set_string("infotext", "Solar Panel is active ") |
|
59 |
meta:set_float("active",1) |
|
60 |
local internal_EU_buffer=meta:get_float("internal_EU_buffer") |
|
61 |
local internal_EU_buffer_size=meta:get_float("internal_EU_buffer_size") |
f845d9
|
62 |
local charge_to_give=40+(pos1.y/250*40) -- make solar energy depending on height |
MK |
63 |
if charge_to_give<0 then charge_to_give=0 end |
|
64 |
if charge_to_give>160 then charge_to_give=160 end |
54529c
|
65 |
if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then |
MK |
66 |
charge_to_give=internal_EU_buffer_size-internal_EU_buffer |
|
67 |
end |
|
68 |
internal_EU_buffer=internal_EU_buffer+charge_to_give |
|
69 |
meta:set_float("internal_EU_buffer",internal_EU_buffer) |
|
70 |
|
|
71 |
else |
|
72 |
meta:set_string("infotext", "Solar Panel is inactive"); |
|
73 |
meta:set_float("active",0) |
|
74 |
end |
|
75 |
end, |
|
76 |
}) |