Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. ready = false
  2. function saveRoutinePosition(action)
  3.  
  4. dataFile = fs.open("Data", fs.exists("Data") and "a" or "w")
  5. dataFile.write(action)
  6. dataFile.close()
  7. end
  8.  
  9. function readRoutine()
  10.  
  11. dataFile = fs.open("Data", "r")
  12. return dataFile.readAll()
  13. end
  14.  
  15. function refuel()
  16.  
  17. if(turtle.getFuelLevel() < turtle.getFuelLimit/2) then
  18. turtle.select(1)
  19. turtle.refuel()
  20. end
  21. end
  22.  
  23. function chestArea()
  24.  
  25. for i = 5, 16 do
  26. turtle.select(i)
  27. turtle.dropDown()
  28. end
  29. turtle.select(4)
  30. while not turtle.compare() do
  31. turtle.turnRight()
  32. end
  33. turtle.select(1)
  34. turtle.suck(turtle.getItemSpace())
  35. turtle.select(4)
  36. turtle.suck(turtle.getItemSpace())
  37. turtle.turnRight()
  38. if not turtle.detect() then
  39. turtle.place()
  40. end
  41. turtle.turnRight()
  42. if not turtle.detect() then
  43. turtle.place()
  44. end
  45.  
  46.  
  47.  
  48. refuel()
  49.  
  50. if fs.exists("Data") then
  51.  
  52. if readRoutine() == "checkWood" then
  53. ready = true
  54. end
  55. else
  56. ready = true
  57. end
  58.  
  59. while true do
  60.  
  61. while ready do
  62.  
  63. --Dig wood
  64. turtle.select(2)
  65. if not turtle.compare() then
  66. saveRoutinePosition("checkWood")
  67. nTurn = 0;
  68. while not turtle.compare() do
  69. if nTurn == 4 then
  70. if not turtle.detectUp() then
  71. saveRoutinePosition("reset")
  72. while not turtle.detectDown do
  73. turtle.down()
  74. end
  75. saveRoutinePosition("chestArea")
  76. chestArea()
  77. break end
  78. end
  79. turtle.turnRight()
  80. nTurn = nTurn + 1;
  81. end
  82. else
  83. turtle.dig()
  84. turtle.turnRight()
  85. turtle.turnRight()
  86. turtle.dig()
  87. if turtle.digUp() then
  88. saveRoutinePosition("digUp")
  89. end
  90. turtle.up()
  91. saveRoutinePosition("checkWood")
  92. end
  93.  
  94. if not ready and readRoutine() == "reset" then
  95.  
  96. while not turtle.detectDown do
  97. turtle.down()
  98. end
  99. saveRoutinePosition("chestArea")
  100. chestArea()
  101. ready = true
  102. end
  103.  
  104. if not ready and readRoutine() == "chestArea" then
  105. chestArea()
  106. ready = true
  107. end
  108.  
  109. if not ready and readRoutine() == "digUp" then
  110. turtle.up()
  111. ready = true
  112. end
  113.  
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement