RealBadAngel
2013-02-01 061e6bbadc89a4e4be2818a691436f8144327cf1
commit | author | age
82cba9 1 minetest.register_node("technic:solar_panel_mv", {
R 2     tiles = {"technic_mv_solar_panel_top.png", "technic_mv_solar_panel_bottom.png", "technic_mv_solar_panel_side.png",
3         "technic_mv_solar_panel_side.png", "technic_mv_solar_panel_side.png", "technic_mv_solar_panel_side.png"},
4     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
5     sounds = default.node_sound_wood_defaults(),
6         description="MV Solar Panel",
7     active = false,
8     technic_mv_power_machine=1,
9     internal_EU_buffer=0;
10     internal_EU_buffer_size=10000;
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_mv_power_machine", 1)
25         meta:set_float("internal_EU_buffer", 0)
26         meta:set_float("internal_EU_buffer_size", 10000)
27
28         meta:set_string("infotext", "MV Solar Panel")
29         meta:set_float("active", false)
30     end,
31 })
32
33 minetest.register_craft({
34     output = 'technic:solar_panel_mv 1',
35     recipe = {
36         {'technic:solar_panel', 'technic:solar_panel','technic:solar_panel'},
37         {'technic:solar_panel', 'technic:mv_transformer','technic:solar_panel'},
38         {'', 'technic:mv_cable',''},
39
40     }
41 })
42
43 minetest.register_abm(
44     {nodenames = {"technic:solar_panel_mv"},
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 >= 14 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")
62             local charge_to_give=300+(pos1.y/250*300) -- make solar energy depending on height
63             if charge_to_give<0 then charge_to_give=0 end
64             if charge_to_give>600 then charge_to_give=600 end
65             if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
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 })