Advertisement
JustMark

Matas Tunnel Bore

Jul 10th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.73 KB | None | 0 0
  1. local layerPairs = nil
  2.  
  3. local maxLayer = 0
  4.  
  5. local inPosition = false
  6.  
  7. function dropItems()
  8.      for x = 2, 16 do
  9.          turtle.select(x)  
  10.          turtle.drop(64)
  11.      end
  12. end
  13.  
  14. function checkCoal()
  15.     bendzoKiekis = turtle.getFuelLevel()
  16.    
  17.     if bendzoKiekis==0 then
  18.         turtle.select(1)
  19.         while not turtle.refuel(1) do
  20.             print('out of fuel')
  21.             sleep(1)
  22.         end
  23.     end
  24.  
  25.    
  26. end
  27. function moveForward(force)
  28.      checkCoal()
  29.  
  30.     if force == true then
  31.         while turtle.detect() do
  32.             turtle.dig()
  33.         end
  34.     end
  35.    
  36.      return turtle.forward()
  37. end
  38.  
  39. function moveUp(force)
  40.     checkCoal()
  41.    
  42.     if force == true then
  43.         while turtle.detectUp() do
  44.             turtle.digUp()
  45.         end
  46.     end
  47.  
  48.     return turtle.up()
  49. end
  50.  
  51. function moveDown(force)
  52.     checkCoal()
  53.  
  54.     if force == true then
  55.         while turtle.detectDown() do
  56.             turtle.digDown()
  57.         end
  58.     end
  59.  
  60.     return turtle.down()
  61. end
  62.  
  63. function digForward()
  64.     turtle.dig()
  65.     moveForward(true)
  66. end    
  67.  
  68. function digUp()
  69.     turtle.digUp()
  70.     moveUp(true)
  71. end
  72.  
  73. function digDown()
  74.     turtle.digDown()
  75.     moveDown(true)
  76. end
  77.  
  78. function digTwoColumns()
  79.     for y = 1, 3 do
  80.         digUp()    
  81.     end
  82.  
  83.     digForward()
  84.  
  85.     for y = 1, 3 do
  86.         digDown()
  87.     end
  88. end
  89.  
  90. function digFourColumns()
  91.     digTwoColumns()
  92.     digForward()
  93.     digTwoColumns()
  94. end
  95.  
  96. function digTwoLayers()
  97.     digForward()
  98.     turtle.turnRight()
  99.  
  100.     digFourColumns()
  101.  
  102.     turtle.turnLeft()
  103.     digForward()
  104.     turtle.turnLeft()
  105.  
  106.     digFourColumns()
  107.  
  108.     turtle.turnRight()
  109.  
  110.     maxLayer = maxLayer + 2
  111. end
  112.  
  113. function reachMaxLayer()
  114.     while moveForward(false) do
  115.         maxLayer = maxLayer + 1
  116.     end
  117.  
  118.     inPosition = true
  119. end
  120.  
  121. function goMining()
  122.     if inPosition == true then
  123.         inPosition = false
  124.     else
  125.         for i = 1, maxLayer do
  126.             moveForward(true)
  127.         end
  128.     end
  129.  
  130.     for i = 1, layerPairs do
  131.         digTwoLayers()
  132.     end
  133. end
  134.  
  135. function goTakeCoal()
  136.     moveUp(true)
  137.     turtle.select(1)
  138.  
  139.     hasFuel = turtle.getItemCount(1)
  140.     needCount = 64 - hasFuel
  141.  
  142.     while not turtle.suck(needCount) do
  143.         print('please put fuel in the chest')
  144.         sleep(1)
  145.     end
  146.  
  147.     moveDown(true)
  148. end
  149.  
  150. function goStoreItems()
  151.     turtle.turnRight()
  152.     turtle.turnRight()
  153.  
  154.     for i = 1, maxLayer do
  155.         moveForward(true)
  156.     end
  157.  
  158.     dropItems()
  159.    
  160.     goTakeCoal()   
  161.  
  162.     turtle.turnRight()
  163.     turtle.turnRight()
  164. end
  165.  
  166. print('How many layer pairs should I dig per session? ')
  167. local input = nil
  168.  
  169. while true do
  170.     input = tonumber(read())
  171.  
  172.     if (input == nil) or (math.floor(input) ~= input) then
  173.         print('input should be an integer.')
  174.     else
  175.         layerPairs = input
  176.         term.clear()
  177.         break
  178.     end
  179. end        
  180.  
  181. goStoreItems()
  182. reachMaxLayer()
  183.  
  184. while true do
  185.     goMining()
  186.     goStoreItems()
  187. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement