ThSchm

StripminerSimple

Aug 17th, 2014
295
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. end
  88.  
  89. local function DigRow()
  90.   turtle.dig()
  91.   forward()
  92.   turtle.digDown()
  93.   turtle.digUp()      
  94. end
  95.  
  96. local function EmptyInventory()
  97.   if not turtle.detect() then
  98.     print("No Block to place items into")
  99.     return
  100.   end
  101.   -- Fuel is in slot 1, never empty this
  102.   for i = 2, 16 do
  103.     turtle.select(i)
  104.     turtle.drop()
  105.   end
  106.   print("Inventory successfully emptied")
  107. end
  108.  
  109. local function FirstMining(amount)
  110.   for i = 1, amount do
  111.     if ContinueDigging() then
  112.       DigRow()
  113.       digDeepAmount = digDeepAmount + 1
  114.     else
  115.       break
  116.     end
  117.   end
  118.  
  119.   turtle.turnLeft()
  120.   turtle.turnLeft()
  121.   while (digDeepAmount > 1) do
  122.     forward()
  123.     digDeepAmount = digDeepAmount - 1
  124.   end  
  125.   turtle.turnLeft()
  126.   turtle.turnLeft()
  127. end
  128.  
  129. local function MiningLoop(amount)
  130.   for i = 1, amount do
  131.     stripeIndex = i
  132.     FirstMining(digDeepAmount)
  133.     if continueDigging() then
  134.       print("Successfully mined stripe #"..i)
  135.     else
  136.       print("Full inventory, aborted mining stripe #"..i)
  137.       break
  138.     end
  139.  
  140.     if (i < amount) then
  141.       turtle.turnRight()
  142.       for j = 1, 3 do
  143.           forward()
  144.       end
  145.     turtle.turnLeft()
  146.     end
  147.   end
  148.  
  149.   turtle.turnLeft()
  150.   for i = 1, (stripeIndex - 1) * 3 do
  151.     forward()
  152.   end
  153.   turtle.turnRight()
  154. end
  155.  
  156. FindChest()
  157. mineToBase(digDownAmount)
  158. MiningLoop(stripeAmount)
  159. moveToTop(digDownAmount)
  160. EmptyInventory()
  161. print ("Run successfully!")
Advertisement
Add Comment
Please, Sign In to add comment