Advertisement
Guest User

quarry

a guest
Jul 24th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. --ver Beta 1.0.0
  2.  
  3. --Defining variables
  4.  
  5. x = 0
  6. y = 64
  7. z = 0
  8. d = 1
  9.  
  10. xh = x
  11. yh = y
  12. zh = z
  13. dh = d
  14.  
  15. dx = {0, -1, 0, 1}
  16. dz = {1, 0, -1, 0}
  17.  
  18. qSize = 8
  19. qColumns = 5
  20. qRows = 3
  21. qDug = 0
  22. qToDig = qColumns * qRows
  23. qCurrentRow = 1
  24.  
  25. dropping = false
  26.  
  27. --Defining main functions
  28.  
  29. function quarry(xq, zq, size)
  30.   goto(xq, 64, zq, 1)
  31.   repeat down() until turtle.detectDown() or y == 5
  32.   if y == 5 then
  33.     dropoff(zh, yh, zh, dh, true)
  34.   else
  35.     layer(size)
  36.   end
  37.   while y > 5 do
  38.     for i = 1, 3 do
  39.       if y > 5 then
  40.         down()
  41.       end
  42.     end
  43.     layer(size)
  44.     turtle.digUp()
  45.   end
  46.   qDug = qDug + 1
  47.   dropoff(xh, yh, zh, dh, true)
  48. end
  49.  
  50. function layer(size)  
  51.   for i = 1, size do
  52.     for j = 1, size - 1 do
  53.       digQ()
  54.     end
  55.     if i < size then
  56.       if i % 2 == 0 then
  57.         left()
  58.         digQ()
  59.         left()
  60.       else
  61.         right()
  62.         digQ()
  63.         right()
  64.       end
  65.     end
  66.   end
  67.   if size % 2 == 0 then
  68.     right()
  69.   else
  70.     left()
  71.   end      
  72. end
  73.  
  74. function dropoff(xs, ys, zs, ds, new)
  75.   dropping = true
  76.   term.clear()
  77.   term.setCursorPos(1, 1)
  78.   if new then
  79.     print("Done with quarry #", qDug + 1, ".")
  80.   else
  81.     print("Inventory full. Unloading...")
  82.   end
  83.   goto(xh, yh, zh, dh)
  84.   for i = 1, 16 do
  85.     turtle.select(i)
  86.     turtle.drop()
  87.   end
  88.   turtle.select(1)
  89.   if not new then
  90.     goto(xs, ys, zs, ds)
  91.     term.clear()
  92.     term.setCursorPos(1, 1)
  93.     print("Digging quarry #", qDug + 1, "...")
  94.   end
  95.   dropping = false
  96. end
  97.  
  98. function goto(xd, yd, zd, dd)
  99.   while y < yh + 2 do
  100.     up()
  101.   end
  102.   if xd < x then
  103.     repeat left() until d == 1
  104.   elseif xd > x then
  105.     repeat left() until d == 3
  106.   end
  107.   repeat forward() until xd == x
  108.   if zd < z then
  109.     repeat left() until d == 2
  110.   elseif zd > z then
  111.     repeat left() until d == 0
  112.   end
  113.   repeat forward() until z == zd
  114.   repeat down() until y == yd
  115.   repeat left() until d == dd
  116. end
  117.  
  118. --Defining movement functions
  119.  
  120. function forward(amount)
  121.   if not amount then
  122.     amount = 1
  123.   end
  124.   for i = 1, amount do
  125.     repeat turtle.dig() until turtle.forward()
  126.     x = x + dx[d + 1]
  127.     z = z + dz[d + 1]
  128.   end
  129.   if not dropping and turtle.getItemCount(16) > 0 then
  130.      dropoff(x, y, z, d)
  131.   end
  132. end
  133.  
  134. function right()
  135.   turtle.turnRight()
  136.   d = d + 1
  137.   if d == 4 then d = 0 end
  138. end
  139.  
  140. function left()
  141.   turtle.turnLeft()
  142.   d = d - 1
  143.   if d == -1 then d = 3 end
  144. end
  145.  
  146. function turnAround()
  147.   left()
  148.   left()
  149. end
  150.  
  151. function up(amount)
  152.   if not amount then
  153.     amount = 1
  154.   end
  155.   for i = 1, amount do
  156.     repeat turtle.digUp() until turtle.up()
  157.     y = y + 1
  158.   end
  159. end
  160.  
  161. function down(amount)
  162.   if not amount then
  163.     amount = 1
  164.   end
  165.   for i = 1, amount do
  166.     repeat turtle.digDown() until turtle.down()
  167.     y = y - 1
  168.   end
  169. end
  170.  
  171. function digQ()
  172.   repeat until not turtle.digDown()
  173.   repeat until not turtle.digUp()
  174.   forward()
  175. end
  176.  
  177. --Run code
  178.  
  179. while qDug < qToDig do
  180.   local xToDig = -10 - ((math.floor(qDug / qRows)) * (qSize + 1))
  181.   local zToDig = 8 + ((qCurrentRow - 1) * (qSize + 1))
  182.   term.clear()
  183.   term.setCursorPos(1, 1)
  184.   print("Digging quarry #", qDug + 1, "...")
  185.   quarry(xToDig, zToDig, qSize)
  186.   qCurrentRow = qCurrentRow + 1
  187.   if qCurrentRow > qRows then
  188.     qCurrentRow = 1
  189.   end
  190. end
  191.  
  192. term.clear()
  193. term.setCursorPos(1, 1)
  194. print("Done digging ", qDug, " quarries.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement