Advertisement
KaosKlaus

BuildStaircase

Mar 8th, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. -- turtle.select(1)
  4. -- local slot=1
  5.  
  6. local function refuel()
  7.     local fuelLevel = turtle.getFuelLevel()
  8.     if fuelLevel == "unlimited" or fuelLevel > 0 then
  9.         return
  10.     end
  11.    
  12.     local function tryRefuel()
  13.         for n=1,16 do
  14.             if turtle.getItemCount(n) > 0 then
  15.                 turtle.select(n)
  16.                 if turtle.refuel(1) then
  17.                     turtle.select(1)
  18.                     return true
  19.                 end
  20.             end
  21.         end
  22.         turtle.select(1)
  23.         return false
  24.     end
  25.    
  26.     if not tryRefuel() then
  27.         print( "Add more fuel to continue." )
  28.         while not tryRefuel() do
  29.             sleep(1)
  30.         end
  31.         print( "Resuming..." )
  32.     end
  33. end
  34.  
  35. function turnR(n)
  36.     if n == nil then n=1 end
  37.     for i = 1,n do
  38.         turtle.turnRight()
  39.     end
  40. end
  41.  
  42. function turnL(n)
  43.     if n == nil then n=1 end
  44.     for i = 1,n do
  45.         turtle.turnLeft()
  46.     end
  47. end
  48.  
  49. function go(n)
  50.     refuel()
  51.     if n == nil then n=1 end
  52.     for i = 1,n do
  53.         turtle.forward()
  54.     end
  55. end
  56.  
  57. function back(n)
  58.     refuel()
  59.     if n == nil then n=1 end
  60.     for i = 1,n do
  61.         turtle.back()
  62.     end
  63. end
  64.  
  65. function down(n)
  66.     refuel()
  67.     if n == nil then n=1 end
  68.     for i = 1,n do
  69.         if not turtle.down() then
  70.             return false
  71.         end
  72.     end
  73.     return true
  74. end
  75.  
  76. function up(n)
  77.     refuel()
  78.     if n == nil then n=1 end
  79.     for i = 1,n do
  80.         turtle.up()
  81.     end
  82. end
  83.  
  84. function place(item)
  85.    
  86.    
  87.     function checkRessources()
  88.         if item == "block" then
  89.             turtle.select(1)
  90.             for i = 1,4 do
  91.                 if turtle.getItemCount(i) > 0 then
  92.                     turtle.select(i)
  93.                     return true
  94.                 end
  95.             end
  96.         elseif item == "stair" then
  97.             turtle.select(5)
  98.             for i = 5,8 do
  99.                 if turtle.getItemCount(i) > 0 then
  100.                     turtle.select(i)
  101.                     return true
  102.                 end
  103.             end
  104.         end
  105.         return false
  106.     end
  107.    
  108.     if not checkRessources() then
  109.         print( "Add more Ressources to continue." )
  110.         while not checkRessources() do
  111.             sleep(1)
  112.         end
  113.         print( "Resuming..." )
  114.     end
  115.    
  116.     turtle.place()
  117. end
  118.  
  119. function placeDown(item)
  120.    
  121.    
  122.     function checkRessources()
  123.         if item == "block" then
  124.             turtle.select(1)
  125.             for i = 1,4 do
  126.                 if turtle.getItemCount(i) > 0 then
  127.                     turtle.select(i)
  128.                     return true
  129.                 end
  130.             end
  131.         elseif item == "stair" then
  132.             turtle.select(5)
  133.             for i = 5,8 do
  134.                 if turtle.getItemCount(i) > 0 then
  135.                     turtle.select(i)
  136.                     return true
  137.                 end
  138.             end
  139.         end
  140.         return false
  141.     end
  142.    
  143.     if not checkRessources() then
  144.         print( "Add more Ressources to continue." )
  145.         while not checkRessources() do
  146.             sleep(1)
  147.         end
  148.         print( "Resuming..." )
  149.     end
  150.    
  151.     turtle.placeDown()
  152. end
  153.  
  154.  
  155.  
  156.  
  157. -- find start pos
  158. go(2)
  159. turnR()
  160. go()
  161. down()
  162. -- loop
  163.  
  164.  
  165. local done=false
  166. while not done do
  167.     place("block")
  168.     turnR()
  169.     back()
  170.     place("block")
  171.     turnR()
  172.     back()
  173.     place("block")
  174.     turnL()
  175.     back()
  176.     place("block")
  177.     back()
  178.     for i = 1,3 do
  179.         place("stair")
  180.         if not down() then done=true break end
  181.         place("block")
  182.         up()
  183.         if i % 2 == 0 then
  184.                 turnL()
  185.             else
  186.                 turnR()
  187.         end
  188.         go()
  189.         if i % 2 == 0 then
  190.                 turnR()
  191.             else
  192.                 turnL()
  193.         end
  194.         place("stair")
  195.         if not down() then done= true break end
  196.         place("block")
  197.         back()
  198.     end
  199. end
  200.  
  201. print("finished")
  202.  
  203.  
  204. --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement