Advertisement
tonytonov

Quarry recharger turtle

Feb 6th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. local location = ""
  2.  
  3. function teleport()
  4.    turtle.turnRight()
  5.    tp = peripheral.wrap("bottom")
  6.    turtle.turnLeft()
  7.    tp.teleport()
  8. end
  9.  
  10. function checkFull()
  11.    greader = peripheral.wrap("right")
  12.    data = greader.get()
  13.    while not data["Full Energy"] do
  14.       sleep(2)
  15.       data=greader.get()
  16.    end
  17.    turtle.dig()
  18. end
  19.  
  20. function checkEmpty()
  21.    greader=peripheral.wrap("right")
  22.    data = greader.get()
  23.    while not data["No Energy"] do
  24.       sleep(2)
  25.       data = greader.get()
  26.    end
  27.    turtle.dig()
  28. end
  29.  
  30. function checkLoc()
  31.    loc = turtle.detectUp()
  32.    if loc == true then
  33.       print("I am at the quarry")
  34.       location = "Quarry"
  35.    else
  36.       print("I am at the charge station")
  37.       location = "Charging"
  38.    end
  39. end
  40.  
  41. function getFuel()
  42.    turtle.turnLeft()
  43.    turtle.forward()
  44.    turtle.forward()
  45.    turtle.forward()
  46.    turtle.forward()
  47.    turtle.turnRight()
  48.    turtle.forward()
  49.    turtle.forward()
  50.    turtle.suckDown()
  51.    turtle.refuel()
  52.    turtle.back()
  53.    turtle.back()
  54.    turtle.turnRight()
  55.    turtle.forward()
  56.    turtle.forward()
  57.    turtle.forward()
  58.    turtle.forward()
  59.    turtle.turnLeft()
  60. end
  61.  
  62.  
  63. function checkFuel()
  64.    fuel = turtle.getFuelLevel()
  65.    print("My fuel level:"..tostring(fuel))
  66.    if fuel < 2500 then
  67.       print("I need fuel")
  68.       getFuel()
  69.       print("My fuel level:"..tostring(turtle.getFuelLevel()))
  70.    end
  71. end
  72.  
  73. while true do
  74.    checkLoc()
  75.    if location == "Quarry" then
  76.       turtle.place()
  77.       checkEmpty()
  78.       teleport()
  79.    else
  80.       turtle.place()
  81.       checkFuel()
  82.       checkFull()
  83.       teleport()
  84.    end
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement