Advertisement
DabDaddy6223

miner_turtleserver.lua

Nov 11th, 2023 (edited)
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. MODEM = peripheral.wrap("left")
  2.  
  3. function getVariables()
  4. write("Enter starting X: ")
  5. local start_x = read()
  6. if tonumber(start_x) == nil then error("Starting X should be a number!") end
  7. write("Enter starting Y: ")
  8. local start_y = read()
  9. if tonumber(start_y) == nil then error("Starting Y should be a number!") end
  10. write("Enter starting Z: ")
  11. local start_z = read()
  12. if tonumber(start_z) == nil then error("Starting Z should be a number!") end
  13. write("Enter width: ")
  14. local width = read()
  15. if tonumber(width) == nil then error("Width should be a number!") end
  16. write("Enter height: ")
  17. local height = read()
  18. if tonumber(height) == nil then error("Height should be a number!") end
  19. write("Enter depth: ")
  20. local depth = read()
  21. if tonumber(depth) == nil then error("Depth should be a number!") end
  22. write("Enter final facing direction: ")
  23. local direction = read()
  24. direction = string.lower(direction)
  25. if direction ~= "north" and direction ~= "east" and direction ~= "west" and direction ~= "south" then error("Direction should either be north, south, east or west") end
  26.  
  27. return start_x, start_y, start_z, width, height, depth, direction
  28. end
  29.  
  30. function refuelIfNeeded()
  31. end
  32.  
  33. -- https://www.computercraft.info/forums2/index.php?/topic/1704-get-the-direction-the-turtle-face/
  34. function getFacingDirection()
  35. loc1 = vector.new(gps.locate(2, false))
  36. if not turtle.forward() then
  37. for j=1,6 do
  38. if not turtle.forward() then
  39. turtle.dig()
  40. else break end
  41. end
  42. end
  43. loc2 = vector.new(gps.locate(2, false))
  44. heading = loc2 - loc1
  45. return ((heading.x + math.abs(heading.x) * 2) + (heading.z + math.abs(heading.z) * 3))
  46. end
  47.  
  48. function goToPosition(end_x, end_y, end_z, start_x, start_y, start_z, final_facing)
  49. current_x, current_y, current_z = start_x, start_y, start_z
  50. facing = getFacingDirection()
  51. print(facing)
  52. end
  53.  
  54. function main()
  55. start_x, start_y, start_z, width, height, depth, direction = getVariables()
  56. current_x, current_y, current_z = gps.locate()
  57. goToPosition(start_x, start_y, start_z, current_x, current_y, current_z, direction)
  58. end
  59.  
  60. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement