summaryrefslogtreecommitdiff
path: root/hole.lua
blob: 6c2501a613cf2f66b3f56a9fb83d0d6a1d21330f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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")

repeat
	local targets = {}
	local scanned = scanner.scan()
	for _,v in ipairs(scanned) do
		if v.name == "minecraft:cobblestone" then
			table.insert(targets,v)
		end
	end
	for _,t in ipairs(targets) do
		local yaw,pitch = yaw_pitch(t.x,t.y,t.z)
		laser.fire(yaw,pitch,1)
	end
until #targets == 0