local sensor = peripheral.wrap("right")
local laser = peripheral.wrap("left")
local function sense()
return sensor.getMetaByID("d5100e46-f630-4c48-a062-b5b75569a576")
--[[local sensed = sensor.sense()
for _,v in ipairs(sensed) do
if v.key ~= "minecraft:player" and v.key ~= "minecraft:item" and v.key ~= "plethora:laser" and v.key ~= "minecraft:arrow" and v.key ~= "minecraft:zombified_piglin" and v.key ~= "minecraft:experience_orb" then
print(v.key)
return v
end
end--]]
end
local function clamp(v, min, max)
if v < min then return min end
if v > max then return max end
return v
end
local function read(file)
local h = fs.open(file, "r")
local d = h.readAll()
h.close()
return d
end
parallel.waitForAny(function()
while true do
--laser.fire(0, 90, 4, false)
local target = sense()
if target and target.x and target.y and target.z then
local x = target.x
local y = target.y
local z = target.z
local yaw = math.deg(math.atan2(x, z))
local horiz = math.sqrt(x*x + z*z)
local pitch = -math.deg(math.atan2(y, horiz))
yaw = clamp(-yaw, -180, 180)
pitch = clamp(pitch, -90, 90)
laser.fire(yaw, pitch, 0.5, false)
else
sleep(0)
end
end
end, function()
while true do
sleep(2)
end
end)