Advertisement
R167

Turtle Program: Three High Mirrored

Nov 10th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. local t = { ... }
  2.  
  3. local direction = 0
  4. if #t < 2 then
  5.   local programName = shell.getRunningProgram()
  6.   print("Usage: "..fs.getName(programName).." <length> <width>")
  7.   return
  8. end
  9.  
  10. length = tonumber(t[1])
  11. depth = tonumber(t[2])
  12. hits = 0
  13.  
  14. length = length - 1
  15.  
  16. print("Digging...")
  17.  
  18. local function refuel()
  19.   if turtle.getFuelLevel() < 50 then
  20.     turtle.select(1)
  21.     turtle.refuel(1)
  22.   end
  23. end
  24.  
  25. local function unload()
  26.   for n = 1,14 do
  27.     turtle.select(n)
  28.     turtle.drop()
  29.   end
  30. end
  31.  
  32. local function tunnel()
  33.   refuel()
  34.   attacks = 0
  35.   for a = 1,length do
  36.     while not turtle.forward() do
  37.       if turtle.detect() then
  38.         turtle.dig()
  39.       else
  40.         turtle.attack()
  41.         attacks = attacks + 1
  42.       end
  43.     end
  44.     while turtle.detectUp() or turtle.detectDown() do
  45.       if turtle.detectUp() then
  46.         turtle.digUp()
  47.       else
  48.         turtle.digDown()
  49.       end
  50.     end
  51.   end
  52.   return attacks
  53. end
  54.  
  55. local function turnTowards()
  56.   turtle.turnLeft()
  57.   while not turtle.forward() do
  58.     turtle.dig()
  59.   end
  60.   turtle.digUp()
  61.   turtle.digDown()
  62.   turtle.turnLeft()
  63. end
  64.  
  65. local function turnAway()
  66.   turtle.turnRight()
  67.   while not turtle.forward() do
  68.     turtle.dig()
  69.   end
  70.   turtle.digUp()
  71.   turtle.digDown()
  72.   turtle.turnRight()
  73. end
  74.  
  75. turtle.digUp()
  76. turtle.digDown()
  77. hits = tunnel() + hits
  78. for d = 1,(depth-1) do
  79.   if direction == 0 then
  80.     turnTowards()
  81.     direction = 1
  82.   else
  83.     turnAway()
  84.     direction = 0
  85.   end
  86.   hits = tunnel() + hits
  87. end
  88. if direction == 0 then
  89.   turtle.turnLeft()
  90.   turtle.turnLeft()
  91.   for q = 1,length do
  92.     turtle.forward()
  93.   end
  94. end
  95. turtle.turnLeft()
  96. for j = 1,(depth-1) do
  97.   turtle.forward()
  98. end
  99. turtle.turnRight()
  100. unload()
  101. turtle.turnLeft()
  102. turtle.turnLeft()
  103. print("Done digging")
  104.  
  105. if hits > 0 then
  106.   print("I attacked "..hits.." times.")
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement