Advertisement
peptide

Redwood Cutter - Main

Jul 19th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. local distance = 150
  2.  
  3. function init()
  4.     print("Init")
  5.  
  6.     resetSignals()
  7.  
  8.     print("Fuel = " .. turtle.getFuelLevel())
  9.  
  10.     while turtle.getFuelLevel() < 500 do
  11.         print("Looking for Fuel")
  12.         for slot = 1,16 do
  13.             if turtle.getFuelLevel() < 500 then
  14.                 turtle.select(slot)
  15.                
  16.                 repeat
  17.                 until turtle.refuel(1) == false or turtle.getFuelLevel() > 500
  18.             end
  19.         end
  20.  
  21.         print("Trying to get fuel from interface")
  22.         repeat
  23.         until turtle.up() == false
  24.  
  25.         useInterface()
  26.        
  27.         print("Fuel = " .. turtle.getFuelLevel())
  28.     end
  29. end
  30.  
  31. function fillFuel()
  32.     while turtle.getFuelLevel() < 500 do
  33.         turtle.select(1)
  34.         turtle.refuel(20)
  35.         print("Fuel = " .. turtle.getFuelLevel())
  36.         sleep(5)
  37.     end
  38. end
  39.  
  40. function findInterface()
  41.     while turtle.detectUp() == false do
  42.         turtle.up()
  43.     end
  44. end
  45.  
  46. function useInterface()
  47.     for slot = 1,16 do
  48.         turtle.select(slot)
  49.         turtle.dropUp()
  50.     end
  51.     turtle.select(1)
  52.     turtle.suckUp()
  53. end
  54.  
  55. function chop()
  56.     for x = 1, distance do
  57.         turtle.suckDown()
  58.         turtle.digDown()
  59.         turtle.down()
  60.     end
  61. end
  62.  
  63. function waitForAll()
  64.  
  65.     print("Waiting for all turtles to be ready")
  66.  
  67.     --wait for a pass on a signal from all directions
  68.     repeat
  69.         sleep(1)
  70.     until redstone.getInput("left")
  71.     redstone.setOutput("right", true)
  72.     print("Left Ready")
  73.  
  74.     repeat
  75.         sleep(1)
  76.     until redstone.getInput("right")
  77.     redstone.setOutput("left", true)
  78.     print("Right Ready")
  79.  
  80.     repeat
  81.         sleep(1)
  82.     until redstone.getInput("front")
  83.     redstone.setOutput("back", true)
  84.     print("Front Ready")
  85.  
  86.     repeat
  87.         sleep(1)
  88.     until redstone.getInput("back")
  89.     redstone.setOutput("front", true)
  90.     print("Back Ready")
  91.  
  92.     --wait to ensure all others get the message
  93.     print("All Ready - Prepare to Move")
  94.     sleep(10)
  95. end
  96.  
  97. function resetSignals()
  98.     redstone.setOutput("left", false)
  99.     redstone.setOutput("right", false)
  100.     redstone.setOutput("front", false)
  101.     redstone.setOutput("back", false)
  102. end
  103.  
  104. --Start main code
  105. init()
  106.  
  107. while true do
  108.     --Stop emitting ready status
  109.     resetSignals()
  110.  
  111.     --move up until we find the interface
  112.     findInterface()
  113.  
  114.     --unload and collect fuel
  115.     useInterface()
  116.  
  117.     --Make sure we have some fuel to move
  118.     fillFuel()
  119.  
  120.     --check that everyone around us is ready
  121.     waitForAll()
  122.    
  123.     --chop down a line
  124.     chop()
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement