ThSchm

StripminerSimple2

Aug 17th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArgs = { ... }
  2.  
  3. local digDownAmount
  4. local digDeepAmount
  5. local stripeAmount
  6.  
  7. local fuelSlot = 1
  8.  
  9. local stripeIndex = 1
  10. local digDeepIndex = 1
  11.  
  12. if not (#tArgs == 3) then
  13.   print ("You need exactly three parameter!")
  14.   return
  15. else
  16.   digDownAmount = tonumber(tArgs[1])
  17.   digDeepAmount = tonumber(tArgs[2])
  18.   stripeAmount = tonumber(tArgs[3])
  19. end
  20.  
  21. local function forward()
  22.   while not turtle.forward() do
  23.     if not turtle.dig() then
  24.       turtle.attack()
  25.       sleep(0.5)
  26.     end
  27.   end
  28. end
  29.  
  30. local function up()
  31.   while not turtle.up() do
  32.     if not turtle.digUp() then
  33.       turtle.attackUp()
  34.       sleep(0.5)
  35.     end
  36.   end
  37. end
  38.  
  39. local function down()
  40.   while not turtle.down() do
  41.     if not turtle.digDown() then
  42.       turtle.attackDown()
  43.       sleep(0.5)
  44.     end
  45.   end
  46. end
  47.  
  48. local function FindChest()
  49.   while not ChestFound do
  50.     for i = 1, 4 do
  51.       if turtle.detect() then
  52.         print("Chest found... starting mine operation!")
  53.         return
  54.       else
  55.         turtle.turnRight()
  56.       end
  57.     end
  58.     print("No Chest found.. place a chest near turtle to start mining")
  59.     sleep(3)
  60.   end
  61. end
  62.  
  63. local function mineToBase(amount)
  64.   turtle.select(fuelSlot + 1)
  65.   for i = 1, amount do
  66.     down()
  67.     turtle.placeUp()
  68.   end
  69.   print("Arrived at mining level.. start mining")
  70. end
  71.  
  72. local function moveToTop(amount)
  73.   turtle.select(fuelSlot + 1)
  74.   for i = 1, amount do
  75.     up()
  76.     turtle.placeDown()
  77.   end
  78.   print("Arrived at starting level.. empting inventory")
  79. end
  80.  
  81. -- Returns false if inventory full
  82. local function ContinueDigging()
  83.   -- Check inventory
  84.   if (turtle.getItemCount(16) > 0) then
  85.     return false
  86.   end
  87.  
  88.   return true
  89. end
  90.  
  91. local function CheckFuel()
  92.   if (turtle.getFuelLevel() >= 100) then
  93.     return true
  94.   else
  95.     local oldSlot = turtle.getSelectedSlot()
  96.     turtle.select(FuelSlot)
  97.     if turtle.refuel(100)
  98.       turtle.select(oldSlot)
  99.       return true
  100.     else
  101.       turtle.select(oldSlot)
  102.       return false
  103.     end
  104.   end
  105. end
  106.  
  107. local function DigRow()
  108.   turtle.dig()
  109.   forward()
  110.   turtle.digDown()
  111.   turtle.digUp()      
  112. end
  113.  
  114. local function EmptyInventory()
  115.   if not turtle.detect() then
  116.     print("No Block to place items into")
  117.     return
  118.   end
  119.   -- Fuel is in slot 1, never empty this
  120.   for i = 2, 16 do
  121.     turtle.select(i)
  122.     turtle.drop()
  123.   end
  124.   print("Inventory successfully emptied")
  125. end
  126.  
  127. local function FirstMining(amount)
  128.   for i = 1, amount do
  129.     if ContinueDigging() and CheckFuel() then
  130.       DigRow()
  131.       digDeepIndex = digDeepIndex + 1
  132.       print("digDeepIndex = "..digDeepIndex)
  133.     else
  134.       break
  135.     end
  136.   end
  137.  
  138.   turtle.turnLeft()
  139.   turtle.turnLeft()
  140.   while (digDeepIndex > 1) do
  141.     forward()
  142.     digDeepIndex = digDeepIndex - 1
  143.   end  
  144.   turtle.turnLeft()
  145.   turtle.turnLeft()
  146. end
  147.  
  148. local function MiningLoop(amount)
  149.   for i = 1, amount do
  150.     stripeIndex = i
  151.     FirstMining(digDeepAmount)
  152.     if ContinueDigging() and CheckFuel() then
  153.       print("Successfully mined stripe #"..i)
  154.     else
  155.       print("Full inventory or out of fuel, aborted mining stripe #"..i)
  156.       break
  157.     end
  158.  
  159.     if (i < amount) then
  160.       turtle.turnRight()
  161.       for j = 1, 3 do
  162.           forward()
  163.       end
  164.     turtle.turnLeft()
  165.     end
  166.   end
  167.  
  168.   turtle.turnLeft()
  169.   for i = 1, (stripeIndex - 1) * 3 do
  170.     forward()
  171.   end
  172.   turtle.turnRight()
  173. end
  174.  
  175. FindChest()
  176. mineToBase(digDownAmount)
  177. MiningLoop(stripeAmount)
  178. moveToTop(digDownAmount)
  179. EmptyInventory()
  180. print ("Run successfully!")
Advertisement
Add Comment
Please, Sign In to add comment