Guest User

StripminerSimple2

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