Advertisement
daFARKA

Minecraft Mining Turtle Strip Mine Program [1.12.2]

Nov 7th, 2020 (edited)
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.53 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. local size = tonumber( tArgs[1] )
  4.  
  5. local offset = 0
  6. if tArgs[2] then
  7.     offset = tonumber( tArgs[2])
  8. end
  9.  
  10. local side = 0
  11. if tArgs[3] then
  12.     local pari3 = tonumber( tArgs[3])
  13.     if pari3 == 1 then
  14.         side = 1
  15.     elseif pari3 == 2 then
  16.         side = 2
  17.     else
  18.         side = 0
  19.     end
  20. end
  21.  
  22. if size < 1 then
  23.     print( "Range of the Tunnel must be positive!" )
  24.     return
  25. end
  26.  
  27. local function slotsLeft()
  28.     local slotsleft=16
  29.     for slot = 1, 16, 1 do
  30.         if turtle.getItemCount(slot) > 0 then
  31.             slotsleft = slotsleft-1
  32.         end
  33.     end
  34.     return slotsleft
  35. end
  36.  
  37. local function dropItems()
  38.     for slot = 1, 16, 1 do
  39.         turtle.select(slot)
  40.         turtle.dropDown()
  41.     end
  42. end
  43.  
  44. local function searchForCoal()
  45.     for slot = 1, 16, 1 do
  46.         local data = turtle.getItemDetail(slot)
  47.         if data then
  48.             if data.name == 'minecraft:coal' then
  49.                 return slot
  50.             end
  51.         end
  52.     end
  53. end
  54.  
  55. if searchForCoal() then
  56.     print(searchForCoal())
  57. end
  58.  
  59.  
  60. local blocksMoved=0
  61. local gotbackbcofInv = false
  62. local gotbackbcofFuel= false
  63. local gotbackbcofSize= false
  64.  
  65. turtle.refuel()
  66. print("Refueled!")
  67. local fuelLevel=turtle.getFuelLevel()
  68. print("FuelLevel: "..fuelLevel)
  69.  
  70. if turtle.getFuelLevel() < size+offset then
  71.     print("Insufficient FuelLevel!")
  72.     return
  73. end
  74.  
  75. local ofs = offset + 20
  76.  
  77. while true do
  78.     while true do
  79.         if offset > 0 then
  80.             for forwardset = 1, offset, 1 do
  81.                 if turtle.getFuelLevel() < blocksMoved+ofs then
  82.                     if searchForCoal() then
  83.                         turtle.select(searchForCoal())
  84.                         turtle.refuel()
  85.                     else
  86.                         gotbackbcofFuel = true
  87.                         print("fuel3!!!")
  88.                         break
  89.                     end
  90.                 end
  91.                 turtle.forward()
  92.             end
  93.             -- If Side = 1 ... right side
  94.             if side==1 then
  95.                 turtle.turnRight()
  96.             -- If Side = 2 ... left side (default)
  97.             else
  98.                 turtle.turnLeft()
  99.             end
  100.         end
  101.         while true do
  102.             if slotsLeft() < 1 then
  103.                 print(slotsLeft())
  104.                 gotbackbcofInv = true
  105.                 break
  106.             end
  107.             if turtle.detectUp() then
  108.                 turtle.digUp()
  109.             elseif turtle.detect() then
  110.                 turtle.dig()
  111.                 turtle.forward()
  112.                 turtle.digUp()
  113.                 blocksMoved=blocksMoved+1
  114.                 if blocksMoved > size then
  115.                     gotbackbcofSize = true
  116.                     break
  117.                 end
  118.                 if turtle.getFuelLevel() < blocksMoved+ofs then
  119.                     if searchForCoal() then
  120.                         turtle.select(searchForCoal())
  121.                         turtle.refuel()
  122.                     else
  123.                         gotbackbcofFuel = true
  124.                         print("fuel3!!!")
  125.                         break
  126.                     end
  127.                 end
  128.             else
  129.                 turtle.forward()
  130.                 blocksMoved=blocksMoved+1
  131.                 if blocksMoved > size then
  132.                     gotbackbcofSize = true
  133.                     break
  134.                 end
  135.                 if turtle.getFuelLevel() < blocksMoved+ofs then
  136.                     if searchForCoal() then
  137.                         turtle.select(searchForCoal())
  138.                         turtle.refuel()
  139.                     else
  140.                         gotbackbcofFuel = true
  141.                         print("fuel3!!!")
  142.                         break
  143.                     end
  144.                 end
  145.             end
  146.             print(turtle.getFuelLevel())
  147.         end
  148.  
  149.         -- Initiating the going back
  150.         turtle.turnLeft()
  151.         turtle.turnLeft()
  152.  
  153.         for moves = 1, blocksMoved, 1 do
  154.             turtle.forward()
  155.         end
  156.         if offset > 0 then
  157.             if side==1 then
  158.                 turtle.turnLeft()
  159.             else
  160.                 turtle.turnRight()
  161.             end
  162.         end
  163.         for forwardset = 1, offset, 1 do
  164.             turtle.forward()
  165.         end
  166.         dropItems()
  167.         if gotbackbcofSize then
  168.             break
  169.         end
  170.         if gotbackbcofInv then
  171.             break
  172.         end
  173.         if gotbackbcofFuel then
  174.             break
  175.         end
  176.     end
  177.     if gotbackbcofSize then
  178.         break
  179.     end
  180.     if gotbackbcofFuel then
  181.         break
  182.     else
  183.         turtle.turnLeft()
  184.         turtle.turnLeft()
  185.         blocksMoved = 0
  186.     end
  187. end
  188.  
  189. turtle.turnLeft()
  190. turtle.turnLeft()
  191. turtle.select(1)
  192. print("Mining finished!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement