coil
2019-08-26 d119a6748264a4f9825eebdd4ddeb2421cc4784a
commit | author | age
ee0765 1 -- A water mill produces LV EUs by exploiting flowing water across it
5f6b87 2 -- It is a LV EU supplier and fairly low yield (max 180EUs)
2e7859 3 -- It is a little over 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 production_level = 0
N 33     local eu_supply        = 0
2e7859 34     local max_output       = 4 * 45 -- keeping it around 180, little more than previous 150 :)
ee0765 35
563a4c 36     local positions = {
N 37         {x=pos.x+1, y=pos.y, z=pos.z},
38         {x=pos.x-1, y=pos.y, z=pos.z},
39         {x=pos.x,   y=pos.y, z=pos.z+1},
40         {x=pos.x,   y=pos.y, z=pos.z-1},
41     }
ee0765 42
563a4c 43     for _, p in pairs(positions) do
N 44         local check = check_node_around_mill(p)
45         if check then
488858 46             water_flow = water_flow + check
ee0765 47         end
S 48     end
563a4c 49
2e7859 50     eu_supply = math.min(4 * water_flow, max_output)
488858 51     production_level = math.floor(100 * eu_supply / max_output)
563a4c 52
72c536 53     meta:set_int("LV_EU_supply", eu_supply)
563a4c 54
N 55     meta:set_string("infotext",
56         S("Hydro %s Generator"):format("LV").." ("..production_level.."%)")
57
58     if production_level > 0 and
59        minetest.get_node(pos).name == "technic:water_mill" then
60         technic.swap_node (pos, "technic:water_mill_active")
61         meta:set_int("LV_EU_supply", 0)
62         return
63     end
64     if production_level == 0 then
65         technic.swap_node(pos, "technic:water_mill")
66     end
67 end
68
69 minetest.register_node("technic:water_mill", {
70     description = S("Hydro %s Generator"):format("LV"),
54004f 71     tiles = {
VE 72         "technic_water_mill_top.png",
73         "technic_machine_bottom.png"..cable_entry,
74         "technic_water_mill_side.png",
75         "technic_water_mill_side.png",
76         "technic_water_mill_side.png",
77         "technic_water_mill_side.png"
78     },
563a4c 79     paramtype2 = "facedir",
83c649 80     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
S 81         technic_machine=1, technic_lv=1},
563a4c 82     legacy_facedir_simple = true,
N 83     sounds = default.node_sound_wood_defaults(),
84     on_construct = function(pos)
85         local meta = minetest.get_meta(pos)
86         meta:set_string("infotext", S("Hydro %s Generator"):format("LV"))
87         meta:set_int("LV_EU_supply", 0)
88     end,
fc87ec 89     technic_run = run,
563a4c 90 })
N 91
92 minetest.register_node("technic:water_mill_active", {
93     description = S("Hydro %s Generator"):format("LV"),
94     tiles = {"technic_water_mill_top_active.png", "technic_machine_bottom.png",
95              "technic_water_mill_side.png",       "technic_water_mill_side.png",
96              "technic_water_mill_side.png",       "technic_water_mill_side.png"},
97     paramtype2 = "facedir",
83c649 98     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
S 99         technic_machine=1, technic_lv=1, not_in_creative_inventory=1},
563a4c 100     legacy_facedir_simple = true,
N 101     sounds = default.node_sound_wood_defaults(),
102     drop = "technic:water_mill",
fc87ec 103     technic_run = run,
563a4c 104     technic_disabled_machine_name = "technic:water_mill",
N 105 })
ee0765 106
S 107 technic.register_machine("LV", "technic:water_mill",        technic.producer)
108 technic.register_machine("LV", "technic:water_mill_active", technic.producer)
109