summaryrefslogtreecommitdiff
path: root/hole.lua
blob: 339ef86211015f95a3ab55bb97f3e5a98cbf187b (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
local function yaw_pitch(xoff,yoff,zoff)
	local yaw = -math.deg(math.atan2(xoff,zoff))
	local perp_dist = math.sqrt(xoff*xoff+zoff*zoff)
	local pitch = -math.deg(math.atan2(yoff, perp_dist))
	return yaw,pitch
end

local scanner = assert(peripheral.wrap"right")
local laser = assert(peripheral.wrap"left")

while true do
	local scanned = scanner.scan()
	local targets = {}
	for _,s in ipairs(scanned) do
		if s.name ~= "minecraft:air" and s.y < 0 then
			local should_add = true
			
			for i,t in ipairs(targets) do
				if t.x == s.x and t.z == s.z then
					should_add = false
					if s.y > t.y then
						targets[i] = s
					end
				end
			end
			if should_add then
				table.insert(targets,s)
			end
		end
	end
	for _,v in ipairs(targets) do
		if     v.z <= 7 and v.z >= -8
		   and v.x <= 7 and v.x >= -8
		   then
			local yaw,pitch = yaw_pitch(v.x,v.y,v.z)
			laser.fire(yaw,pitch,4)
		end
	end
end