Protowalker

Untitled

Jun 6th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. os.loadAPI("apis/tortoise.lua")
  2.  
  3.  
  4. local id,x,z=...
  5.  
  6. id=tonumber(id)
  7. x=tonumber(x)
  8. z=tonumber(z)
  9.  
  10. local position = {x=0,y=0,z=0}
  11. local turns = 0
  12.  
  13. local fuelChestPos = {x=1,y=0,z=4}
  14. local oreChestPos = {x=1,y=0,z=1}
  15.  
  16.  
  17. local function moveX(dist)
  18. local relTurns = turns%4
  19. if relTurns == 0 then
  20. tortoise.forceForward(dist)
  21. elseif relTurns == 1 then
  22. tortoise.turnLeft()
  23. tortoise.forceForward(dist)
  24. tortoise.turnRight()
  25. elseif relTurns == 2 then
  26. tortoise.forceBack(dist)
  27. else
  28. tortoise.turnRight()
  29. tortoise.forceForward(dist)
  30. tortoise.turnLeft()
  31. end
  32. position.x = position.x + dist
  33. end
  34.  
  35. local function moveY(dist)
  36. tortoise.forceDown(dist)
  37. position.y = position.y + dist
  38. end
  39.  
  40. local function moveZ(dist)
  41. tortoise.turnRight()
  42. moveX(dist)
  43. tortoise.turnLeft()
  44. position.x = position.x - dist
  45. position.z = position.z + dist
  46. end
  47.  
  48. if id==1 then
  49. moveX(1)
  50. elseif id==2 then
  51. moveX(1)
  52. moveZ(z*0.5)
  53. moveY(1)
  54. position.y=0
  55. elseif id==3 then
  56. moveX(x*0.5)
  57. moveY(2)
  58. position.y=0
  59. elseif id==4 then
  60. moveX(x*0.5)
  61. moveZ(z*0.5)
  62. moveY(3)
  63. position.y=0
  64. else
  65. print("no ID specified. quitting")
  66. return
  67. end
  68.  
  69. local function turnLeft(times)
  70. if times == 0 then return end
  71. tortoise.turnLeft(times)
  72. turns = turns - times
  73. end
  74.  
  75. local function turnRight(times)
  76. if times == 0 then return end
  77. tortoise.turnRight(times)
  78. turns = turns + times
  79. end
  80.  
  81. local function distanceFromHome()
  82. return position.x + position.y + position.z
  83. end
  84.  
  85. local function checkFuel()
  86. if turtle.getFuelLevel() + (80 * turtle.getItemCount()) < distanceFromHome()+10 then
  87. local oldPos = position
  88.  
  89. moveY(-position.y)
  90. moveX(fuelChestPos.x-position.x)
  91. moveZ(fuelChestPos.z-position.z)
  92.  
  93. turnLeft(turns)
  94. turnLeft(2)
  95. turtle.suck(64)
  96. moveZ(-2)
  97.  
  98. for i=2,16 do
  99. turtle.select(i)
  100. turtle.drop()
  101. end
  102. turtle.select(1)
  103.  
  104. turnRight(2)
  105.  
  106.  
  107. moveY(oldPos.y)
  108. moveX(oldPos.x-position.x)
  109. moveZ(oldPos.z-position.z)
  110.  
  111. end
  112. end
  113.  
  114. local function checkInv()
  115. for i=2,16 do
  116. if turtle.getItemCount(i) == 0 then
  117. return
  118. end
  119. end
  120.  
  121. local oldPos = position
  122. moveY(-position.y)
  123. moveX(oreChestPos.x - position.x)
  124. moveZ(oreChestPos.z - position.z)
  125. turnLeft(turns)
  126. turnLeft(2)
  127. for i=2,16 do
  128. turtle.select(i)
  129. turtle.drop()
  130. end
  131.  
  132. moveZ(3)
  133. turtle.select(1)
  134. turtle.suck(64-turtle.getItemCount())
  135.  
  136. turnRight(2)
  137.  
  138. moveX(oldPos.x - position.x)
  139. moveZ(oldPos.z - position.z)
  140. moveY(position.y)
  141. end
  142.  
  143.  
  144. while true do
  145. for i=1,x/2 do
  146. for _=1,z/2 do
  147. turnLeft(turns)
  148. checkFuel()
  149. checkInv()
  150. turtle.digDown()
  151. if turtle.detectDown() then
  152. moveY(-position.y - id)
  153. moveX(x)
  154. print("finished.")
  155. return
  156. end
  157. if i%2==1 then moveZ(1)
  158. else moveZ(-1) end
  159. end
  160. if position.y%2==1 then moveX(1)
  161. else moveX(-1) end
  162. end
  163. moveY(1)
  164. end
Advertisement
Add Comment
Please, Sign In to add comment