Advertisement
Guest User

Quarry

a guest
Apr 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.13 KB | None | 0 0
  1. --Preface
  2. ---------------------------------------
  3. print("Welcome to the Quarry 2.0")
  4. term.setTextColor(colors.white)
  5. print("This quarry is designed to mine along the x, y and z coordinates that you write below.")
  6. term.setTextColor(colors.green)
  7. print()
  8. print("Legond")
  9. print("x = distance forwards")
  10. print("y = depth below")
  11. print("z = distance left")
  12. print()
  13. term.setTextColor(colors.orange)
  14. print("Please place a chest behind the Quarry Turtle and a chest above.")
  15.  
  16. term.setTextColor(colors.gray)
  17. print("Coordinates: ")
  18. Cords = read()
  19.  
  20.  
  21. --Variables
  22. ---------------------------------------
  23. --x     Distance Forwards
  24. --y     Distance Downwards
  25. --z     Distance Left
  26. --hx    Home X
  27. --hy    Home Y
  28. --hz    Home Z
  29. --lsx   Present X
  30. --lsy   Present Y
  31. --lsz   Present Z
  32.  
  33.  
  34. --Functions
  35. ---------------------------------------
  36. local tArgs = {...}
  37.  
  38. --"On the Road"
  39. function forward()
  40.   for i = 1, tArgs[1]-1 do
  41.     turtle.dig()
  42.     turtle.forward()
  43.     if i == 0 then
  44.       D = false    --Code Completed
  45.     end
  46.   end
  47. end
  48.  
  49. --"Veer for the port laddy"
  50. function left()
  51.   turtle.turnLeft()
  52.   turtle.dig()
  53.   turtle.forward()
  54.   turtle.turnLeft()
  55.   D = false        --Code Completed
  56. end
  57.  
  58. --"Right's on the mark matey"
  59. function right()
  60.   turtle.turnRight()
  61.   turtle.dig()
  62.   turtle.forward()
  63.   turtle.turnRight()
  64.   D = false        --There's a trend...
  65. end
  66.  
  67. --"Losing Altitude"
  68. function down()
  69.   turtle.digDown()
  70.   turtle.down()
  71.   turtle.down()
  72.   D = false
  73. end
  74.  
  75. --"Honey, I'm coming home!"
  76. function home(hx,hy,hz)
  77. lsx, lsy, lsz = gps.locate(10,false)
  78. difx = lsx - hx
  79. dify = lsy - hy
  80. difz = lsz - hz
  81. turtle.forward()
  82. x1, y1, z1 = gps.locate(10,false)
  83. f = 0
  84. if x1 < x then f = 3 end
  85. if x1 > x then f = 1 end
  86. if z1 < z then f = 0 end
  87. if z1 > z then f = 2 end
  88. while f > 0 do
  89.   turtle.turnLeft()
  90.   f = f-1
  91. end
  92. if divz > 0 then
  93.   turtle.forward()
  94.   difz = difz -1
  95. end
  96. turtle.turnLeft()
  97. if divx > 0 then
  98.   turtle.forward()
  99.   difx = difx -1
  100. end
  101. turtle.turnLeft()
  102. if difz < 0 then
  103.   turtle.forward()
  104.   difz = difz +1
  105. end
  106. turtle.turnLeft()
  107. if difx < 0 then
  108.   turtle.forward()
  109.   difx = difx +1
  110. end
  111. while dify > 0 do
  112.   turtle.down()
  113.   dify = dify -1
  114. end
  115. while dify <= 0 do
  116.   turtle.up()
  117.   dify = dify +1
  118. end
  119. if {lsx, lsy, lsz} == {hx, hy, hz} then
  120.   D = false
  121. end
  122. end
  123.  
  124. --"Good nut, bad nut, good nut, odd nut"
  125. function even(q)
  126.   if (q % 2) == 0 then  --More Problems
  127.     qb = true        --If even
  128.   else
  129.     qb = false       --If odd
  130.   D = false
  131.   end
  132. end
  133. --Main Code
  134. ---------------------------------------
  135. --"Setting up Shop"
  136. hx, hy, hz = gps.locate(10)
  137.  
  138. --"Gold Rush"
  139. local leftTurns = 0
  140. local rightTurns = 0
  141.  
  142. if even(tArgs[1]) == true then
  143.   leftTurns = tArgs[3]/2
  144.   rightTurns = leftTurns
  145. else
  146.   leftTurns = (tArgs[3]/2) + 0.5
  147.   rightTurns = leftTurns - 1
  148. end
  149.  
  150. local s = tArgs[2]
  151.  
  152. --Layer Function
  153. function Layer()
  154. repeat
  155.   --Moves forwards and then turns left
  156.   if leftTurns > 0 then    --ERROR DAMN
  157.     forward()
  158.     left()
  159.     leftTurns = leftTurns -1
  160.   --Moves forwards and then turns right
  161.   elseif rightTurns > 0 then
  162.     forward()
  163.     left()
  164.     right()
  165.     rightTurns = rightTurns -1
  166.   end
  167. until rightTurns == 0
  168.  
  169. turtle.turnRight(2)
  170. turtle.forward(tArg[1]-1)
  171. turtle.turnLeft()
  172. turtle.forward(tArg[3]-1)
  173. turtle.turnRight()
  174.  
  175. down()
  176.  
  177. end
  178.  
  179. local s = 0
  180. local l = 0
  181.  
  182. repeat
  183.   Layer()
  184.   s = s-1
  185.   l = l+1
  186. until s == 0
  187.  
  188. --"Coming Home"
  189.  
  190. local turtleslots = {...}
  191.  
  192. while turtle.getItemCount(16) > 0 do
  193.   home(hx, hy, hz)
  194.   --need to set face direction
  195.   --turtle.suckUp(63) ???
  196.   turtle.drop(turtleslot[2])
  197.   turtle.drop(turtleslot[3])
  198.   turtle.drop(turtleslot[4])
  199.   turtle.drop(turtleslot[5])
  200.   turtle.drop(turtleslot[6])
  201.   turtle.drop(turtleslot[7])
  202.   turtle.drop(turtleslot[8])
  203.   turtle.drop(turtleslot[9])
  204.   turtle.drop(turtleslot[10])
  205.   turtle.drop(turtleslot[11])
  206.   turtle.drop(turtleslot[12])
  207.   turtle.drop(turtleslot[13])
  208.   turtle.drop(turtleslot[14])
  209.   turtle.drop(turtleslot[15])
  210.   turtle.drop(turtleslot[16])
  211.   turtle.turnRight(2)
  212.   turtle.down(l)
  213. end
  214. --"Recharge"
  215. while turtle.getFuelLevel() == 0 do
  216.   turtle.refuel(63)
  217. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement