DeepFriedBabeez

CC TurtleQuarry

May 8th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. length = 0
  2. width = 0
  3. depth = 0
  4.  
  5.  
  6. --functions--
  7.  
  8. function clr()
  9.     term.clear()
  10.     term.setCursorPos(1,1)
  11. end
  12.  
  13. function forward(units)
  14.     for i=0, units do
  15.         while (turtle.forward() == false) do
  16.             turtle.dig()
  17.             turtle.attack()
  18.         end
  19.  
  20.         if (facing == 0) then
  21.             currentY = currentY + 1
  22.         elseif (facing == 1) then
  23.             currentX = currentX + 1
  24.         elseif (facing == 2) then
  25.             currentY = currentY - 1
  26.         elseif (facing == 3) then
  27.             currentX = currentX - 1
  28.         end
  29.  
  30.         if (turtle.getItemCount(12) == 0) then
  31.             dump(currentX, currentY, currentZ, facing)
  32.         end
  33.        
  34.     end
  35. end
  36.  
  37. function right(units)
  38.     for i=0, units do
  39.         turtle.turnRight()
  40.         facing = facing + 1
  41.         if (facing > 3) then
  42.             facing = 0
  43.         end
  44.     end
  45. end
  46.  
  47. function left(units)
  48.     for i=0, units do
  49.         turtle.turnLeft()
  50.         facing = facing - 1
  51.         if (facing < 0) then
  52.             facing = 3
  53.         end
  54.     end
  55. end
  56.  
  57. function up(units)
  58.     for i=0, units do
  59.         while (turtle.up() == false) do
  60.             turtle.digUp()
  61.             turtle.attackUp()
  62.         end
  63.         currentZ = currentZ + 1
  64.     end
  65. end
  66.  
  67. function down(units)
  68.     for i=0, units do
  69.         while (turtle.down() == false) do
  70.             turtle.digDown()
  71.             turtle.attackDown()
  72.         end
  73.         currentZ = currentZ - 1
  74.     end
  75. end
  76.  
  77. function dump(xPos, yPos, zPos, dir)
  78.     while (facing ~= 2) do
  79.         right(1)
  80.     end
  81.     up(zPos)
  82.     forward(yPos)
  83.    
  84.     if (xPos > 0) then
  85.         right(1)
  86.         forward(xPos)
  87.         left(1)
  88.     elseif (xPos < 0) then
  89.         left(1)
  90.         forward(-xPos)
  91.         right(1)
  92.     end
  93.  
  94.  
  95.     for i=1, 16 do
  96.         turtle.select(i)
  97.         turtle.drop()
  98.     end
  99.    
  100.     turtle.select(1)
  101.  
  102.     if (dir ~= -1) then
  103.         right(2)
  104.  
  105.         if (xPos > 0) then
  106.             right(1)
  107.             forward(xPos)
  108.             left(1)
  109.         elseif (xPos < 0) then
  110.             left(1)
  111.             forward(-xPos)
  112.             right(1)
  113.         end
  114.  
  115.         forward(yPos)
  116.         down(zPos)
  117.    
  118.         while (facing ~= dir) do
  119.             right(1)
  120.         end
  121.     end
  122. end
  123.  
  124.  
  125.  
  126. function dump()
  127.     for i=1, 16 do
  128.         turtle.select(i)
  129.         turtle.drop()
  130.     end
  131.    
  132.     turtle.select(1)
  133. end
  134.  
  135.  
  136.  
  137.  
  138.  
  139. --variables--
  140.  
  141. currentX = 0
  142. currentY = 0
  143. currentZ = 0
  144. facing = 0  --0 relative north, 1 relative east, 2 relative south, 3 relative west
  145.  
  146. move = 0 --determines whether to go left or right
  147.  
  148. --main--
  149.  
  150. --using standard zig zag, goes down 1 after each layer (will include offset later?)
  151.  
  152. for d=0, depth do
  153.     for l=0, length do
  154.         if (move % 2 == 0) then
  155.             left(1)
  156.             forward(width)
  157.             right(1)
  158.         else
  159.             right(1)
  160.             forward(width)
  161.             left(1)
  162.         end
  163.        
  164.         if (l ~= length) then
  165.             forward(1)
  166.         end
  167.        
  168.         move = move + 1
  169.     end
  170.  
  171.     down(1)
  172.     right(2)
  173.  
  174. end
  175.  
  176. dump(currentX, currentY, currentZ, -1)
  177.  
  178. print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment