SHARE
TWEET

miningUtil.lua

a guest Feb 14th, 2020 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkForBedrockFront()
  2.     local success, data = turtle.inspect()
  3.     if data.name == 'minecraft:bedrock' then
  4.         print('Bedrock reached, program stopped')
  5.         while true do
  6.         end
  7.     end
  8. end
  9.  
  10. function checkForBedrockDown()
  11.     local success, data = turtle.inspectDown()
  12.     if data.name == 'minecraft:bedrock' then
  13.         print('Bedrock reached, program stopped')
  14.         while true do
  15.         end
  16.     end
  17. end
  18.  
  19. function turnAroundRight()
  20.     turtle.turnRight()
  21.     repeat
  22.         checkForBedrockFront()
  23.         turtle.dig()
  24.         checkInventoryFull()
  25.     until(turtle.forward())
  26.     turtle.digUp()
  27.     checkInventoryFull()
  28.     turtle.digDown()
  29.     checkInventoryFull()
  30.     turtle.turnRight()
  31.     checkFuel()
  32. end
  33.  
  34. function turnAroundLeft()
  35.     turtle.turnLeft()
  36.     repeat
  37.         checkForBedrockFront()
  38.         turtle.dig()
  39.         checkInventoryFull()
  40.     until(turtle.forward())
  41.     turtle.digUp()
  42.     checkInventoryFull()
  43.     turtle.digDown()
  44.     checkInventoryFull()
  45.     turtle.turnLeft()
  46.     checkFuel()
  47. end
  48.  
  49. function checkInventoryFull()
  50.     -- search for empty slot
  51.     for slot = 3, 16, 1 do
  52.         if turtle.getItemCount(slot) == 0 then
  53.             return
  54.         end
  55.     end
  56.    
  57.     -- empty inventory into ender chest
  58.     turtle.select(1)
  59.     turtle.placeUp()
  60.     for slot = 3, 16, 1 do
  61.         turtle.select(slot)
  62.         turtle.refuel()
  63.         while not turtle.dropUp() and turtle.getItemCount(slot) ~= 0 do -- wait if chest is full
  64.             print('Waiting for ender chest to become empty...')
  65.         end
  66.         term.clear()
  67.     end
  68.     turtle.select(1)
  69.     turtle.digUp()
  70. end
  71.  
  72. function checkFuel()
  73.     local fuelLevel = turtle.getFuelLevel()
  74.    
  75.     if fuelLevel < 5 then
  76.         -- check for fuel in inventory
  77.         for slot = 3, 16, 1 do
  78.             turtle.select(slot)
  79.             if turtle.refuel() then
  80.                 return
  81.             end
  82.         end
  83.        
  84.         -- get fuel from ender chest
  85.         turtle.select(2)
  86.         turtle.placeUp()
  87.         turtle.select(3)
  88.         while not turtle.suckUp() do    -- wait if chest is empty
  89.             print('Waiting for fuel to become available...')
  90.         end
  91.         term.clear()
  92.         turtle.select(2)
  93.         turtle.digUp()
  94.        
  95.         -- get gathered fuel from inventory
  96.         for slot = 3, 16, 1 do
  97.             turtle.select(slot)
  98.             if turtle.refuel() then
  99.                 return
  100.             end
  101.         end
  102.     end
  103. end
  104.  
  105. function digAndMoveForward()
  106.     repeat
  107.         checkForBedrockFront()
  108.         turtle.dig()
  109.         checkInventoryFull()
  110.     until(turtle.forward())
  111.     turtle.digUp()
  112.     checkInventoryFull()
  113.     turtle.digDown()
  114.     checkInventoryFull()
  115.     checkFuel()
  116. end
  117.  
  118. function digAndMoveDown()
  119.     repeat
  120.         checkForBedrockDown()
  121.         turtle.digDown()
  122.         checkInventoryFull()
  123.     until(turtle.down())
  124.     turtle.digDown()
  125.     checkInventoryFull()
  126.     checkFuel()
  127. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top