summaryrefslogtreecommitdiff
path: root/firealarm_smokedetector/init.lua
blob: dc67a1b5cbb1d78ee1259f5eba8e7481a4c9c118 (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
local smokeDetectorOffBottomTexture = "[combine:32x320"..
                                      ":0,0=firealarm_smokedetector_bottom_on.png"..
                                      ":0,32=firealarm_smokedetector_bottom_off.png"..
                                      ":0,64=firealarm_smokedetector_bottom_off.png"..
                                      ":0,96=firealarm_smokedetector_bottom_off.png"..
                                      ":0,128=firealarm_smokedetector_bottom_off.png"..
                                      ":0,160=firealarm_smokedetector_bottom_off.png"..
                                      ":0,192=firealarm_smokedetector_bottom_off.png"..
                                      ":0,224=firealarm_smokedetector_bottom_off.png"..
                                      ":0,256=firealarm_smokedetector_bottom_off.png"..
                                      ":0,288=firealarm_smokedetector_bottom_off.png"

minetest.register_node(":firealarm:smokedetector_off",{
	description = "Fire Alarm Smoke Detector",
	groups = { oddly_breakable_by_hand = 1 },
	tiles = {
		"firealarm_smokedetector_sides.png",
		{
			name = smokeDetectorOffBottomTexture,
			animation = {
				type = "vertical_frames",
				aspect_w = 32,
				aspect_h = 32,
				length = 5,
			},
		},
		"firealarm_smokedetector_sides.png",
		"firealarm_smokedetector_sides.png",
		"firealarm_smokedetector_sides.png",
		"firealarm_smokedetector_sides.png",
	},
	paramtype = "light",
	paramtype2 = "facedir",
	drawtype = "nodebox",
	node_box = {
		type = "fixed",
		fixed = {
			{-0.2,0.4,-0.2,0.2,0.5,0.2},
			{-0.075,0.35,-0.075,0.075,0.4,0.075},
		},
	},
	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("signaling",pos,{active = false,manualReset = false})
		minetest.get_meta(pos):set_int("agressive",1)
	end,
	after_dig_node = function(pos)
		firealarm.setDevInfo("signaling",pos,nil)
	end,
})

minetest.register_node(":firealarm:smokedetector_on",{
	drop = "firealarm:smokedetector_off",
	description = "Fire Alarm Smoke Detector (on state - you hacker you!)",
	groups = { oddly_breakable_by_hand = 1,not_in_creative_inventory = 1 },
	tiles = {
		"firealarm_smokedetector_sides.png",
		"firealarm_smokedetector_bottom_on.png",
		"firealarm_smokedetector_sides.png",
		"firealarm_smokedetector_sides.png",
		"firealarm_smokedetector_sides.png",
		"firealarm_smokedetector_sides.png",
	},
	paramtype = "light",
	paramtype2 = "facedir",
	drawtype = "nodebox",
	node_box = {
		type = "fixed",
		fixed = {
			{-0.2,0.4,-0.2,0.2,0.5,0.2},
			{-0.075,0.35,-0.075,0.075,0.4,0.075},
		},
	},
	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_dig_node = function(pos)
		firealarm.setDevInfo("signaling",pos,nil)
	end,
})

minetest.register_abm({
	label = "Check for fire",
	nodenames = {"firealarm:smokedetector_off"},
	interval = 5,
	chance = 1,
	action = function(pos,node)
		local devInfo = firealarm.getDevInfo("signaling",pos)
		if not devInfo then return end
		local minp = vector.add(pos,vector.new(-4,-10,-4))
		local maxp = vector.add(pos,vector.new(4,0,4))
		local fire = false
		local fire_nodes = {["fire:permanent_flame"] = true,["fire:basic_flame"] = true}
		for x=minp.x,maxp.x,1 do
			for y=minp.y,maxp.y,1 do
				for z=minp.z,maxp.z,1 do
					if fire_nodes[minetest.get_node({x=x,y=y,z=z}).name] then fire = true end
				end
			end
		end
		if fire or minetest.get_meta(pos):get_int("agressive") == 0 then
			devInfo.active = true
			firealarm.setDevInfo("signaling",pos,devInfo)
			node.name = "firealarm:smokedetector_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,
})

minetest.register_abm({
	label = "Reset LED",
	nodenames = {"firealarm:smokedetector_on"},
	interval = 1,
	chance = 1,
	action = function(pos,node)
		local devInfo = firealarm.getDevInfo("signaling",pos)
		if (not devInfo) or devInfo.active then return end
		node.name = "firealarm:smokedetector_off"
		minetest.set_node(pos,node)
		minetest.get_meta(pos):set_int("agressive",1)
	end,
})

minetest.register_craft({
	output = "firealarm:smokedetector_off",
	recipe = {
		{"plasticbox:plasticbox","homedecor:ic","plasticbox:plasticbox",},
		{"homedecor:copper_strip","technic:uranium_lump","homedecor:copper_strip",},
		{"","plasticbox:plasticbox","mesecons_lightstone:lightstone_red_off",},
	}
})

minetest.register_craft({
	output = "firealarm:smokedetector_off",
	recipe = {
		{"plasticbox:plasticbox","homedecor:ic","plasticbox:plasticbox",},
		{"mesecons_lamp:lamp_off","","mesecons_solarpanel:solar_panel_off",},
		{"","plasticbox:plasticbox","mesecons_lightstone:lightstone_red_off",},
	}
})