ShadowNinja
2013-10-06 363f0332788e04e2e4bb63af5cd21fac5ae56ae5
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.
4 minetest.register_alias("water_mill", "technic:water_mill")
5
6 minetest.register_craft({
7     output = 'technic:water_mill',
8     recipe = {
9         {'default:stone', 'default:stone',        'default:stone'},
10         {'group:wood',    'default:diamond',      'group:wood'},
11         {'default:stone', 'default:copper_ingot', 'default:stone'},
12     }
13 })
14
15 minetest.register_node("technic:water_mill", {
16     description = "Water Mill",
17     tiles = {"technic_water_mill_top.png",  "technic_machine_bottom.png",
18              "technic_water_mill_side.png", "technic_water_mill_side.png",
19              "technic_water_mill_side.png", "technic_water_mill_side.png"},
20     paramtype2 = "facedir",
21     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
22     legacy_facedir_simple = true,
23     sounds = default.node_sound_wood_defaults(),
24     on_construct = function(pos)
25         local meta = minetest.get_meta(pos)
26         meta:set_string("infotext", "Water Mill")
27         meta:set_int("LV_EU_supply", 0)
28     end,    
29 })
30
31 minetest.register_node("technic:water_mill_active", {
32     description = "Water Mill",
33     tiles = {"technic_water_mill_top_active.png", "technic_machine_bottom.png",
34              "technic_water_mill_side.png",       "technic_water_mill_side.png",
35              "technic_water_mill_side.png",       "technic_water_mill_side.png"},
36     paramtype2 = "facedir",
37     groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
38     legacy_facedir_simple = true,
39     sounds = default.node_sound_wood_defaults(),
40     drop = "technic:water_mill",
41 })
42
43 local function check_node_around_mill(pos)
44     local node = minetest.get_node(pos)
45     if node.name == "default:water_flowing" or
46        node.name == "default:water_source" then
47         return true
48     end
49     return false
50 end
51
52 minetest.register_abm({
53     nodenames = {"technic:water_mill", "technic:water_mill_active"},
54     interval = 1,
55     chance   = 1,
56     action = function(pos, node, active_object_count, active_object_count_wider)
57         local meta             = minetest.get_meta(pos)
58         local water_nodes      = 0
59         local lava_nodes       = 0
60         local production_level = 0
61         local eu_supply        = 0
62
63         local positions = {
64             {x=pos.x+1, y=pos.y, z=pos.z},
65             {x=pos.x-1, y=pos.y, z=pos.z},
66             {x=pos.x,   y=pos.y, z=pos.z+1},
67             {x=pos.x,   y=pos.y, z=pos.z-1},
68         }
69
70         for _, p in pairs(positions) do
71             local check = check_node_around_mill(p)
72             if check then
73                 water_nodes = water_nodes + 1
74             end
75         end
76
77         production_level = 25 * water_nodes
78         eu_supply = 30 * water_nodes
79
80         if production_level > 0 then
81             meta:set_int("LV_EU_supply", eu_supply)
82         end
83
84         meta:set_string("infotext",
85             "Water Mill ("..production_level.."%)")
86
87         if production_level > 0 and
88            minetest.get_node(pos).name == "technic:water_mill" then
89             hacky_swap_node (pos, "technic:water_mill_active")
90             meta:set_int("LV_EU_supply", 0)
91             return
92         end
93         if production_level == 0 then
94             hacky_swap_node(pos, "technic:water_mill")
95         end
96     end
97 }) 
98
99 technic.register_machine("LV", "technic:water_mill",        technic.producer)
100 technic.register_machine("LV", "technic:water_mill_active", technic.producer)
101