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 |
minetest.register_node("technic:geothermal", { |
be2f30
|
24 |
description = S("Geothermal Generator"), |
ee0765
|
25 |
tiles = {"technic_geothermal_top.png", "technic_machine_bottom.png", "technic_geothermal_side.png", |
S |
26 |
"technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"}, |
|
27 |
paramtype2 = "facedir", |
|
28 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2}, |
|
29 |
legacy_facedir_simple = true, |
|
30 |
sounds = default.node_sound_wood_defaults(), |
|
31 |
on_construct = function(pos) |
|
32 |
local meta = minetest.get_meta(pos) |
be2f30
|
33 |
meta:set_string("infotext", S("Geothermal Generator")) |
ee0765
|
34 |
meta:set_int("LV_EU_supply", 0) |
S |
35 |
end, |
|
36 |
}) |
|
37 |
|
|
38 |
minetest.register_node("technic:geothermal_active", { |
be2f30
|
39 |
description = S("Geothermal Generator"), |
ee0765
|
40 |
tiles = {"technic_geothermal_top_active.png", "technic_machine_bottom.png", "technic_geothermal_side.png", |
S |
41 |
"technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"}, |
|
42 |
paramtype2 = "facedir", |
|
43 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1}, |
|
44 |
legacy_facedir_simple = true, |
|
45 |
sounds = default.node_sound_wood_defaults(), |
|
46 |
drop = "technic:geothermal", |
|
47 |
}) |
|
48 |
|
|
49 |
local check_node_around = function(pos) |
|
50 |
local node = minetest.get_node(pos) |
|
51 |
if node.name == "default:water_source" or node.name == "default:water_flowing" then return 1 end |
|
52 |
if node.name == "default:lava_source" or node.name == "default:lava_flowing" then return 2 end |
|
53 |
return 0 |
|
54 |
end |
|
55 |
|
|
56 |
minetest.register_abm({ |
|
57 |
nodenames = {"technic:geothermal","technic:geothermal_active"}, |
|
58 |
interval = 1, |
|
59 |
chance = 1, |
|
60 |
action = function(pos, node, active_object_count, active_object_count_wider) |
|
61 |
local meta = minetest.get_meta(pos) |
|
62 |
local water_nodes = 0 |
|
63 |
local lava_nodes = 0 |
|
64 |
local production_level = 0 |
|
65 |
local eu_supply = 0 |
|
66 |
|
|
67 |
-- Correct positioning is water on one side and lava on the other. |
|
68 |
-- The two cannot be adjacent because the lava the turns into obsidian or rock. |
|
69 |
-- To get to 100% production stack the water and lava one extra block down as well: |
|
70 |
-- WGL (W=Water, L=Lava, G=the generator, |=an LV cable) |
|
71 |
-- W|L |
|
72 |
|
|
73 |
local positions = { |
|
74 |
{x=pos.x+1, y=pos.y, z=pos.z}, |
|
75 |
{x=pos.x+1, y=pos.y-1, z=pos.z}, |
|
76 |
{x=pos.x-1, y=pos.y, z=pos.z}, |
|
77 |
{x=pos.x-1, y=pos.y-1, z=pos.z}, |
|
78 |
{x=pos.x, y=pos.y, z=pos.z+1}, |
|
79 |
{x=pos.x, y=pos.y-1, z=pos.z+1}, |
|
80 |
{x=pos.x, y=pos.y, z=pos.z-1}, |
|
81 |
{x=pos.x, y=pos.y-1, z=pos.z-1}, |
|
82 |
} |
|
83 |
for _, p in pairs(positions) do |
|
84 |
local check = check_node_around(p) |
|
85 |
if check == 1 then water_nodes = water_nodes + 1 end |
|
86 |
if check == 2 then lava_nodes = lava_nodes + 1 end |
|
87 |
end |
|
88 |
|
|
89 |
if water_nodes == 1 and lava_nodes == 1 then production_level = 25; eu_supply = 50 end |
|
90 |
if water_nodes == 2 and lava_nodes == 1 then production_level = 50; eu_supply = 100 end |
|
91 |
if water_nodes == 1 and lava_nodes == 2 then production_level = 75; eu_supply = 200 end |
|
92 |
if water_nodes == 2 and lava_nodes == 2 then production_level = 100; eu_supply = 300 end |
|
93 |
|
|
94 |
if production_level > 0 then |
|
95 |
meta:set_int("LV_EU_supply", eu_supply) |
|
96 |
end |
|
97 |
|
37acdc
|
98 |
meta:set_string("infotext", |
BM |
99 |
S("Geothermal Generator").." ("..production_level.."%)") |
ee0765
|
100 |
|
S |
101 |
if production_level > 0 and minetest.get_node(pos).name == "technic:geothermal" then |
f3d8b4
|
102 |
technic.swap_node (pos, "technic:geothermal_active") |
ee0765
|
103 |
return |
S |
104 |
end |
|
105 |
if production_level == 0 then |
f3d8b4
|
106 |
technic.swap_node(pos, "technic:geothermal") |
ee0765
|
107 |
meta:set_int("LV_EU_supply", 0) |
S |
108 |
end |
|
109 |
end |
|
110 |
}) |
|
111 |
|
|
112 |
technic.register_machine("LV", "technic:geothermal", technic.producer) |
|
113 |
technic.register_machine("LV", "technic:geothermal_active", technic.producer) |
|
114 |
|