summaryrefslogtreecommitdiff
path: root/firealarm_meseconsio/init.lua
blob: c0b076fa8f80f0cdbc632d7476069bd885dc08a1 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
minetest.register_node(":firealarm:mesecons_input_off",{
	description = "Fire Alarm Mesecons Input Module",
	groups = { oddly_breakable_by_hand = 1 },
	tiles = {
		"firealarm_meseconsio_input_off.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
	},
	paramtype = "light",
	paramtype2 = "facedir",
	drawtype = "nodebox",
	node_box = {
		type = "fixed",
		fixed = {
			{-0.5,-0.5,-0.5,0.5,-0.4,0.5},
		},
	},
	on_punch = function(pos,_,player)
		local name = player:get_player_name()
		minetest.chat_send_player(name,string.format("Position: %d,%d,%d",pos.x,pos.y,pos.z))
	end,
	mesecons = {
		effector = {
			action_on = function(pos,node)
				local devInfo = firealarm.getDevInfo("signaling",pos)
				if devInfo then
					devInfo.active = true
					node.name = "firealarm:mesecons_input_on"
					minetest.set_node(pos,node)
					if devInfo.associated then
						local panelPos = minetest.get_position_from_hash(devInfo.associated)
						if panelPos then firealarm.loadNode(panelPos) end
						if type(firealarm.panelABM) == "function" then firealarm.panelABM(pos) end
					end
				end
			end,
		},
	},
	after_place_node = function(pos)
		firealarm.setDevInfo("signaling",pos,{active = false,manualReset = true})
	end,
	after_dig_node = function(pos)
		firealarm.setDevInfo("signaling",pos,nil)
	end,
})

minetest.register_node(":firealarm:mesecons_input_on",{
	description = "Fire Alarm Mesecons Input Module (on state - you hacker you!)",
	drop = "firealarm:mesecons_input_off",
	groups = { oddly_breakable_by_hand = 1, not_in_creative_inventory = 1 },
	tiles = {
		"firealarm_meseconsio_input_on.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
	},
	paramtype = "light",
	paramtype2 = "facedir",
	drawtype = "nodebox",
	node_box = {
		type = "fixed",
		fixed = {
			{-0.5,-0.5,-0.5,0.5,-0.4,0.5},
		},
	},
	on_punch = function(pos,_,player)
		local name = player:get_player_name()
		minetest.chat_send_player(name,string.format("Position: %d,%d,%d",pos.x,pos.y,pos.z))
	end,
	mesecons = {
		effector = {
			action_off = function(pos,node)
				local devInfo = firealarm.getDevInfo("signaling",pos)
				if devInfo then
					devInfo.active = false
					node.name = "firealarm:mesecons_input_off"
					minetest.set_node(pos,node)
				end
			end,
		},
	},
	after_dig_node = function(pos)
		firealarm.setDevInfo("signaling",pos,nil)
	end,
})

minetest.register_node(":firealarm:mesecons_output_off",{
	description = "Fire Alarm Mesecons Output Module",
	groups = { oddly_breakable_by_hand = 1 },
	tiles = {
		"firealarm_meseconsio_output_off.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
	},
	paramtype = "light",
	paramtype2 = "facedir",
	drawtype = "nodebox",
	node_box = {
		type = "fixed",
		fixed = {
			{-0.5,-0.5,-0.5,0.5,-0.4,0.5},
		},
	},
	mesecons = {
		receptor = {
			state = mesecon.state.off,
		},
	},
	on_punch = function(pos,_,player)
		local name = player:get_player_name()
		minetest.chat_send_player(name,string.format("Position: %d,%d,%d",pos.x,pos.y,pos.z))
	end,
	after_place_node = function(pos)
		firealarm.setDevInfo("notification",pos,{strobeActive = false,hornActive = false})
	end,
	after_dig_node = function(pos)
		firealarm.setDevInfo("notification",pos,nil)
	end,
})

minetest.register_node(":firealarm:mesecons_output_on",{
	drop = "firealarm:mesecons_output_off",
	description = "Fire Alarm Mesecons Output Module (on state - you hacker you!)",
	groups = { oddly_breakable_by_hand = 1,not_in_creative_inventory = 1 },
	tiles = {
		"firealarm_meseconsio_output_on.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
		"firealarm_meseconsio_sides.png",
	},
	paramtype = "light",
	paramtype2 = "facedir",
	drawtype = "nodebox",
	node_box = {
		type = "fixed",
		fixed = {
			{-0.5,-0.5,-0.5,0.5,-0.4,0.5},
		},
	},
	mesecons = {
		receptor = {
			state = mesecon.state.on,
		},
	},
})

minetest.register_abm({
	label = "Update mesecons output state",
	nodenames = {"firealarm:mesecons_output_off","firealarm:mesecons_output_on"},
	interval = 2,
	chance = 1,
	action = function(pos,node)
		local devInfo = firealarm.getDevInfo("notification",pos)
		if not devInfo then return end
		if node.name == "firealarm:mesecons_output_off" and devInfo.strobeActive then
			node.name = "firealarm:mesecons_output_on"
			minetest.set_node(pos,node)
			mesecon.receptor_on(pos)
		elseif node.name == "firealarm:mesecons_output_on" and not devInfo.strobeActive then
			node.name = "firealarm:mesecons_output_off"
			minetest.set_node(pos,node)
			mesecon.receptor_off(pos)
		end
	end,
})

minetest.register_craft({
	output = "firealarm:mesecons_input_off",
	recipe = {
		{"","dye:red","",},
		{"mesecons:wire_00000000_off","mesecons_luacontroller:luacontroller0000","",},
		{"","","",},
	}
})

minetest.register_craft({
	output = "firealarm:mesecons_output_off",
	recipe = {
		{"","dye:red","",},
		{"","mesecons_luacontroller:luacontroller0000","mesecons:wire_00000000_off",},
		{"","","",},
	}
})