ShadowNinja
2013-10-30 be2f30a1a2f5b6c2aae7fd4cf8231aec2da0844d
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 = {
12         {'default:stone', 'default:stone',        'default:stone'},
13         {'group:wood',    'default:diamond',      'group:wood'},
14         {'default:stone', 'default:copper_ingot', 'default:stone'},
15     }
16 })
17
18 minetest.register_node("technic:water_mill", {
be2f30 19     description = S("Water Mill"),
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)
be2f30 29         meta:set_string("infotext", S("Water Mill"))
ee0765 30         meta:set_int("LV_EU_supply", 0)
S 31     end,    
32 })
33
34 minetest.register_node("technic:water_mill_active", {
be2f30 35     description = S("Water Mill"),
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",
be2f30 88             S("Water Mill").." ("..production_level.."%)")
ee0765 89
S 90         if production_level > 0 and
91            minetest.get_node(pos).name == "technic:water_mill" then
92             hacky_swap_node (pos, "technic:water_mill_active")
93             meta:set_int("LV_EU_supply", 0)
94             return
95         end
96         if production_level == 0 then
97             hacky_swap_node(pos, "technic:water_mill")
98         end
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