le_Fish

TreeScript

May 7th, 2020
3,100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.96 KB | None | 0 0
  1. local blockToMove = 99
  2.  
  3. -- I've made refill a function so you could use it anywhere in the code. But for now
  4. -- this function will run at the start of each new loop to check if the turtle has
  5. -- enough items
  6. function refill()
  7.     if turtle.getFuelLevel <= 50 then
  8.         for i = 16,1,-1 do
  9.             turtle.select(i)
  10.             turtle.dropUp()
  11.         end
  12.         turtle.suckDown() --Code to pick up stacks of coal from chest
  13.         turtle.refuel() --Code to refuel all
  14.         turtle.turnRight()
  15.         turtle.suck(1)
  16.         turtle.turnRight()
  17.         turtle.suck(2)
  18.         turtle.turnLeft()
  19.         turtle.turnLeft()
  20.         print("Done Refueling")
  21.     elseif turtle.getItemCount(1) == 0 then
  22.         turtle.turnRight()
  23.         turtle.suck(1)
  24.         turtle.turnLeft()
  25.         print("Refilled Saplings")
  26.     elseif turtle.getItemCount(2) == 0 then
  27.         turtle.turnRight()
  28.         turtle.turnRight()
  29.         turtle.suck(2)
  30.         turtle.turnLeft()
  31.         turtle.turnLeft()
  32.         print("Refilled Bone Meal")
  33.     end
  34. end
  35.  
  36. -- Go home is now also a function, but this function should
  37. -- actually never be called since removeTree has a "homing" system
  38. function goHome()
  39.     for attempt = 1, blocksToMove do
  40.         local success, error = turtle.down()
  41.         if not turtle.down() then
  42.             turtle.back()
  43.             print("Returned to Start")
  44.             break
  45.         end
  46.     end
  47. end
  48.  
  49. -- Remove tree is now also a function. It will
  50. function removeTree()
  51.     local up = 1
  52.     local tree = true
  53.     -- While turtle.inspectUP is true and turtle.inspectup.name = a log, dig up
  54.     while turtle.inspectUp() and turtle.inspectUp().name == "MineFactoryReloaded:rubberwood.log" do
  55.         turtle.digUp()
  56.         turtle.up()
  57.         up = up + 1
  58.     end
  59.     -- Go down as many times as we went up
  60.     for i = 1, up do
  61.         turtle.down()
  62.     end
  63. end
  64.  
  65. -- Make this one big loop so it keeeeeps on going
  66. while true do
  67.     -- First refill if needed
  68.     refill()
  69.     if turtle.detect() == false and turtle.detectUp() == false and turtle.detectDown() == false then
  70.         -- This function should actually never run, since remove tree gets you home.
  71.         -- Should go home
  72.         goHome()
  73.     else
  74.         -- Check if there is anything in front of me
  75.         local check, infront = turtle.inspect()
  76.  
  77.         if not check then
  78.             -- No sapling and noving above me
  79.             turtle.select(1)
  80.             turtle.place()
  81.             print("Placed Sapling")
  82.         end
  83.         -- Check if infront is a sapling. if so, place bonemeal. If it's a log, I should probably remove the tree
  84.         if check and infront.name == "MineFactoryReloaded:rubberwood.sapling" then
  85.             turtle.select(2)
  86.             turtle.place()
  87.             print("Used Bonemeal")
  88.         elseif check and infront.name == "MineFactoryReloaded:rubberwood.log" then
  89.             turtle.dig()
  90.             turtle.forward()
  91.             removeTree()
  92.             turtle.back()
  93.         end
  94.     end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment