ConorYoungs

Excavator Computer Craft Script

Apr 11th, 2021 (edited)
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. print("Conor's excavating program!!")
  2. write("Please enter the length: ")
  3. local length = tonumber(read())
  4.  
  5. write("Please enter the width: ")
  6. local width = tonumber(read())
  7.  
  8. write("Please enter the depth: ")
  9. local depth = tonumber(read())
  10.  
  11. local function checkFuel()
  12.     if turtle.getFuelLevel() < 200 then
  13.         for i = 1, 16 do
  14.             turtle.select(i)
  15.             if turtle.refuel(0) then
  16.                 turtle.refuel(1)
  17.             end
  18.         end
  19.     end
  20. end
  21.  
  22. local function left(currentDepth, depth)
  23.     turtle.turnLeft()
  24.     turtle.dig()
  25.  
  26.     if currentDepth + 1 < depth then
  27.         turtle.digDown()
  28.     end
  29.  
  30.     turtle.forward()
  31.     turtle.turnLeft()
  32. end
  33.  
  34. local function right(currentDepth, depth)
  35.     turtle.turnRight()
  36.     turtle.dig()
  37.  
  38.     if currentDepth + 1 < depth then
  39.         turtle.digDown()
  40.     end
  41.  
  42.     turtle.forward()
  43.     turtle.turnRight()
  44. end
  45.  
  46. local function excavate(length, width, depth)
  47.     if depth > 1 then
  48.         turtle.digDown()
  49.     end
  50.  
  51.     local i = 0
  52.     local z = 1
  53.  
  54.     --for i = 1, depth do
  55.     while i < depth do
  56.         for j = 1, width do
  57.             checkFuel()
  58.  
  59.             for k = 1, length - 1 do
  60.                 if i + 1 < depth then
  61.                     turtle.digDown()
  62.                 end
  63.                 turtle.dig()
  64.                 turtle.forward()
  65.             end
  66.  
  67.             if j < width then
  68.                 -- if even width
  69.                 if width % 2 == 0 then
  70.                     -- if even depth
  71.                     if z % 2 == 0 then
  72.                         if j % 2 == 0 then
  73.                             right(i, depth)
  74.                         else
  75.                             left(i, depth)
  76.                         end
  77.                     -- if odd depth
  78.                     else
  79.                         if j % 2 == 0 then
  80.                             left(i, depth)
  81.                         else
  82.                             right(i, depth)
  83.                         end
  84.                     end
  85.                 -- if odd width
  86.                 else
  87.                     if j % 2 == 0 then
  88.                         left(i, depth)
  89.                     else
  90.                         right(i, depth)
  91.                     end
  92.                 end
  93.             end
  94.         end
  95.  
  96.         -- position turtle if more than 0 depth to go
  97.         if i + 1 < depth then
  98.             turtle.turnRight()
  99.             turtle.turnRight()
  100.             turtle.digDown()
  101.             turtle.down()
  102.  
  103.             if i + 2 < depth then
  104.                 turtle.digDown()
  105.                 turtle.down()
  106.             end
  107.         end
  108.  
  109.         if i + 1 < depth then
  110.             i = i + 2
  111.         elseif i < depth then
  112.             i = i + 1
  113.         end
  114.  
  115.         z = z + 1
  116.     end
  117. end
  118.  
  119. excavate(length, width, depth)
Add Comment
Please, Sign In to add comment