Advertisement
Guest User

quarry

a guest
Jul 24th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. arg = {...}
  2.  
  3. if arg[1] ~= nil and arg[2] ~= nil then
  4.   width = arg[1]
  5.   length = arg[2]
  6. else
  7.   term.setTextColor(colors.red)
  8.   print("usage: quarry <width> <length>")
  9. end
  10.  
  11. x = 0
  12. z = 0
  13. y = 0
  14. facing = 0
  15.  
  16. function refuel()
  17.   if turtle.getFuelLevel() < 5 then
  18.     turtle.refuel(1)
  19.     return true
  20.   end
  21. end
  22.  
  23. function step()
  24.   while not turtle.forward() do
  25.     if not refuel() then
  26.       if turtle.detect() then
  27.         turtle.dig()
  28.       else
  29.         turtle.attack()
  30.       end
  31.     end
  32.   end
  33.   if facing == 0 then z = z + 1 end
  34.   if facing == 2 then z = z - 1 end
  35.   if facing == 1 then x = x + 1 end
  36.   if facing == 3 then x = x - 1 end
  37. end
  38.  
  39. function up()
  40.   while not turtle.up() do
  41.     if not refuel() then
  42.       if turtle.detectUp() then
  43.         turtle.digUp()
  44.       else
  45.         turtle.attackUp()
  46.       end
  47.     end
  48.   end
  49.   y = y + 1
  50. end
  51.  
  52. function down()
  53.   while not turtle.down() do
  54.     if not refuel() then
  55.       if turtle.detectDown() then
  56.         turtle.digDown()
  57.       else
  58.         turtle.attackDown()
  59.       end
  60.     end
  61.   end
  62.   y = y - 1
  63. end
  64.  
  65. function turnLeft()
  66.   turtle.turnLeft()
  67.   facing = facing - 1
  68.   if facing < 0 then facing = 0 end
  69. end
  70.  
  71. function turnRight()
  72.   turtle.turnRight()
  73.   facing = facing + 1
  74.   if facing > 3 then facing = 3 end
  75. end
  76.  
  77. function turnAround()
  78.   if z == length-1 then
  79.     function turn = turnRight
  80.   elseif z == 0 then
  81.     function turn = turnLeft
  82.   end
  83.   turn()
  84.   step()
  85.   turn()
  86. end
  87.  
  88. function layer()
  89.   for i = 1,width do
  90.     for j = 1,length do
  91.       step()
  92.     end
  93.     turnAround()
  94.   end
  95. end
  96.  
  97. function start()
  98.   down()
  99.   layer()
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement