SHARE
TWEET

tree.lua

a guest Nov 13th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("flex.lua")
  2. os.loadAPI("dig.lua")
  3.  
  4. local args,auto = {...},false
  5. if args[1] == "auto" then
  6.  auto = true
  7. end --if
  8.  
  9. dig.setFuelSlot(2,16)
  10.  
  11. local function chopTree()
  12.  flex.send("Chopping tree...",colors.orange)
  13.  dig.fwd()
  14.  while dig.gety() < 30 do
  15.   turtle.dig()
  16.   dig.up()
  17.  end
  18.  dig.right()
  19.  dig.fwd()
  20.  dig.left()
  21.  while dig.gety() > 0 do
  22.   dig.down()
  23.   turtle.dig()
  24.  end
  25.  dig.gotox(0)
  26.  dig.gotoz(0)
  27.  dig.gotor(0)
  28.  flex.send("Tree chopped!",colors.lime)
  29. end --function
  30.  
  31.  
  32. local function plantSaplings()
  33.  local a,x
  34.  turtle.select(1)
  35.  a = true
  36.  while turtle.getItemCount() < 4 or
  37.     string.find(turtle.getItemDetail()
  38.     ["name"],"sapling") == 0 do
  39.   if a then
  40.    flex.send("Insert saplings please!",
  41.      colors.orange)
  42.    a = false
  43.   end
  44.   sleep(1)
  45.  end
  46.  if not a then
  47.   flex.send("Thanks!",colors.lime)
  48.  end
  49.  flex.send("Planting saplings...",colors.orange)
  50.  dig.up()
  51.  dig.fwd()
  52.  turtle.digDown()
  53.  dig.placeDown()
  54.  for x=1,3 do
  55.   dig.fwd()
  56.   turtle.digDown()
  57.   dig.placeDown()
  58.   dig.right()
  59.  end
  60.  dig.fwd()
  61.  dig.left()
  62.  dig.fwd()
  63.  dig.down()
  64.  dig.right(2)
  65.  flex.send("Saplings planted!",colors.lime)
  66. end --function
  67.  
  68.  
  69. local grow = false
  70. local function treeGrows()
  71.  while string.find(flex.getBlock(),
  72.     "log") == nil do
  73.   sleep(2)
  74.   if turtle.getItemCount(1) < 64 then
  75.    flex.condense()
  76.   end --if
  77.  end --while
  78.  grow = true
  79. end --function
  80.  
  81.  
  82. if fs.exists("startup.lua") then
  83.  dig.loadCoords()
  84.  if dig.getx() ~= 0 or
  85.     dig.gety() ~= 0 or
  86.     dig.getz() ~= 0 or
  87.     dig.getr() ~= 0 then
  88.   dig.goto(0,0,0,0)
  89.   chopTree()
  90.  end --if
  91. end --if
  92.  
  93.  
  94. if auto then
  95.  dig.makeStartup("tree",args)
  96.  
  97.  local done = false
  98.  while not done do
  99.  
  100.   turtle.select(1)
  101.   plantSaplings()
  102.  
  103.   flex.condense()
  104.   dig.left(2)
  105.   flex.dump(3,16)
  106.   dig.left(2)
  107.  
  108.   flex.send("Waiting for tree to grow..."
  109.      ,colors.lightBlue)
  110.  
  111.   grow = false
  112.   parallel.waitForAny(treeGrows,
  113.     flex.keyPress)
  114.  
  115.   if grow then
  116.    chopTree()
  117.   else
  118.    done = true
  119.   end --if/else
  120.  
  121.  end --while
  122.  
  123. else
  124.  if string.find(flex.getBlock(),
  125.       "log") ~= nil then
  126.   chopTree()
  127.  else
  128.   flex.send("No tree found",colors.orange)
  129.  end
  130.  
  131. end --if/else
  132.  
  133.  
  134. os.unloadAPI("dig.lua")
  135. os.unloadAPI("flex.lua")
  136. if fs.exists("startup.lua") then
  137.  shell.run("rm startup.lua")
  138. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top