Tim
2015-01-18 00f61dfb81100094b64de06ca4e1ef73ef8bcd47
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
ee0765 7 minetest.register_alias("water_mill", "technic:water_mill")
S 8
9 minetest.register_craft({
10     output = 'technic:water_mill',
11     recipe = {
5e4a87 12         {'technic:marble', 'default:diamond',        'technic:marble'},
Z 13         {'group:wood',     'technic:machine_casing', 'group:wood'},
14         {'technic:marble', 'technic:lv_cable0',      'technic:marble'},
ee0765 15     }
S 16 })
17
18 local function check_node_around_mill(pos)
19     local node = minetest.get_node(pos)
20     if node.name == "default:water_flowing" or
21        node.name == "default:water_source" then
22         return true
23     end
24     return false
25 end
26
563a4c 27 local run = function(pos, node)
N 28     local meta             = minetest.get_meta(pos)
29     local water_nodes      = 0
30     local lava_nodes       = 0
31     local production_level = 0
32     local eu_supply        = 0
ee0765 33
563a4c 34     local positions = {
N 35         {x=pos.x+1, y=pos.y, z=pos.z},
36         {x=pos.x-1, y=pos.y, z=pos.z},
37         {x=pos.x,   y=pos.y, z=pos.z+1},
38         {x=pos.x,   y=pos.y, z=pos.z-1},
39     }
ee0765 40
563a4c 41     for _, p in pairs(positions) do
N 42         local check = check_node_around_mill(p)
43         if check then
44             water_nodes = water_nodes + 1
ee0765 45         end
S 46     end
563a4c 47
N 48     production_level = 25 * water_nodes
49     eu_supply = 30 * water_nodes
50
51     if production_level > 0 then
52         meta:set_int("LV_EU_supply", eu_supply)
53     end
54
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"),
71     tiles = {"technic_water_mill_top.png",  "technic_machine_bottom.png",
72              "technic_water_mill_side.png", "technic_water_mill_side.png",
73              "technic_water_mill_side.png", "technic_water_mill_side.png"},
74     paramtype2 = "facedir",
75     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1},
76     legacy_facedir_simple = true,
77     sounds = default.node_sound_wood_defaults(),
78     on_construct = function(pos)
79         local meta = minetest.get_meta(pos)
80         meta:set_string("infotext", S("Hydro %s Generator"):format("LV"))
81         meta:set_int("LV_EU_supply", 0)
82     end,
fc87ec 83     technic_run = run,
563a4c 84 })
N 85
86 minetest.register_node("technic:water_mill_active", {
87     description = S("Hydro %s Generator"):format("LV"),
88     tiles = {"technic_water_mill_top_active.png", "technic_machine_bottom.png",
89              "technic_water_mill_side.png",       "technic_water_mill_side.png",
90              "technic_water_mill_side.png",       "technic_water_mill_side.png"},
91     paramtype2 = "facedir",
92     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1, not_in_creative_inventory=1},
93     legacy_facedir_simple = true,
94     sounds = default.node_sound_wood_defaults(),
95     drop = "technic:water_mill",
fc87ec 96     technic_run = run,
563a4c 97     technic_disabled_machine_name = "technic:water_mill",
N 98 })
ee0765 99
S 100 technic.register_machine("LV", "technic:water_mill",        technic.producer)
101 technic.register_machine("LV", "technic:water_mill_active", technic.producer)
102