gravityio

stripmine.lua

Jan 13th, 2021
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. local arg = ...
  2.  
  3. local dist = 0
  4. local maxInv = 16
  5.  
  6. local function Refuel()
  7.     for i = 1, maxInv do
  8.         turtle.select(i)
  9.         turtle.refuel(64)
  10.     end
  11. end
  12.  
  13. local function Dig(distance)
  14.     for i = 1, distance do
  15.         turtle.dig()
  16.         turtle.forward()
  17.         turtle.digUp()
  18.         turtle.digDown()
  19.     end
  20. end
  21.  
  22. local function Return(distance)
  23.     for i = 1, distance do
  24.         turtle.back()
  25.     end
  26. end
  27.  
  28. local function TurtleCount()
  29.     local count = 0
  30.     local slots = {}
  31.     for i = 1, maxInv do
  32.         local item = turtle.getItemDetail(i)
  33.         if item ~= nil and item.name == "computercraft:turtle_normal" then
  34.              count = count + 1
  35.              table.insert(slots, i)
  36.         end
  37.     end
  38.     return count, slots
  39. end
  40.  
  41. local function Miner()
  42.     Dig(dist)
  43.     Return(dist)
  44. end
  45.  
  46. local function Captain()
  47.     turtle.turnLeft()
  48.     local turtleCount, turtleSlots = TurtleCount()
  49.  
  50.     for i = 1, turtleCount - 1 do
  51.         turtle.forward()
  52.     end
  53.     turtle.select(turtleSlots[1])
  54.     turtle.place()
  55.     for i = 1, turtleCount - 1 do
  56.         turtle.back()
  57.         turtle.select(turtleSlots[turtleCount - i])
  58.         turtle.place()
  59.     end
  60.  
  61.     turtle.turnRight()
  62.  
  63.     Miner()
  64. end
  65.  
  66. local function ProcArgs()
  67.     if arg ~= nil then
  68.         if string.lower(arg) == "captain" then Captain() return end
  69.     end
  70.  
  71.     Miner()
  72. end
  73.  
  74. local function ReadDistance()
  75.     while true do
  76.         write("Enter distance: ")
  77.         dist = tonumber(read())
  78.         if dist ~= 0 then break end
  79.     end
  80. end
  81.  
  82. local function Init()
  83.     ReadDistance()
  84.     ProcArgs()
  85. end
  86.  
  87. Init()
  88.  
  89.  
Add Comment
Please, Sign In to add comment