Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. local zz=turtle
  2. local args = {...}
  3. local currentX=0 -- hoz
  4. local currentY=0 -- height
  5. local currentZ=0 -- depth
  6. local currRad=1 -- 0 is the right, 1 is default (original direction), 2 is the left, 3 is the back
  7. local mapData={{0,16,2,},{0,16,3,},{0,17,4,},{0,17,5,},{0,17,6,},{0,18,7,},{0,19,8,},{0,19,9,},{0,20,10,},{0,21,11,},{0,22,12,},{0,22,13,},{0,17,14,},{0,18,14,},{0,19,14,},{0,23,14,},{0,24,15,},{0,20,15,},{0,19,15,},{0,21,16,},{0,22,16,},{0,23,16,},{0,24,16,},{0,24,17,},{0,23,17,}} -- {y,x,z,slotID}
  8. local cacheSlot = {}
  9. function placeUp(slotID)
  10. for i=1,12 do
  11. zz.select(i)
  12. if zz.compareTo(slotID) then
  13. return zz.placeUp()
  14. end
  15. end
  16. return false
  17. end
  18. function refuel(amount)
  19. while zz.getFuelLevel()<=math.abs(amount) do
  20. zz.select(16)
  21. zz.refuel(1)
  22. print("Refueling")
  23. end
  24. end
  25. function turnRight()
  26. while zz.turnRight() do
  27. currRad=(currRad-1)%4
  28. break
  29. end
  30. end
  31. function turnLeft()
  32. while zz.turnLeft() do
  33. currRad=(currRad+1)%4
  34. break
  35. end
  36. end
  37. function turnToRad(r)
  38. if currRad==r then
  39. return true
  40. end
  41. while currRad~=r do
  42. if currRad>r then
  43. turnRight()
  44. elseif currRad<r then
  45. turnLeft()
  46. end
  47. end
  48. end
  49. function alertForProblem(stringCauseOfProblem)
  50. zz.turnRight()
  51. zz.turnRight()
  52. zz.turnRight()
  53. zz.turnRight()
  54. print(stringCauseOfProblem)
  55. end
  56. function moveByX(ox)
  57. local x=currentX+ox
  58. turnToRad(0)
  59. refuel(ox)
  60. while ox~=0 do
  61. if ox<0 then
  62. if zz.back() then
  63. ox=ox+1
  64. currentX=currentX-1
  65. else
  66. alertForProblem("can not move - check fuel or obstacle")
  67. moveByX(ox)
  68. break
  69. end
  70. else
  71. if zz.forward() then
  72. ox=ox-1
  73. currentX=currentX+1
  74. else
  75. alertForProblem("can not move - check fuel or obstacle")
  76. moveByX(ox)
  77. break
  78. end
  79. end
  80. end
  81. end
  82. function moveByZ(oz)
  83. local z=currentZ+oz
  84. turnToRad(1)
  85. refuel(oz)
  86. while oz~=0 do
  87. if oz<0 then
  88. if zz.back() then
  89. oz=oz+1
  90. currentZ=currentZ-1
  91. else
  92. alertForProblem("can not move - check fuel or obstacle")
  93. moveByZ(oz)
  94. break
  95. end
  96. else
  97. if zz.forward() then
  98. oz=oz-1
  99. currentZ=currentZ+1
  100. else
  101. alertForProblem("can not move - check fuel or obstacle")
  102. moveByZ(oz)
  103. break
  104. end
  105. end
  106. end
  107. end
  108. function moveByY(oy)
  109. local y=currentY+oy
  110. refuel(oy)
  111. while oy~=0 do
  112. if oy<0 then
  113. if zz.down() then
  114. oy=oy+1
  115. currentY=currentY-1
  116. else
  117. alertForProblem("can not move down - check fuel or obstacle")
  118. moveByY(oy)
  119. break
  120. end
  121. else
  122. if zz.up() then
  123. oy=oy-1
  124. currentY=currentY+1
  125. else
  126. alertForProblem("can not move up - check fuel or obstacle")
  127. moveByY(oy)
  128. break
  129. end
  130. end
  131. end
  132. end
  133. function goToCord(y,x,z)
  134. local differenceX=x-(currentX)
  135. local differenceY=y-currentY
  136. local differenceZ=z-currentZ
  137. if differenceX~=0 then moveByX(differenceX) end
  138. if differenceY~=0 then moveByY(differenceY) end
  139. if differenceZ~=0 then moveByZ(differenceZ) end
  140. end
  141. function placeAt(y,x,z,slotID)
  142. goToCord(y,x,z)
  143. if placeUp(slotID) then return true
  144. else
  145. alertForProblem("can not place underneath - must be air underneath or do I have a block to place")
  146. placeAt(y,x,z,slotID)
  147. end
  148. end
  149. function progressionPlace(startAt)
  150. for i=15,222 do
  151. local result=placeAt(14-i,0,0,15)
  152. if result then print("Finished Task #"..i.." out of "..222) end
  153. end
  154. goToCord(0,0,0);
  155. end
  156. if (#args==1) then
  157. progressionPlace(1)
  158.  
  159. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement