Advertisement
RabaGhast

TreeTurtle

Oct 30th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. returning = false
  2. space = 4
  3. st = 60
  4. warning = 20
  5. limit = turtle.getFuelLimit()
  6.  
  7. function getFuelPercentage()
  8.   level = turtle.getFuelLevel()
  9.   percentage = (level/limit)*100
  10.   print("fuel at: "..percentage.."%")
  11.   return percentage
  12. end
  13.  
  14. function chop()
  15.   print("Chopping")
  16.   turtle.select(1)
  17.   --sleep(st)
  18.   turtle.turnRight()
  19.   local success, data = turtle.inspect()
  20.   if (success and data.name == "minecraft:log") then
  21. ----chopping------
  22.     turtle.dig()
  23.     turtle.forward()
  24.     repeat
  25.       local success, data = turtle.inspectUp()
  26.       turtle.digUp()
  27.       turtle.suck()
  28.       turtle.up()
  29.     until data.name ~= "minecraft:log"
  30.     while turtle.down() do
  31.     end
  32.     for i = 1,4 do
  33.       turtle.suck()
  34.       turtle.turnRight()
  35.     end
  36.     turtle.back()
  37.   end
  38.   turtle.place()
  39.   turtle.turnLeft()
  40. end
  41.  
  42. function move()
  43.   --sleep(st)
  44.   for i = 1,space do
  45.     turtle.forward()
  46.     turtle.suck()
  47.   end
  48.   local success, data = turtle.inspect()
  49.   if success then
  50.     print("i see a wall")
  51.     print("Block name: ", data.name)
  52.     rotate()
  53.     return
  54.   end
  55.   print("moving")
  56. end
  57.  
  58. function unload()
  59.   print("Unloading")
  60.   --sleep(st)
  61.   turtle.turnLeft()
  62.   for j = 1,4 do
  63.     turtle.forward()
  64.     for i=1,16 do
  65.       turtle.select(i)
  66.       turtle.dropDown()
  67.     end
  68.     if j == 4 and getFuelPercentage() < warning then
  69.       print("fuel low")
  70.       turtle.select(1)
  71.       turtle.suckDown()
  72.       turtle.refuel()
  73.     end
  74.   end
  75.   for j = 1, 4 do
  76.     turtle.back()
  77.     if j == 1 then
  78.       turtle.select(1)
  79.       turtle.suckDown()
  80.     end
  81.   end
  82.   turtle.turnRight()
  83.   print("sleeping")
  84.   sleep(st)
  85. end
  86.  
  87. function rotate()
  88.   print("Rotating")
  89.   --sleep(st)
  90.   turtle.turnRight()
  91.   turtle.forward()
  92.   turtle.forward()
  93.   turtle.turnRight()
  94.   if returning then
  95.     unload()
  96.     returning = false
  97.     move()
  98.   else
  99.     returning = true
  100.   end
  101. end
  102.  
  103.  
  104. ----------Main----------
  105.  
  106.  
  107. while true do
  108.   move()
  109.   if not returning then
  110.     chop()
  111.   end
  112.   --print(returning)
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement