Advertisement
GladdeSnaak

Miner

Apr 26th, 2021 (edited)
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1.  
  2. function checkFuel()
  3.     repcount = 0
  4.     fuelLevel = turtle.getFuelLevel()
  5.         while fuelLevel <= 10 and repcount <= 5000 do
  6.             for i = 1,16 do
  7.                 turtle.select(i)
  8.                 itemInfo = turtle.getItemDetail()
  9.                     if itemInfo ~= nil then
  10.                         if itemInfo.name == "minecraft:coal" then
  11.                             turtle.refuel()
  12.                             print("Refueled ", itemInfo["count"], " coal from slot", i)
  13.                             break
  14.                         end
  15.                     end
  16.             end
  17.             fuelLevel = turtle.getFuelLevel()
  18.             repcount = repcount + 1
  19.         end
  20. end
  21.  
  22.  
  23. function selectChest()
  24.     hasChest = false
  25.         for i = 1,16 do
  26.             turtle.select(i)
  27.             itemInSlot = turtle.getItemDetail()
  28.                 if itemInSlot ~= nil then
  29.                     if itemInSlot.name == "minecraft:chest" then   
  30.                         hasChest = true
  31.                         turtle.digDown()
  32.                         turtle.placeDown()
  33.                         break
  34.                     end
  35.                 end
  36.         end
  37.     if hasChest == false then
  38.     print("No chest in system, inventory is full, put a chest in the inventory")
  39.     sleep(10)
  40.     selectChest()
  41.    
  42.     end
  43. end
  44.  
  45.  
  46.  
  47. function checkInventory()
  48.     isFull = true
  49.     itemSelect = 1
  50.     turtle.select(itemSelect)
  51.         for i = 1,16 do
  52.             itemInSlot = turtle.getItemDetail(i)
  53.                 if itemInSlot == nill then 
  54.                 isFull = false
  55.                 break
  56.                 end
  57.         end
  58.     if isFull == true then
  59.         print("inventory is full, searching for chest to dump items")
  60.         selectChest()
  61.         dumpItems()
  62.     end
  63. end
  64.  
  65.  
  66. function dumpItems()
  67.         for i = 1,16 do
  68.             turtle.select(i)
  69.             itemInfo = turtle.getItemDetail()
  70.             if itemInfo ~= nil then
  71.                     if itemInfo.name == "minecraft:chest" or itemInfo.name == "mincraft:coal" then
  72.                         print("This item in slot", i, "won't be dropped")
  73.                         else
  74.                             turtle.dropDown()
  75.                     end
  76.             end
  77.         end
  78. end
  79.  
  80.            
  81. function fwd()
  82.     turtle.digUp()
  83.     while turtle.forward() == false do
  84.     turtle.dig()
  85.     turtle.attack()
  86.     checkFuel()
  87.     checkInventory()
  88.     end
  89.     turtle.digUp()
  90.     turtle.digDown()
  91. end
  92.  
  93. function lfd()
  94.     turtle.turnLeft()
  95.     while turtle.forward() == false do
  96.     turtle.dig()
  97.     turtle.attack()
  98.     checkFuel()
  99.     checkInventory()
  100.     end
  101.     turtle.digUp()
  102.     turtle.digDown()
  103. end
  104.  
  105. function rfd()
  106.     turtle.turnRight()
  107.     while turtle.forward() == false do
  108.     turtle.dig()
  109.     turtle.attack()
  110.     checkFuel()
  111.     checkInventory()
  112.     end
  113.     turtle.digUp()
  114.     turtle.digDown()
  115. end
  116.  
  117.  
  118. function initiate()
  119.  
  120. print("How wide should the turtle go?")
  121. width = tonumber(read())
  122.  
  123. print("How deep should the turtle go?")
  124. depth = tonumber(read())-1
  125.  
  126. dig(width, depth)
  127.  
  128. end
  129.  
  130.  
  131.  
  132. function dig(width, depth)
  133. row = 1
  134. for i = 1,depth do
  135.             fwd()
  136.             end
  137.             row = 2
  138.     while row-1 <= width do
  139.             for i = 2,depth do
  140.             fwd()
  141.             end
  142.         print("Row",row, "is finshed")
  143.         rfd()
  144.         rfd()
  145.         row = row + 1
  146.        
  147.             for i = 2,depth do
  148.                 fwd()
  149.             end
  150.         lfd()
  151.         lfd()
  152.         row = row+1
  153.     end
  154.     fwd()
  155. end
  156.  
  157. function setCords()
  158.  
  159. end
  160.  
  161. initiate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement