dealingwith

better_cube_clearer

Nov 16th, 2020 (edited)
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 0 0
  1. function fuel()
  2.   if turtle.getFuelLevel() < 30 then
  3.     turtle.select(1)
  4.     if turtle.refuel(1) then
  5.       return true
  6.     end
  7.     print("Refuelling failed.")
  8.     return false
  9.   end
  10. end
  11.  
  12. function right()
  13.   turtle.turnRight()
  14. end
  15.  
  16. function left()
  17.   turtle.turnLeft()
  18. end
  19.  
  20. function forward()
  21.   while not turtle.forward() do
  22.     if not turtle.dig() then
  23.       turtle.attack()
  24.     end
  25.   end
  26. end
  27.  
  28. function up()
  29.   while not turtle.up() do
  30.     digUp()
  31.   end
  32. end
  33.  
  34. function down()
  35.   while not turtle.down() do
  36.     digDown()
  37.   end
  38. end
  39.  
  40. function shiftRight()
  41.   right()
  42.   forward()
  43.   left()
  44. end
  45.  
  46. function shiftLeft()
  47.   left()
  48.   forward()
  49.   right()
  50. end
  51.  
  52. function shiftNRight(n)
  53.   right()
  54.   for i=1,n,1 do
  55.     forward()
  56.   end
  57.   left()
  58. end
  59.  
  60. function shiftNLeft(n)
  61.   left()
  62.   for i=1,n,1 do
  63.     forward()
  64.   end
  65.   right()
  66. end
  67.  
  68. function dig()
  69.   if turtle.detect() then
  70.     turtle.dig()
  71.   end
  72. end
  73.  
  74. function digUp()
  75.   if turtle.detectUp() then
  76.     turtle.digUp()
  77.   end
  78. end
  79.  
  80. function digDown()
  81.   if turtle.detectDown() then
  82.     turtle.digDown()
  83.   end
  84. end
  85.  
  86. function dump(start_point,end_point)
  87.   for i=start_point,end_point,1 do
  88.     turtle.select(i)
  89.     turtle.drop()
  90.   end
  91. end
  92.  
  93. function find(id)
  94.   for i=1,16,1 do
  95.     local data = turtle.getItemDetail(i)
  96.     if data and data.name == id then
  97.       return i
  98.     end
  99.   end
  100.   return 0
  101. end
  102.  
  103. function turnAround()
  104.   right()
  105.   right()
  106. end
  107.  
  108. function fif(val, a, b)
  109.   if val then a() else b() end
  110. end
  111.  
  112. function fifFlip(val, a, b)
  113.   if val then a() else b() end
  114.   return not val
  115. end
  116.  
  117. function move(len)
  118.   for i=1,len,1 do
  119.     fuel()
  120.     forward()
  121.   end
  122. end
  123.  
  124. function digRow(depth)
  125.   moved_depth = 0
  126.   while moved_depth < depth do
  127.     fuel()
  128.     dig()
  129.     forward()
  130.     moved_depth = moved_depth + 1
  131.     digUp()
  132.     digDown()
  133.   end
  134. end
  135.  
  136. term.write("Insert depth: ")
  137. depth = tonumber(read())
  138. print(" ")
  139.  
  140. term.write("Insert width: ")
  141. width = tonumber(read())
  142. print(" ")
  143.  
  144. term.write("Insert height: ")
  145. height = tonumber(read())
  146. print(" ")
  147.  
  148. moved_height = 0
  149. up()
  150. front = true
  151.  
  152. for i=1,width,1 do
  153.   while moved_height < height + 1 do
  154.     digRow(depth)
  155.     turnAround()
  156.     up()
  157.     up()
  158.     up()
  159.     moved_height = moved_height + 3
  160.     if front then
  161.         front = false
  162.     else
  163.         front = true
  164.     end
  165.   end
  166.   for i=1,moved_height,1 do
  167.     down()
  168.   end
  169.   moved_height = 0
  170.   if front then
  171.     shiftRight()
  172.   else
  173.     shiftLeft()
  174.   end
  175. end
Advertisement
Add Comment
Please, Sign In to add comment