commit | author | age
|
2e7859
|
1 |
-- A Hydro Turbine produces MV EUs by exploiting flowing water across it |
5f6b87
|
2 |
-- It is a MV EU supplier and fairly high yield (max 1800EUs) |
2e7859
|
3 |
|
TM |
4 |
local S = technic.getter |
|
5 |
|
|
6 |
local cable_entry = "^technic_cable_connection_overlay.png" |
|
7 |
|
|
8 |
minetest.register_alias("hydro_turbine", "technic:hydro_turbine") |
|
9 |
|
|
10 |
minetest.register_craft({ |
|
11 |
output = 'technic:hydro_turbine', |
|
12 |
recipe = { |
|
13 |
{'technic:stainless_steel_ingot', 'technic:water_mill', 'technic:stainless_steel_ingot'}, |
|
14 |
{'technic:water_mill', 'technic:mv_transformer', 'technic:water_mill'}, |
|
15 |
{'technic:stainless_steel_ingot', 'technic:mv_cable', 'technic:stainless_steel_ingot'}, |
|
16 |
} |
|
17 |
}) |
|
18 |
|
|
19 |
local function get_water_flow(pos) |
|
20 |
local node = minetest.get_node(pos) |
8ebc1d
|
21 |
if minetest.get_item_group(node.name, "water") == 3 and string.find(node.name, "flowing") then |
2e7859
|
22 |
return node.param2 -- returns approx. water flow, if any |
TM |
23 |
end |
|
24 |
return 0 |
|
25 |
end |
|
26 |
|
|
27 |
--- |
4f78a6
|
28 |
-- 10 times better than LV hydro because of 2 extra water mills and 4 stainless steel, a transformer and whatnot ;P. |
2e7859
|
29 |
-- Man hydro turbines are tough and long lasting. So, give it some value :) |
TM |
30 |
local run = function(pos, node) |
|
31 |
local meta = minetest.get_meta(pos) |
|
32 |
local water_flow = 0 |
a8daa4
|
33 |
local production_level |
DL |
34 |
local eu_supply |
2e7859
|
35 |
local max_output = 40 * 45 -- Generates 1800EU/s |
TM |
36 |
|
|
37 |
local positions = { |
|
38 |
{x=pos.x+1, y=pos.y, z=pos.z}, |
|
39 |
{x=pos.x-1, y=pos.y, z=pos.z}, |
|
40 |
{x=pos.x, y=pos.y, z=pos.z+1}, |
|
41 |
{x=pos.x, y=pos.y, z=pos.z-1}, |
|
42 |
} |
|
43 |
|
|
44 |
for _, p in pairs(positions) do |
|
45 |
water_flow = water_flow + get_water_flow(p) |
|
46 |
end |
|
47 |
|
|
48 |
eu_supply = math.min(40 * water_flow, max_output) |
|
49 |
production_level = math.floor(100 * eu_supply / max_output) |
|
50 |
|
|
51 |
meta:set_int("MV_EU_supply", eu_supply) |
|
52 |
|
|
53 |
meta:set_string("infotext", |
|
54 |
S("Hydro %s Generator"):format("MV").." ("..production_level.."%)") |
|
55 |
if production_level > 0 and |
|
56 |
minetest.get_node(pos).name == "technic:hydro_turbine" then |
|
57 |
technic.swap_node(pos, "technic:hydro_turbine_active") |
|
58 |
meta:set_int("MV_EU_supply", 0) |
|
59 |
return |
|
60 |
end |
|
61 |
if production_level == 0 then |
|
62 |
technic.swap_node(pos, "technic:hydro_turbine") |
|
63 |
end |
|
64 |
end |
|
65 |
|
|
66 |
minetest.register_node("technic:hydro_turbine", { |
|
67 |
description = S("Hydro %s Generator"):format("MV"), |
|
68 |
tiles = { |
|
69 |
"technic_hydro_turbine_top.png", |
|
70 |
"technic_machine_bottom.png"..cable_entry, |
|
71 |
"technic_hydro_turbine_side.png", |
|
72 |
"technic_hydro_turbine_side.png", |
|
73 |
"technic_hydro_turbine_side.png", |
|
74 |
"technic_hydro_turbine_side.png" |
|
75 |
}, |
|
76 |
paramtype2 = "facedir", |
|
77 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, |
|
78 |
technic_machine=1, technic_mv=1}, |
|
79 |
legacy_facedir_simple = true, |
|
80 |
sounds = default.node_sound_wood_defaults(), |
|
81 |
on_construct = function(pos) |
|
82 |
local meta = minetest.get_meta(pos) |
|
83 |
meta:set_string("infotext", S("Hydro %s Generator"):format("MV")) |
|
84 |
meta:set_int("MV_EU_supply", 0) |
|
85 |
end, |
|
86 |
technic_run = run, |
|
87 |
}) |
|
88 |
|
|
89 |
minetest.register_node("technic:hydro_turbine_active", { |
|
90 |
description = S("Hydro %s Generator"):format("MV"), |
|
91 |
tiles = {"technic_hydro_turbine_top_active.png", "technic_machine_bottom.png", |
|
92 |
"technic_hydro_turbine_side.png", "technic_hydro_turbine_side.png", |
|
93 |
"technic_hydro_turbine_side.png", "technic_hydro_turbine_side.png"}, |
|
94 |
paramtype2 = "facedir", |
|
95 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, |
|
96 |
technic_machine=1, technic_mv=1, not_in_creative_inventory=1}, |
|
97 |
legacy_facedir_simple = true, |
|
98 |
sounds = default.node_sound_wood_defaults(), |
|
99 |
drop = "technic:hydro_turbine", |
|
100 |
technic_run = run, |
|
101 |
technic_disabled_machine_name = "technic:hydro_turbine", |
|
102 |
}) |
|
103 |
|
|
104 |
technic.register_machine("MV", "technic:hydro_turbine", technic.producer) |
|
105 |
technic.register_machine("MV", "technic:hydro_turbine_active", technic.producer) |