Advertisement
Guest User

mine.lua

a guest
Mar 24th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. if #tArgs == 0 then
  4.   print("Usage: <distance>")
  5.   return
  6. end
  7.  
  8. blocks = 0
  9. totalDist = 0
  10.  
  11. local function refuel()
  12.   slot = turtle.getSelectedSlot()
  13.   turtle.select(1)
  14.   if (turtle.getItemCount(1) == 1) then
  15.     return false
  16.   end
  17.   turtle.refuel(turtle.getItemCount(1) - 1)
  18.   turtle.select(slot)
  19.   return true
  20. end
  21.  
  22. local function printStatus()
  23.   term.clear()
  24.   print("Status: {")
  25.   print("  Distance Covered: " .. totalDist)
  26.   print("  Blocks excavated: " .. blocks)
  27.   print("  Fuel Remaining: " .. turtle.getFuelLevel())
  28.   print("}")
  29. end
  30.  
  31. local function moveForward()
  32.   if (turtle.forward() == false) then
  33.     while turtle.dig() do
  34.       blocks = blocks+1
  35.       printStatus()
  36.     end
  37.     if (turtle.forward() == false) then
  38.       if (turtle.getFuelLevel() == 0 and refuel() == false) then
  39.         print("The turtle is out of fuel.")
  40.         return false
  41.       else
  42.         print("The turtle is blocked.")
  43.         return false
  44.       end
  45.     end
  46.   end
  47.   printStatus()
  48.   return true
  49. end
  50.  
  51. local function moveUp()
  52.   if (turtle.up() == false) then
  53.     while turtle.digUp() do
  54.     end
  55.     if (turtle.up() == false) then
  56.       if (turtle.getFuelLevel() == 0 and refuel() == false) then
  57.         print("The turtle has ran out of fuel.")
  58.         return false
  59.       else
  60.         print("The turtle is blocked.")
  61.         return false
  62.       end
  63.     end
  64.   end
  65.   return true
  66. end
  67.  
  68. local function digForward()
  69.   while turtle.dig() do
  70.     blocks=blocks+1
  71.     printStatus()
  72.   end
  73. end
  74.  
  75. local function full()
  76.   for i = 1, 16 do
  77.     if (turtle.getItemCount(i) == 0) then
  78.       return false
  79.     end
  80.   end
  81.   return true
  82. end
  83.  
  84. local function unload()
  85.   for i = 2, 16 do
  86.     turtle.select(i)
  87.     turtle.dropDown()
  88.   end
  89. end
  90.  
  91. local function startUnload()
  92.   for i = 1, totalDist do
  93.     turtle.back()
  94.   end
  95.   unload()
  96. end
  97.  
  98. local function digSides()
  99.   turtle.turnLeft()
  100.   digForward(blocks)
  101.   if (turtle.digDown()) then blocks=blocks+1 end
  102.   turtle.down()
  103.   printStatus()
  104.   digForward(blocks)
  105.   if (turtle.digDown()) then blocks=blocks+1 end
  106.   turtle.down()
  107.   printStatus()
  108.   digForward(blocks)
  109.   turtle.turnLeft()
  110.   turtle.turnLeft()
  111.   digForward(blocks)
  112.   turtle.up()
  113.   printStatus()
  114.   digForward(blocks)
  115.   turtle.up()
  116.   printStatus()
  117.   digForward(blocks)
  118.   turtle.turnLeft()
  119. end
  120.  
  121. local function mine(distance)
  122.   for i=1,distance do
  123.     if (full()) then startUnload() end
  124.     moveForward(blocks)
  125.     totalDist = totalDist+1
  126.     digSides(blocks)
  127.   end
  128.   printStatus()
  129.   startUnload(distance)
  130. end
  131.  
  132. local distance = tonumber(tArgs[1])
  133.  
  134. while distance > 0 do
  135.   for i=1,totalDist do turtle.forward() end
  136.   mine(distance, totalDist)
  137.   print("Enter the new Distance: ")
  138.   distance = tonumber(read())
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement