kpoppel
2013-07-02 053fa59739f4b772174bf0a090969b3395ab3f98
commit | author | age
ee5c6c 1 -- A geothermal EU generator
K 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)
82cba9 5 minetest.register_alias("geothermal", "technic:geothermal")
R 6
7 minetest.register_craft({
8     output = 'technic:geothermal',
9     recipe = {
10         {'default:stone', 'default:stone', 'default:stone'},
cdb368 11         {'default:copper_ingot', 'default:diamond', 'default:copper_ingot'},
R 12         {'default:stone', 'default:copper_ingot', 'default:stone'},
82cba9 13     }
R 14 })
15
16 minetest.register_craftitem("technic:geothermal", {
17     description = "Geothermal Generator",
18     stack_max = 99,
19 }) 
20
ee5c6c 21 local geothermal_formspec =
82cba9 22     "invsize[8,4;]"..
R 23     "image[1,1;1,2;technic_power_meter_bg.png]"..
24     "label[0,0;Geothermal Generator]"..
25     "label[1,3;Power level]"..
26     "list[current_player;main;0,5;8,4;]"
27     
28
ee5c6c 29 minetest.register_node(
K 30    "technic:geothermal",
31    {
32       description = "Geothermal Generator",
33       tiles = {"technic_geothermal_top.png", "technic_machine_bottom.png", "technic_geothermal_side.png",
34            "technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"},
35       paramtype2 = "facedir",
36       groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
37       legacy_facedir_simple = true,
38       sounds = default.node_sound_wood_defaults(),
39       on_construct = function(pos)
40             local meta = minetest.env:get_meta(pos)
41             meta:set_string("infotext", "Geothermal Generator")
42             meta:set_float("technic_power_machine", 1)
43             meta:set_int("LV_EU_supply", 0)
44             meta:set_string("formspec", geothermal_formspec)    
45              end,    
46    })
82cba9 47
ee5c6c 48 minetest.register_node(
K 49    "technic:geothermal_active",
50    {
51       description = "Geothermal Generator",
52       tiles = {"technic_geothermal_top_active.png", "technic_machine_bottom.png", "technic_geothermal_side.png",
53            "technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"},
54       paramtype2 = "facedir",
55       groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
56       legacy_facedir_simple = true,
57       sounds = default.node_sound_wood_defaults(),
58       drop="technic:geothermal",
59    })
82cba9 60
ee5c6c 61 local check_node_around = function(pos)
K 62                  local node=minetest.env:get_node(pos)
63                  if node.name=="default:water_source" or node.name=="default:water_flowing" then return 1 end
64                  if node.name=="default:lava_source" or node.name=="default:lava_flowing" then return 2 end    
65                  return 0
66               end
82cba9 67
ee5c6c 68 minetest.register_abm(
K 69    {
70       nodenames = {"technic:geothermal","technic:geothermal_active"},
71       interval = 1,
72       chance   = 1,
73       action = function(pos, node, active_object_count, active_object_count_wider)
74           local meta             = minetest.env:get_meta(pos)
75           local water_nodes      = 0
76           local lava_nodes       = 0
77           local production_level = 0
78           local eu_supply        = 0
82cba9 79
ee5c6c 80           -- Correct positioning is water on one side and lava on the other.
K 81           -- The two cannot be adjacent because the lava the turns into obsidian or rock.
82           -- To get to 100% production stack the water and lava one extra block down as well:
83           --    WGL (W=Water, L=Lava, G=the generator, |=an LV cable)
84                   --    W|L
85           pos.x=pos.x+1
86           local check=check_node_around(pos)
87           if check==1 then water_nodes=water_nodes+1 end
88           if check==2 then lava_nodes=lava_nodes+1 end
89           pos.y=pos.y-1
90           local check=check_node_around(pos)
91           if check==1 then water_nodes=water_nodes+1 end
92           if check==2 then lava_nodes=lava_nodes+1 end
82cba9 93
ee5c6c 94           pos.x=pos.x-2
K 95           check=check_node_around(pos)
96           if check==1 then water_nodes=water_nodes+1 end
97           if check==2 then lava_nodes=lava_nodes+1 end
98           pos.y=pos.y+1
99           check=check_node_around(pos)
100           if check==1 then water_nodes=water_nodes+1 end
101           if check==2 then lava_nodes=lava_nodes+1 end
102
103           pos.x=pos.x+1
104           pos.z=pos.z+1
105           check=check_node_around(pos)
106           if check==1 then water_nodes=water_nodes+1 end
107           if check==2 then lava_nodes=lava_nodes+1 end
108           pos.y=pos.y-1
109           check=check_node_around(pos)
110           if check==1 then water_nodes=water_nodes+1 end
111           if check==2 then lava_nodes=lava_nodes+1 end
112
113           pos.z=pos.z-2
114           check=check_node_around(pos)
115           if check==1 then water_nodes=water_nodes+1 end
116           if check==2 then lava_nodes=lava_nodes+1 end
117           pos.y=pos.y+1
118           check=check_node_around(pos)
119           if check==1 then water_nodes=water_nodes+1 end
120           if check==2 then lava_nodes=lava_nodes+1 end
121
122           -- Back to (0,0,0)
123           pos.z=pos.z+1
82cba9 124     
ee5c6c 125           if water_nodes==1 and lava_nodes==1 then production_level =  25; eu_supply = 50 end
K 126           if water_nodes==2 and lava_nodes==1 then production_level =  50; eu_supply = 100 end
127           if water_nodes==1 and lava_nodes==2 then production_level =  75; eu_supply = 200 end
128           if water_nodes==2 and lava_nodes==2 then production_level = 100; eu_supply = 300 end
82cba9 129
ee5c6c 130           if production_level>0 then
K 131              meta:set_int("LV_EU_supply", eu_supply)
132           end
82cba9 133
ee5c6c 134           local load = 1 -- math.floor((charge/max_charge)*100)
K 135           meta:set_string("formspec",
136                   "invsize[8,4;]"..
137                      "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
138                      (load)..":technic_power_meter_fg.png]"..
139                   "label[0,0;Geothermal Generator]"..
140                   "label[1,3;Power level]"..
141                   "label[4,0;Production at "..tostring(production_level).."%]"
142                 )
82cba9 143                 
ee5c6c 144           if production_level>0 and minetest.env:get_node(pos).name=="technic:geothermal" then
K 145              hacky_swap_node (pos,"technic:geothermal_active")
146              return
147           end
148           if production_level==0 then
149              hacky_swap_node (pos,"technic:geothermal")
150              meta:set_int("LV_EU_supply", 0)
151           end
152            end
153    }) 
82cba9 154
ee5c6c 155 technic.register_LV_machine ("technic:geothermal","PR")
K 156 technic.register_LV_machine ("technic:geothermal_active","PR")