Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --2x2 lumberjack program (Original program by AaronDM, Heavily edited by ZeroBurn)
- --Chops down 2x2 trees such as Redwood or Fir and deposits them in a nearby chest
- --(currently in extra special mode for my tree chopping build)
- local isGrown = false
- local tArgs = { ... }
- function ascend()
- for i=1, 4 do
- turtle.up()
- end --for
- end --ascend()
- function descend()
- for i=1, 4 do
- turtle.down()
- end --for
- end --descend()
- --Basic fuel check function
- function checkFuel()
- if turtle.getFuelLevel() < 100 then
- repeat
- turtle.select(16)
- turtle.refuel(2)
- turtle.select(1)
- until turtle.getFuelLevel() >= 100
- end --if
- end --checkFuel()
- --Plants 4 Redwood saplings in a 2x2
- function plantTree()
- print("Planting Tree")
- turtle.select(15)
- turtle.forward()
- turtle.place()
- turtle.back()
- turtle.place()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- turtle.place()
- turtle.back()
- turtle.place()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- isGrown = false
- end --plantTree()
- --Uses Bonemeal to grow tree. (Only runs if there is Bonemeal in 13)
- function growTree()
- turtle.select(13)
- turtle.place()
- end --growTree()
- --Alternate checking for if the tree has grown. (If there are no saplings in 14)
- function altCheckTree()
- turtle.up()
- isGrown = not turtle.forward()
- if isGrown == false then
- repeat
- turtle.back()
- turtle.down()
- sleep(30)
- turtle.up()
- isGrown = turtle.foward()
- until isGrown == true
- end --if
- turtle.down()
- end --growTree()
- function checkTree()
- if turtle.getItemCount(13) >= 1 then
- growTree()
- end
- if turtle.getItemCount(14) >= 1 then
- turtle.select(14)
- isGrown = not turtle.compare()
- print("Is Grown: "..tostring(isGrown))
- else
- altCheckTree()
- end --if
- end --checkTree()
- --Cuts down the Redwood. Up the left side, then down the right side.
- function cutTree()
- print("Chopping Down Tree")
- turtle.select(1)
- turtle.dig()
- sleep(0.25)
- turtle.forward()
- turtle.dig()
- local height = 0
- if turtle.detectUp() == true then
- repeat
- turtle.dig()
- turtle.digUp()
- turtle.up()
- height = height + 1
- until turtle.detectUp() == false
- end --if
- checkFuel()
- turtle.turnRight()
- if turtle.detect() == true then
- turtle.dig()
- end --if
- turtle.forward()
- turtle.turnLeft()
- if turtle.detectDown() == true then
- repeat
- turtle.dig()
- turtle.digDown()
- turtle.down()
- height = height - 1
- until height <= 0
- end --if
- turtle.dig()
- end --cutTree()
- --Deposits the first 7 slots in a chest behind the turtle.
- function dropOff()
- --local distance = 0
- checkFuel()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- --while turtle.forward() do
- -- distance = distance + 1
- --end --while
- for i=1, 8 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- turtle.turnLeft()
- turtle.turnLeft()
- --distance = distance - 1
- --while distance > 0 do
- -- turtle.forward()
- -- distance = distance - 1
- --end --while
- checkFuel()
- end --dropOff()
- function checkInventory()
- return turtle.getItemCount(15) >= 4 and turtle.getItemCount(16) >= 2
- end --checkInventory()
- function getInventory()
- turtle.select(14)
- while turtle.getItemCount(14) < 64 do
- turtle.suck()
- end --while
- turtle.transferTo(15, 4)
- turtle.transferTo(1, 59)
- turtle.select(1)
- turtle.drop()
- turtle.turnRight()
- if turtle.getItemCount(16) == 0 then
- turtle.select(16)
- turtle.suck()
- end --if
- turtle.turnLeft()
- end --getInventory()
- --Main Script
- term.clear()
- print("Please confirm inventory.")
- print("Slot 13 = Bonemeal [Optional]")
- print("Slot 14 = Test Sapling [Optional; Only need one]")
- print("Slot 15 = Planting Saplings [Minimum 4]")
- print("Slot 16 = Fuel [Minimum 2]")
- if #tArgs < 1 then
- print("Run how many times?")
- times = tonumber(read())
- else
- times = tonumber(tArgs[1])
- print("Running "..times.." times")
- end
- if times == 0 then
- cutTree()
- checkFuel()
- return true
- end
- for i=1, times do
- getInventory()
- if not checkInventory() then
- term.clear()
- write("Please resupply.")
- return
- end
- checkFuel()
- ascend()
- if not turtle.detect() then
- plantTree()
- else
- print("Skipping Planting Tree")
- end
- if isGrown == false then
- repeat
- print("Is Grown: "..tostring(isGrown))
- checkTree()
- sleep(15)
- until isGrown == true
- end
- checkFuel()
- cutTree()
- checkFuel()
- dropOff()
- descend()
- end
- print("Complete")
- return
Advertisement
Add Comment
Please, Sign In to add comment