Gaimo

stair

Sep 26th, 2018
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. -- data entry --
  2. local Args = {...}
  3.  
  4. if #Args ~= 1 then
  5.     print("Usage: stair <distance>")
  6.     return
  7. end
  8.  
  9. -- check fuel level --
  10. function checkfuel()
  11.     if turtle.getFuelLevel() < 80 then
  12.         print("Add coal on inventory!")
  13.         for n=1,16 do
  14.             local nCount = turtle.getItemCount(n)
  15.             if nCount > 0 then
  16.                 turtle.select( n )
  17.                 if turtle.refuel(1) then
  18.                     print( "New Fuel level is "..turtle.getFuelLevel() )
  19.                 end
  20.             end
  21.         end
  22.     end
  23. end
  24.  
  25. -- vars --
  26. dist = tonumber ( Args[1] )
  27. posI = tonumber ( Args[1] )
  28.  
  29. -- Checks --
  30. if dist < 1 then
  31.     print ("Please enter a positive number!")
  32.     return
  33. end
  34.  
  35. -- funcs --
  36.  
  37. -- part 1 --
  38. function func1()
  39.     checkfuel()
  40.     if turtle.detect() then
  41.         turtle.dig()
  42.         if turtle.detectDown() then
  43.             turtle.digDown()
  44.             turtle.forward()
  45.             func2()
  46.         end
  47.     else
  48.         if turtle.detectDown() then
  49.             turtle.digDown()
  50.             turtle.down()
  51.             dist = dist - 1
  52.             if turtle.detect() then
  53.                 turtle.dig()
  54.                 turtle.forward()   
  55.             end
  56.             func2()
  57.         else
  58.             turtle.down()
  59.             dist = dist -1
  60.             fBuild()
  61.         end
  62.     end
  63. end
  64.  
  65. function func2()
  66.     if turtle.detect() then
  67.         turtle.dig()
  68.         if turtle.detectDown() then
  69.             turtle.digDown()
  70.             turtle.down()
  71.             dist = dist - 1
  72.         end
  73.     end
  74. end
  75.  
  76. -- build down--
  77. function fBuild()
  78.     for n=1,16 do
  79.         local nCount = turtle.getItemCount(n)
  80.         if nCount > 0 then
  81.             turtle.select( n )
  82.             if turtle.placeDown() then
  83.                 turtle.forward()
  84.             end
  85.         end
  86.     end
  87. end
  88.  
  89. function fReturn()
  90.     turtle.turnRight()
  91.     turtle.turnRight()
  92.  
  93.     while posI > 0 do
  94.         turtle.up()
  95.         turtle.forward()
  96.         posI = posI - 1
  97.     end
  98.  
  99.     if posI == 0 then
  100.         for n=1,16 do
  101.             local nCount = turtle.getItemCount(n)
  102.             if nCount > 0 then
  103.                 turtle.select( n )
  104.                 turtle.drop(nCount)
  105.             end
  106.         end
  107.     end
  108. end
  109.  
  110. -- program --
  111.  
  112. term.clear()
  113. print ("========= starting excavation ========")
  114. print( "Fuel level is "..turtle.getFuelLevel() )
  115.  
  116. while dist > 0 do
  117.     func1()
  118. end
  119.  
  120. if dist == 0 then
  121.     fReturn()
  122. end
Advertisement
Add Comment
Please, Sign In to add comment