Advertisement
Semikolon

Untitled

Jan 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. print("== Tree farming script ===")
  2. print("Author: MichiVIP")
  3. print("Version: 0.0.1")
  4.  
  5. local rubberwoodstr = "IC2:rubberWood"
  6.  
  7. local grassstr = "minecraft:grass"
  8. local dirtstr = "minecraft:dirt"
  9.  
  10. local detectionstr = "eng_toolbox:limestone"
  11.  
  12. local cheststr = "minecraft:chest"
  13.  
  14. local waterstr = "minecraft:flowing_water"
  15.  
  16. write("Enter sleep amount in seconds: ")
  17. local sleepamount = tonumber(io.read())
  18. print("Place saplings in slot 1 and a chest behind the turtle")
  19. io.read()
  20.  
  21. local function farmtree()
  22.     local success, data = turtle.inspect()
  23.     if not success then
  24.         turtle.select(1)
  25.         turtle.place()
  26.         return
  27.     elseif data.name == rubberwoodstr then
  28.         turtle.dig()
  29.     end
  30.     turtle.forward()
  31.     local counter = 0
  32.     while true do
  33.         local success, data = turtle.inspectUp()
  34.         if success and data.name == rubberwoodstr then
  35.             turtle.digUp()
  36.             turtle.up()
  37.             counter = counter + 1
  38.         else
  39.             break
  40.         end
  41.     end
  42.     for i = 0, counter, 1 do
  43.         turtle.down()
  44.     end
  45.     turtle.back()
  46.     if not turtle.detect() then
  47.         local success, data = turtle.inspect()
  48.         if success and data.name == waterstr then
  49.             return
  50.         end
  51.         turtle.select(1)
  52.         turtle.place()
  53.     end
  54. end
  55.  
  56. local function backtomain()
  57.     turtle.down()
  58.     while true do
  59.         turtle.back()
  60.         local success, data = turtle.inspectDown()
  61.         if success and data.name == detectionstr then
  62.             turtle.turnRight()
  63.             return
  64.         end
  65.     end
  66. end
  67.  
  68. local function nexttree()
  69.     if not turtle.forward() then
  70.         return false
  71.     end
  72.     while true do
  73.         local success, data = turtle.inspectDown()
  74.         if success and data.name == detectionstr then
  75.             turtle.turnLeft()
  76.             break
  77.         else
  78.             if not turtle.forward() then
  79.                 return false
  80.             end
  81.         end
  82.     end
  83.     while true do
  84.         local success, data = turtle.inspect()
  85.         if success then
  86.             if data.name == dirtstr or data.name == grassstr then
  87.                 turtle.up()
  88.                 local success, data = turtle.inspect()
  89.                 if not success or not data.name == rubberwoodstr then
  90.                     turtle.down()
  91.                     backtomain()
  92.                     return nexttree()
  93.                 end
  94.                 break
  95.             end
  96.         end
  97.         turtle.forward()
  98.     end
  99.     return true
  100. end
  101.  
  102. local function returntohome()
  103.     turtle.turnRight()
  104.     turtle.turnRight()
  105.     while true do
  106.         turtle.forward()
  107.         local success, data = turtle.inspect()
  108.         if success and data.name == cheststr then
  109.             for i = 2, 16, 1 do
  110.                 turtle.select(i)
  111.                 print(turtle.drop())
  112.             end
  113.             turtle.turnRight()
  114.             turtle.turnRight()
  115.             return
  116.         end
  117.     end
  118. end
  119.  
  120. local counter = 1
  121. while true do
  122.     print("Starting tree farming try no " .. counter)
  123.     while nexttree() do
  124.         farmtree()
  125.         backtomain()
  126.     end
  127.     returntohome()
  128.     counter = counter + 1
  129.     os.sleep(sleepamount)
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement