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+2.5 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 and s.y > -5 and s.z <= 7 and s.z >= -8 and s.x <= 7 and s.x >= -8 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 local yaw,pitch = yaw_pitch(v.x,v.y,v.z) print(v.x,v.y,v.z,yaw,pitch,v.name) laser.fire(yaw,pitch,4) end if #targets == 0 then for i = 1,3 do if turtle.detectDown() then break end assert(turtle.down()) end end end