Zefram
2014-07-07 5e4a87b92599aa0fc9a56081209c930d08a2c3bd
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 minetest.register_node("technic:water_mill", {
7c4b70 19     description = S("Hydro %s Generator"):format("LV"),
ee0765 20     tiles = {"technic_water_mill_top.png",  "technic_machine_bottom.png",
S 21              "technic_water_mill_side.png", "technic_water_mill_side.png",
22              "technic_water_mill_side.png", "technic_water_mill_side.png"},
23     paramtype2 = "facedir",
24     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
25     legacy_facedir_simple = true,
26     sounds = default.node_sound_wood_defaults(),
27     on_construct = function(pos)
28         local meta = minetest.get_meta(pos)
7c4b70 29         meta:set_string("infotext", S("Hydro %s Generator"):format("LV"))
ee0765 30         meta:set_int("LV_EU_supply", 0)
S 31     end,    
32 })
33
34 minetest.register_node("technic:water_mill_active", {
7c4b70 35     description = S("Hydro %s Generator"):format("LV"),
ee0765 36     tiles = {"technic_water_mill_top_active.png", "technic_machine_bottom.png",
S 37              "technic_water_mill_side.png",       "technic_water_mill_side.png",
38              "technic_water_mill_side.png",       "technic_water_mill_side.png"},
39     paramtype2 = "facedir",
40     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
41     legacy_facedir_simple = true,
42     sounds = default.node_sound_wood_defaults(),
43     drop = "technic:water_mill",
44 })
45
46 local function check_node_around_mill(pos)
47     local node = minetest.get_node(pos)
48     if node.name == "default:water_flowing" or
49        node.name == "default:water_source" then
50         return true
51     end
52     return false
53 end
54
55 minetest.register_abm({
56     nodenames = {"technic:water_mill", "technic:water_mill_active"},
57     interval = 1,
58     chance   = 1,
59     action = function(pos, node, active_object_count, active_object_count_wider)
60         local meta             = minetest.get_meta(pos)
61         local water_nodes      = 0
62         local lava_nodes       = 0
63         local production_level = 0
64         local eu_supply        = 0
65
66         local positions = {
67             {x=pos.x+1, y=pos.y, z=pos.z},
68             {x=pos.x-1, y=pos.y, z=pos.z},
69             {x=pos.x,   y=pos.y, z=pos.z+1},
70             {x=pos.x,   y=pos.y, z=pos.z-1},
71         }
72
73         for _, p in pairs(positions) do
74             local check = check_node_around_mill(p)
75             if check then
76                 water_nodes = water_nodes + 1
77             end
78         end
79
80         production_level = 25 * water_nodes
81         eu_supply = 30 * water_nodes
82
83         if production_level > 0 then
84             meta:set_int("LV_EU_supply", eu_supply)
85         end
86
87         meta:set_string("infotext",
7c4b70 88             S("Hydro %s Generator"):format("LV").." ("..production_level.."%)")
ee0765 89
S 90         if production_level > 0 and
91            minetest.get_node(pos).name == "technic:water_mill" then
f3d8b4 92             technic.swap_node (pos, "technic:water_mill_active")
ee0765 93             meta:set_int("LV_EU_supply", 0)
S 94             return
95         end
96         if production_level == 0 then
f3d8b4 97             technic.swap_node(pos, "technic:water_mill")
ee0765 98         end
S 99     end
100 }) 
101
102 technic.register_machine("LV", "technic:water_mill",        technic.producer)
103 technic.register_machine("LV", "technic:water_mill_active", technic.producer)
104