kpoppel
2013-07-02 053fa59739f4b772174bf0a090969b3395ab3f98
commit | author | age
ee5c6c 1 -- A water mill produces LV EUs by exploiting flowing water across it
K 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.
82cba9 4 minetest.register_alias("water_mill", "technic:water_mill")
R 5
6 minetest.register_craft({
7     output = 'technic:water_mill',
8     recipe = {
9         {'default:stone', 'default:stone', 'default:stone'},
e139ff 10         {'default:wood', 'default:diamond', 'default:wood'},
82cba9 11         {'default:stone', 'moreores:copper_ingot', 'default:stone'},
R 12     }
13 })
14
15 minetest.register_craftitem("technic:water_mill", {
16     description = "Water Mill",
17     stack_max = 99,
18 }) 
19
ee5c6c 20 local water_mill_formspec =
82cba9 21     "invsize[8,4;]"..
R 22     "image[1,1;1,2;technic_power_meter_bg.png]"..
23     "label[0,0;Water Mill]"..
24     "label[1,3;Power level]"..
25     "list[current_player;main;0,5;8,4;]"
26     
27
ee5c6c 28 minetest.register_node(
K 29    "technic:water_mill",
30    {
31       description = "Water Mill",
32       tiles = {"technic_water_mill_top.png", "technic_machine_bottom.png", "technic_water_mill_side.png",
33            "technic_water_mill_side.png", "technic_water_mill_side.png", "technic_water_mill_side.png"},
34       paramtype2 = "facedir",
35       groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
36       legacy_facedir_simple = true,
37       sounds = default.node_sound_wood_defaults(),
38       on_construct = function(pos)
39             local meta = minetest.env:get_meta(pos)
40             meta:set_string("infotext", "Water Mill")
41             meta:set_float("technic_power_machine", 1)
42             meta:set_int("LV_EU_supply", 0)
43             meta:set_string("formspec", water_mill_formspec)    
44              end,    
45    })
82cba9 46
ee5c6c 47 minetest.register_node(
K 48    "technic:water_mill_active",
49    {
50       description = "Water Mill",
51       tiles = {"technic_water_mill_top_active.png", "technic_machine_bottom.png", "technic_water_mill_side.png",
52            "technic_water_mill_side.png", "technic_water_mill_side.png", "technic_water_mill_side.png"},
53       paramtype2 = "facedir",
54       groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
55       legacy_facedir_simple = true,
56       sounds = default.node_sound_wood_defaults(),
57       drop="technic:water_mill",
82cba9 58 })
R 59
ee5c6c 60 local check_node_around_mill = function(pos)
K 61                   local node=minetest.env:get_node(pos)
62                   if node.name=="default:water_flowing" then return 1 end
63                   return 0
64                    end
82cba9 65
ee5c6c 66 minetest.register_abm(
K 67    {
68       nodenames = {"technic:water_mill","technic:water_mill_active"},
69       interval = 1,
70       chance   = 1,
71       action = function(pos, node, active_object_count, active_object_count_wider)
72           local meta             = minetest.env:get_meta(pos)
73           local water_nodes      = 0
74           local lava_nodes       = 0
75           local production_level = 0
76           local eu_supply        = 0
82cba9 77
ee5c6c 78           pos.x=pos.x+1
K 79           local check=check_node_around_mill (pos)
80           if check==1 then water_nodes=water_nodes+1 end
81           pos.x=pos.x-2
82           check=check_node_around_mill (pos)
83           if check==1 then water_nodes=water_nodes+1 end
84           pos.x=pos.x+1
85           pos.z=pos.z+1
86           check=check_node_around_mill (pos)
87           if check==1 then water_nodes=water_nodes+1 end
88           pos.z=pos.z-2
89           check=check_node_around_mill (pos)
90           if check==1 then water_nodes=water_nodes+1 end
91           pos.z=pos.z+1
82cba9 92     
ee5c6c 93           if water_nodes==1 then production_level =  25; eu_supply =  30 end
K 94           if water_nodes==2 then production_level =  50; eu_supply =  60 end
95           if water_nodes==3 then production_level =  75; eu_supply =  90 end
96           if water_nodes==4 then production_level = 100; eu_supply = 120 end
82cba9 97
ee5c6c 98           if production_level>0 then
K 99              meta:set_int("LV_EU_supply", eu_supply)
100           end
82cba9 101
ee5c6c 102           local load = 1 -- math.floor((charge/max_charge)*100)
K 103           meta:set_string("formspec",
104                   "invsize[8,4;]"..
105                      "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
106                      (load)..":technic_power_meter_fg.png]"..
107                   "label[0,0;Water Mill]"..
108                   "label[1,3;Power level]"..
109                   "label[4,0;Production at "..tostring(production_level).."%]"
110                 )
82cba9 111                 
ee5c6c 112           if production_level>0 and minetest.env:get_node(pos).name=="technic:water_mill" then
K 113              hacky_swap_node (pos,"technic:water_mill_active")
114              meta:set_int("LV_EU_supply", 0)
115              return
116           end
117           if production_level==0 then hacky_swap_node (pos,"technic:water_mill") end
118            end
119    }) 
82cba9 120
ee5c6c 121 technic.register_LV_machine ("technic:water_mill","PR")
K 122 technic.register_LV_machine ("technic:water_mill_active","PR")