ShadowNinja
2013-10-30 be2f30a1a2f5b6c2aae7fd4cf8231aec2da0844d
commit | author | age
ee0765 1 -- A geothermal EU generator
S 2 -- Using hot lava and water this device can create energy from steam
3 -- The machine is only producing LV EUs and can thus not drive more advanced equipment
4 -- The output is a little more than the coal burning generator (max 300EUs)
5
6 minetest.register_alias("geothermal", "technic:geothermal")
7
be2f30 8 local S = technic.getter
S 9
ee0765 10 minetest.register_craft({
S 11     output = 'technic:geothermal',
12     recipe = {
13         {'default:stone', 'default:stone', 'default:stone'},
14         {'default:copper_ingot', 'default:diamond', 'default:copper_ingot'},
15         {'default:stone', 'default:copper_ingot', 'default:stone'},
16     }
17 })
18
19 minetest.register_craftitem("technic:geothermal", {
be2f30 20     description = S("Geothermal Generator"),
ee0765 21 }) 
S 22
23 local geothermal_formspec =
24     "invsize[8,4;]"..
be2f30 25     "label[0,0;"..S("Geothermal Generator").."]"..
ee0765 26     "list[current_player;main;0,5;8,4;]"
S 27     
28
29 minetest.register_node("technic:geothermal", {
be2f30 30     description = S("Geothermal Generator"),
ee0765 31     tiles = {"technic_geothermal_top.png", "technic_machine_bottom.png", "technic_geothermal_side.png",
S 32              "technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"},
33     paramtype2 = "facedir",
34     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
35     legacy_facedir_simple = true,
36     sounds = default.node_sound_wood_defaults(),
37     on_construct = function(pos)
38         local meta = minetest.get_meta(pos)
be2f30 39         meta:set_string("infotext", S("Geothermal Generator"))
ee0765 40         meta:set_int("LV_EU_supply", 0)
S 41         meta:set_string("formspec", geothermal_formspec)    
42     end,    
43 })
44
45 minetest.register_node("technic:geothermal_active", {
be2f30 46     description = S("Geothermal Generator"),
ee0765 47     tiles = {"technic_geothermal_top_active.png", "technic_machine_bottom.png", "technic_geothermal_side.png",
S 48              "technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"},
49     paramtype2 = "facedir",
50     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
51     legacy_facedir_simple = true,
52     sounds = default.node_sound_wood_defaults(),
53     drop = "technic:geothermal",
54 })
55
56 local check_node_around = function(pos)
57     local node = minetest.get_node(pos)
58     if node.name == "default:water_source" or node.name == "default:water_flowing" then return 1 end
59     if node.name == "default:lava_source"  or node.name == "default:lava_flowing"  then return 2 end    
60     return 0
61 end
62
63 minetest.register_abm({
64     nodenames = {"technic:geothermal","technic:geothermal_active"},
65     interval = 1,
66     chance   = 1,
67     action = function(pos, node, active_object_count, active_object_count_wider)
68         local meta             = minetest.get_meta(pos)
69         local water_nodes      = 0
70         local lava_nodes       = 0
71         local production_level = 0
72         local eu_supply        = 0
73
74         -- Correct positioning is water on one side and lava on the other.
75         -- The two cannot be adjacent because the lava the turns into obsidian or rock.
76         -- To get to 100% production stack the water and lava one extra block down as well:
77         --    WGL (W=Water, L=Lava, G=the generator, |=an LV cable)
78         --    W|L
79
80         local positions = {
81             {x=pos.x+1, y=pos.y,   z=pos.z},
82             {x=pos.x+1, y=pos.y-1, z=pos.z},
83             {x=pos.x-1, y=pos.y,   z=pos.z},
84             {x=pos.x-1, y=pos.y-1, z=pos.z},
85             {x=pos.x,   y=pos.y,   z=pos.z+1},
86             {x=pos.x,   y=pos.y-1, z=pos.z+1},
87             {x=pos.x,   y=pos.y,   z=pos.z-1},
88             {x=pos.x,   y=pos.y-1, z=pos.z-1},
89         }
90         for _, p in pairs(positions) do
91             local check = check_node_around(p)
92             if check == 1 then water_nodes = water_nodes + 1 end
93             if check == 2 then lava_nodes  = lava_nodes  + 1 end
94         end
95
96         if water_nodes == 1 and lava_nodes == 1 then production_level =  25; eu_supply = 50 end
97         if water_nodes == 2 and lava_nodes == 1 then production_level =  50; eu_supply = 100 end
98         if water_nodes == 1 and lava_nodes == 2 then production_level =  75; eu_supply = 200 end
99         if water_nodes == 2 and lava_nodes == 2 then production_level = 100; eu_supply = 300 end
100
101         if production_level > 0 then
102             meta:set_int("LV_EU_supply", eu_supply)
103         end
104
105         meta:set_string("formspec",
106             "invsize[8,4;]"..
be2f30 107             "label[0,0;"..S("Geothermal Generator").."]"..
S 108             "label[4,0;"..S("Production at %d%%"):format(production_level).."]")
ee0765 109
S 110         if production_level > 0 and minetest.get_node(pos).name == "technic:geothermal" then
111             hacky_swap_node (pos, "technic:geothermal_active")
112             return
113         end
114         if production_level == 0 then
115             hacky_swap_node(pos, "technic:geothermal")
116             meta:set_int("LV_EU_supply", 0)
117         end
118     end
119 }) 
120
121 technic.register_machine("LV", "technic:geothermal",        technic.producer)
122 technic.register_machine("LV", "technic:geothermal_active", technic.producer)
123