Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sensor = peripheral.wrap("back")
- local names = {stand="ArmorStand",eye="EyeOfEnderSignal",player="DCampbell"}
- local aPos = {x=13.5,y=69,z=-193.5}
- local pos1 = {x=0,y=0,z=0}
- local pos2 = {x=0,y=0,z=0}
- local ppos1 = {x=0,y=0,z=0}
- local ppos2 = {x=0,y=0,z=0}
- function findObjByName(name, entities)
- for _, entity in pairs(entities) do
- if entity.name == name then
- return entity
- end
- end
- return nil
- end
- function updatePos(entities,fixedName,relName,fixedPos,posOut)
- local fixed = findObjByName(fixedName, entities)
- local rel = findObjByName(relName, entities)
- posOut.x = rel.x - fixed.x + fixedPos.x
- posOut.y = rel.y - fixed.y + fixedPos.y
- posOut.z = rel.z - fixed.z + fixedPos.z
- end
- function getPearlCoord(pposOut,posOut)
- print("Enter Armor Stand Coords (x, z):")
- aPos.x = tonumber(read())
- aPos.z = tonumber(read())
- print("Throw eye of ender when ready")
- while not findObjByName(names.eye,sensor.sense()) do
- sleep(0.25)
- end
- updatePos(sensor.sense(),names.stand,names.player,aPos,pposOut)
- print("Tracking eye of ender...")
- while true do
- local entities = sensor.sense()
- local obj = findObjByName(names.eye,entities)
- if not obj then
- break
- end
- updatePos(entities,names.stand,names.eye,aPos,posOut)
- sleep(0.25)
- end
- print("Angle recorded")
- end
- function getIntersection(a0,a1,b0,b1)
- local ma = (a1.z - a0.z)/(a1.x - a0.x)
- local mb = (b1.z - b0.z)/(b1.x - b0.x)
- local x = (ma*a0.x - mb*b0.x + b0.z - a0.z)/(ma - mb)
- local z = ma*(x - a0.x) + a0.z
- return {x=x,z=z}
- end
- --Code
- print(getIntersection({x=0,z=1},{x=5.01,z=6},{x=5,z=0},{x=5.01,z=1}).x)
- print("First throw:")
- getPearlCoord(ppos1,pos1)
- print("Second throw:")
- getPearlCoord(ppos2,pos2)
- local inter = getIntersection(ppos1,pos1,ppos2,pos2)
- print(("Intersection:\n%s, %s"):format(inter.x,inter.z))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement