Advertisement
dacman9

FancyPortalLocator

May 17th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. local sensor = peripheral.wrap("back")
  2. local names = {stand="ArmorStand",eye="EyeOfEnderSignal",player="DCampbell"}
  3. local aPos = {x=13.5,y=69,z=-193.5}
  4. local pos1 = {x=0,y=0,z=0}
  5. local pos2 = {x=0,y=0,z=0}
  6. local ppos1 = {x=0,y=0,z=0}
  7. local ppos2 = {x=0,y=0,z=0}
  8.  
  9. function findObjByName(name, entities)
  10. for _, entity in pairs(entities) do
  11. if entity.name == name then
  12. return entity
  13. end
  14. end
  15. return nil
  16. end
  17. function updatePos(entities,fixedName,relName,fixedPos,posOut)
  18. local fixed = findObjByName(fixedName, entities)
  19. local rel = findObjByName(relName, entities)
  20. posOut.x = rel.x - fixed.x + fixedPos.x
  21. posOut.y = rel.y - fixed.y + fixedPos.y
  22. posOut.z = rel.z - fixed.z + fixedPos.z
  23. end
  24. function getPearlCoord(pposOut,posOut)
  25. print("Enter Armor Stand Coords (x, z):")
  26. aPos.x = tonumber(read())
  27. aPos.z = tonumber(read())
  28. print("Throw eye of ender when ready")
  29. while not findObjByName(names.eye,sensor.sense()) do
  30. sleep(0.25)
  31. end
  32. updatePos(sensor.sense(),names.stand,names.player,aPos,pposOut)
  33. print("Tracking eye of ender...")
  34. while true do
  35. local entities = sensor.sense()
  36. local obj = findObjByName(names.eye,entities)
  37. if not obj then
  38. break
  39. end
  40. updatePos(entities,names.stand,names.eye,aPos,posOut)
  41. sleep(0.25)
  42. end
  43. print("Angle recorded")
  44. end
  45. function getIntersection(a0,a1,b0,b1)
  46. local ma = (a1.z - a0.z)/(a1.x - a0.x)
  47. local mb = (b1.z - b0.z)/(b1.x - b0.x)
  48. local x = (ma*a0.x - mb*b0.x + b0.z - a0.z)/(ma - mb)
  49. local z = ma*(x - a0.x) + a0.z
  50. return {x=x,z=z}
  51. end
  52.  
  53. --Code
  54. print(getIntersection({x=0,z=1},{x=5.01,z=6},{x=5,z=0},{x=5.01,z=1}).x)
  55. print("First throw:")
  56. getPearlCoord(ppos1,pos1)
  57. print("Second throw:")
  58. getPearlCoord(ppos2,pos2)
  59. local inter = getIntersection(ppos1,pos1,ppos2,pos2)
  60. print(("Intersection:\n%s, %s"):format(inter.x,inter.z))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement