DigiZA

Turtle Stairs v1

May 21st, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. -----------------------------------------------------------------
  2. --                      Functions                              --
  3. -----------------------------------------------------------------
  4. function checkFuel() --Fuel checking, refuels if able, gives error if no fuel.
  5.   result = true
  6.   while turtle.getFuelLevel() < 1 do
  7.    result = false
  8.    for i=2,16 do
  9.     turtle.select(i)
  10.     if turtle.refuel(1) then
  11.      result = true
  12.      break
  13.     end
  14.    end
  15.     if not result then
  16.      print " "
  17.      print "Please add a fuel to slot 16"
  18.      print "Press Enter when done."
  19.      x = read()
  20.     end
  21.   end
  22. end
  23.  
  24. function forward() --Move and Dig Forward
  25.  checkFuel()
  26.   if turtle.detect() then
  27.    turtle.dig()
  28.   end
  29.  turtle.forward()
  30. end
  31.  
  32. function down() --Move and Dig Down
  33.  checkFuel()
  34.   if turtle.detectDown() then
  35.    turtle.digDown()
  36.   end
  37.  turtle.down()
  38. end
  39.  
  40. function place() --Place stairs
  41.  checkFuel()
  42.   result = true
  43.    if not turtle.detectDown() then
  44.     result = false
  45.    for i=2,16 do
  46.     turtle.select(i)
  47.      if turtle.getItemCount(15) >3  then
  48.       result = true
  49.       break
  50.      end
  51.     end
  52.    end
  53.    if not result then
  54.     print " "
  55.     print "Please add stairs."
  56.     print "Press Enter when done."
  57.     x = read()
  58.    end
  59.      --Place Middle
  60.      turtle.select(15)
  61.      turtle.turnRight()
  62.      turtle.turnRight()
  63.      turtle.placeDown()
  64.      --Place Right
  65.      turtle.turnLeft()
  66.      turtle.forward()
  67.      turtle.turnRight()
  68.      turtle.placeDown()
  69.      --place Left
  70.      turtle.turnRight()
  71.      turtle.forward()
  72.      turtle.forward()
  73.      turtle.turnLeft()
  74.      turtle.placeDown()
  75.      --return mid    
  76.      turtle.turnLeft()
  77.      turtle.forward()
  78.      turtle.turnLeft()
  79. end
  80.  
  81. function sides() --Clears Left and Right.
  82.  turtle.turnLeft()
  83.   if turtle.detect() then
  84.    turtle.dig()
  85.   end
  86.  turtle.turnRight()
  87.  turtle.turnRight()
  88.   if turtle.detect() then
  89.    turtle.dig()
  90.   end
  91.  turtle.turnLeft()
  92. end
  93.  
  94. function Ret2strt() --Return to start
  95.  checkFuel()
  96.  turtle.up()
  97.  turtle.back()
  98. end
  99.  
  100. function firststeps()
  101.  checkFuel()
  102.  down()
  103.  sides()
  104.  turtle.up()
  105.  place()
  106. end
  107.  
  108. -----------------------------------------------------------------
  109. --                      End Functions                          --
  110. -----------------------------------------------------------------
  111.  
  112. print("How deep shall I go?")
  113. ammount = read() --read() is a function which returns text you entered.
  114.  firststeps()
  115. for i=1, ammount do --Loop Start
  116. print("Doing run ", i," of ", ammount)
  117.  checkFuel()
  118.  turtle.up()
  119.  turtle.up()
  120.  turtle.up()
  121.  --Digging
  122.  forward()
  123.  sides()
  124.  down()
  125.  sides()
  126.  down()
  127.  sides()
  128.  down()
  129.  sides()
  130.  down()
  131.  sides()
  132.  down()
  133.  sides()
  134.  turtle.up()
  135.  place()
  136. end
  137. print "Turtle done!"
  138. print "Going back."
  139. for i=1, ammount do
  140.   Ret2strt()
  141. end
  142. print "All Done."
Advertisement
Add Comment
Please, Sign In to add comment