Maciej 'agaran' Pijanka
2017-03-15 10307f23a78b33af50dc4a5f3d1baafb4ee4b0d9
commit | author | age
ee0765 1
be2f30 2 local S = technic.getter
S 3
ee0765 4 minetest.register_craft({
S 5     output = 'technic:wind_mill_frame 5',
6     recipe = {
68b7bc 7         {'technic:carbon_steel_ingot', '',                           'technic:carbon_steel_ingot'},
Z 8         {'',                           'technic:carbon_steel_ingot', ''},
9         {'technic:carbon_steel_ingot', '',                           'technic:carbon_steel_ingot'},
ee0765 10     }
S 11 })
12
13 minetest.register_craft({
14     output = 'technic:wind_mill',
15     recipe = {
68ea0a 16         {'',                           'technic:motor',              ''},
Z 17         {'technic:carbon_steel_ingot', 'technic:carbon_steel_block', 'technic:carbon_steel_ingot'},
83c649 18         {'',                           'technic:mv_cable',           ''},
ee0765 19     }
S 20 })
21
22 minetest.register_node("technic:wind_mill_frame", {
be2f30 23     description = S("Wind Mill Frame"),
ee0765 24     drawtype = "glasslike_framed",
68b7bc 25     tiles = {"technic_carbon_steel_block.png", "default_glass.png"},
ee0765 26     sunlight_propagates = true,
S 27     groups = {cracky=3},
28     sounds = default.node_sound_stone_defaults(),
29     paramtype = "light",
30 })
31
563a4c 32 local function check_wind_mill(pos)
N 33     if pos.y < 30 then
34         return false
35     end
d39797 36     pos = {x=pos.x, y=pos.y, z=pos.z}
563a4c 37     for i = 1, 20 do
d39797 38         pos.y = pos.y - 1
T 39         local node = minetest.get_node_or_nil(pos)
40         if not node then
41             -- we reached CONTENT_IGNORE, we can assume, that nothing changed
42             -- as the user will have to load the block to change it
43             return
44         end
563a4c 45         if node.name ~= "technic:wind_mill_frame" then
N 46             return false
47         end
48     end
49     return true
50 end
51
52 local run = function(pos, node)
53     local meta = minetest.get_meta(pos)
54     local machine_name = S("Wind %s Generator"):format("MV")
55
d39797 56     local check = check_wind_mill(pos)
T 57     if check == false then
563a4c 58         meta:set_int("MV_EU_supply", 0)
N 59         meta:set_string("infotext", S("%s Improperly Placed"):format(machine_name))
d39797 60     elseif check == true then
T 61         local power = math.min(pos.y * 100, 5000)
563a4c 62         meta:set_int("MV_EU_supply", power)
d39797 63         meta:set_string("infotext", S("@1 (@2 EU)", machine_name, technic.pretty_num(power)))
563a4c 64     end
d39797 65     -- check == nil: assume nothing has changed
563a4c 66 end
N 67
ee0765 68 minetest.register_node("technic:wind_mill", {
7c4b70 69     description = S("Wind %s Generator"):format("MV"),
68b7bc 70     tiles = {"technic_carbon_steel_block.png"},
ee0765 71     paramtype2 = "facedir",
83c649 72     groups = {cracky=1, technic_machine=1, technic_mv=1},
S 73     connect_sides = {"top", "bottom", "back", "left", "right"},
ee0765 74     sounds = default.node_sound_stone_defaults(),
S 75     drawtype = "nodebox",
76     paramtype = "light",
77     node_box = {
78         type = "fixed",
79         fixed = {
80             {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -- Main box
81             {-0.1, -0.1, -0.5,  0.1, 0.1, -0.6}, -- Shaft
82             {-0.1, -1,   -0.6,  0.1, 1,   -0.7}, -- Vertical blades
83             {-1,   -0.1, -0.6,  1,   0.1, -0.7}, -- Horizontal blades
84         }
85     },
86     on_construct = function(pos)
87         local meta = minetest.get_meta(pos)
7c4b70 88         meta:set_string("infotext", S("Wind %s Generator"):format("MV"))
ee0765 89         meta:set_int("MV_EU_supply", 0)
563a4c 90     end,
N 91     technic_run = run,
ee0765 92 })
S 93
94 technic.register_machine("MV", "technic:wind_mill", technic.producer)
95