Advertisement
Guest User

digHole

a guest
Mar 29th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1. write("What length should the hole be? ")
  2. local lengthTXT = read()
  3. local length = tonumber(lengthTXT)
  4. write("What width should the hole be? ")
  5. local widthTXT = read()
  6. local width = tonumber(widthTXT)
  7. write("What depth should the hole be? ")
  8. local depthTXT = read()
  9. local depth = tonumber(depthTXT)
  10. write("Digging a "..lengthTXT.."x"..widthTXT.."x"..depthTXT.." hole")
  11.  
  12. local doLenFlip = 0
  13. local doWidFlip = 0
  14. local doDepFlip = 0
  15.  
  16. if turtle.getFuelLevel() == 0 then
  17.   turtle.refuel(1)
  18. end
  19.  
  20. local x = 0
  21. local y = 0
  22. local z = 0
  23.  
  24. for i = 1, depth do
  25.   for j = 1, width do
  26.     for k = 1, length-1 do
  27.       if turtle.getFuelLevel() == 0 then
  28.         turtle.refuel(1)
  29.       end
  30.       turtle.dig()
  31.       repeat
  32.         turtle.dig()
  33.       until turtle.forward()
  34.       if doLenFlip == 0 then
  35.         x = x + 1
  36.       else
  37.         x = x - 1
  38.       end
  39.       local xtxt = tostring(x)
  40.       local ytxt = tostring(y)
  41.       local ztxt = tostring(z)
  42.       print(xtxt, ytxt, ztxt)
  43.     end
  44.     if turtle.getFuelLevel() == 0 then
  45.       turtle.refuel(1)
  46.     end
  47.     if j ~= width then
  48.       if doLenFlip == 0 then
  49.         turtle.turnRight()
  50.         turtle.dig()
  51.         turtle.forward()
  52.         turtle.turnRight()
  53.         doLenFlip = 1
  54.       else
  55.         turtle.turnLeft()
  56.         turtle.dig()
  57.         turtle.forward()
  58.         turtle.turnLeft()
  59.         doLenFlip = 0
  60.       end
  61.       if doWidFlip == 0 then
  62.         z = z + 1
  63.       else
  64.         z = z - 1
  65.       end
  66.     end
  67.   end
  68.   if i ~= depth then
  69.     if turtle.getFuelLevel() == 0 then
  70.       turtle.refuel(1)
  71.     end
  72.     turtle.digDown()
  73.     turtle.down()
  74.     turtle.turnRight()
  75.     turtle.turnRight()
  76.     if doWidFlip == 0 then
  77.       doWidFlip = 1
  78.     else
  79.       doWidFlip = 0
  80.     end
  81.     y = y + 1
  82.   end
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement