Advertisement
rjs232323

Untitled

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