SmallJoker
2018-08-04 9b40d02fbd9e8c39c5c64cc7de89a7fe45382f04
commit | author | age
ee0765 1 -- A water mill produces LV EUs by exploiting flowing water across it
S 2 -- It is a LV EU supplyer and fairly low yield (max 120EUs)
3 -- It is a little under half as good as the thermal generator.
be2f30 4
S 5 local S = technic.getter
6
54004f 7 local cable_entry = "^technic_cable_connection_overlay.png"
VE 8
ee0765 9 minetest.register_alias("water_mill", "technic:water_mill")
S 10
11 minetest.register_craft({
12     output = 'technic:water_mill',
13     recipe = {
5e4a87 14         {'technic:marble', 'default:diamond',        'technic:marble'},
Z 15         {'group:wood',     'technic:machine_casing', 'group:wood'},
83c649 16         {'technic:marble', 'technic:lv_cable',       'technic:marble'},
ee0765 17     }
S 18 })
19
20 local function check_node_around_mill(pos)
21     local node = minetest.get_node(pos)
8cab1a 22     if node.name == "default:water_flowing"
VE 23       or node.name == "default:river_water_flowing" then
24         return node.param2 -- returns approx. water flow, if any
ee0765 25     end
S 26     return false
27 end
28
563a4c 29 local run = function(pos, node)
N 30     local meta             = minetest.get_meta(pos)
488858 31     local water_flow       = 0
563a4c 32     local lava_nodes       = 0
N 33     local production_level = 0
34     local eu_supply        = 0
fd609d 35     local max_output       = 35 * 45 -- four param2's at 15 makes 60, cap it lower for "overload protection"
488858 36                                      -- (plus we want the gen to report 100% if three sides have full flow)
ee0765 37
563a4c 38     local positions = {
N 39         {x=pos.x+1, y=pos.y, z=pos.z},
40         {x=pos.x-1, y=pos.y, z=pos.z},
41         {x=pos.x,   y=pos.y, z=pos.z+1},
42         {x=pos.x,   y=pos.y, z=pos.z-1},
43     }
ee0765 44
563a4c 45     for _, p in pairs(positions) do
N 46         local check = check_node_around_mill(p)
47         if check then
488858 48             water_flow = water_flow + check
ee0765 49         end
S 50     end
563a4c 51
fd609d 52     eu_supply = math.min(35 * water_flow, max_output)
488858 53     production_level = math.floor(100 * eu_supply / max_output)
563a4c 54
72c536 55     meta:set_int("LV_EU_supply", eu_supply)
563a4c 56
N 57     meta:set_string("infotext",
58         S("Hydro %s Generator"):format("LV").." ("..production_level.."%)")
59
60     if production_level > 0 and
61        minetest.get_node(pos).name == "technic:water_mill" then
62         technic.swap_node (pos, "technic:water_mill_active")
63         meta:set_int("LV_EU_supply", 0)
64         return
65     end
66     if production_level == 0 then
67         technic.swap_node(pos, "technic:water_mill")
68     end
69 end
70
71 minetest.register_node("technic:water_mill", {
72     description = S("Hydro %s Generator"):format("LV"),
54004f 73     tiles = {
VE 74         "technic_water_mill_top.png",
75         "technic_machine_bottom.png"..cable_entry,
76         "technic_water_mill_side.png",
77         "technic_water_mill_side.png",
78         "technic_water_mill_side.png",
79         "technic_water_mill_side.png"
80     },
563a4c 81     paramtype2 = "facedir",
83c649 82     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
S 83         technic_machine=1, technic_lv=1},
563a4c 84     legacy_facedir_simple = true,
N 85     sounds = default.node_sound_wood_defaults(),
86     on_construct = function(pos)
87         local meta = minetest.get_meta(pos)
88         meta:set_string("infotext", S("Hydro %s Generator"):format("LV"))
89         meta:set_int("LV_EU_supply", 0)
90     end,
fc87ec 91     technic_run = run,
563a4c 92 })
N 93
94 minetest.register_node("technic:water_mill_active", {
95     description = S("Hydro %s Generator"):format("LV"),
96     tiles = {"technic_water_mill_top_active.png", "technic_machine_bottom.png",
97              "technic_water_mill_side.png",       "technic_water_mill_side.png",
98              "technic_water_mill_side.png",       "technic_water_mill_side.png"},
99     paramtype2 = "facedir",
83c649 100     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
S 101         technic_machine=1, technic_lv=1, not_in_creative_inventory=1},
563a4c 102     legacy_facedir_simple = true,
N 103     sounds = default.node_sound_wood_defaults(),
104     drop = "technic:water_mill",
fc87ec 105     technic_run = run,
563a4c 106     technic_disabled_machine_name = "technic:water_mill",
N 107 })
ee0765 108
S 109 technic.register_machine("LV", "technic:water_mill",        technic.producer)
110 technic.register_machine("LV", "technic:water_mill_active", technic.producer)
111