summaryrefslogtreecommitdiff
path: root/mesecons_hydroturbine/init.lua
blob: 6be30078baa54ac8e4d314be34963427e72627cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
-- HYDRO_TURBINE

minetest.register_node("mesecons_hydroturbine:hydro_turbine_off", {
	drawtype = "nodebox",
	tile_images = {"jeija_hydro_turbine_off.png"},
	groups = {dig_immediate=2},
    	description="Water Turbine",
	paramtype = "light",
	selection_box = {
		type = "fixed",
		fixed = {{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
			{-0.15, 0.5, -0.15, 0.15, 1.45, 0.15},
			{-0.45, 1.15, -0.1, 0.45, 1.45, 0.1},
			{-0.1, 1.15, -0.45, 0.1, 1.45, 0.45}},
	},
	node_box = {
		type = "fixed",
		fixed = {{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
			{-0.15, 0.5, -0.15, 0.15, 1.45, 0.15},
			{-0.45, 1.15, -0.1, 0.45, 1.45, 0.1},
			{-0.1, 1.15, -0.45, 0.1, 1.45, 0.45}},
	},
})

minetest.register_node("mesecons_hydroturbine:hydro_turbine_on", {
	drawtype = "nodebox",
	tile_images = {"jeija_hydro_turbine_on.png"},
	drop = '"mesecons_hydroturbine:hydro_turbine_off" 1',
	groups = {dig_immediate=2,not_in_creative_inventory=1},
	description="Water Turbine",
	paramtype = "light",
	selection_box = {
		type = "fixed",
		fixed = {{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
			{-0.15, 0.5, -0.15, 0.15, 1.45, 0.15},
			{-0.5, 1.15, -0.1, 0.5, 1.45, 0.1},
			{-0.1, 1.15, -0.5, 0.1, 1.45, 0.5}},
	},
	node_box = {
		type = "fixed",
		fixed = {{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
			{-0.15, 0.5, -0.15, 0.15, 1.45, 0.15},
			{-0.5, 1.15, -0.1, 0.5, 1.45, 0.1},
			{-0.1, 1.15, -0.5, 0.1, 1.45, 0.5}},
	},
})


minetest.register_abm({
nodenames = {"mesecons_hydroturbine:hydro_turbine_off"},
	interval = 1,
	chance = 1,
	action = function(pos, node, active_object_count, active_object_count_wider)
		local waterpos={x=pos.x, y=pos.y+1, z=pos.z}
		if minetest.env:get_node(waterpos).name=="default:water_flowing" then
			--minetest.env:remove_node(pos)
			minetest.env:add_node(pos, {name="mesecons_hydroturbine:hydro_turbine_on"})
			nodeupdate(pos)
			mesecon:receptor_on(pos)
		end
	end,
})

minetest.register_abm({
nodenames = {"mesecons_hydroturbine:hydro_turbine_on"},
	interval = 1,
	chance = 1,
	action = function(pos, node, active_object_count, active_object_count_wider)
		local waterpos={x=pos.x, y=pos.y+1, z=pos.z}
		if minetest.env:get_node(waterpos).name~="default:water_flowing" then
			--minetest.env:remove_node(pos)
			minetest.env:add_node(pos, {name="mesecons_hydroturbine:hydro_turbine_off"})
			nodeupdate(pos)
			mesecon:receptor_off(pos)
		end
	end,
})

mesecon:add_receptor_node("mesecons_hydroturbine:hydro_turbine_on")
mesecon:add_receptor_node_off("mesecons_hydroturbine:hydro_turbine_off")

minetest.register_craft({
	output = '"mesecons_hydroturbine:hydro_turbine_off" 2',
	recipe = {
	{'','"default:stick"', ''},
	{'"default:stick"', '"default:steel_ingot"', '"default:stick"'},
	{'','"default:stick"', ''},
	}
})