Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- uses Robust Turtle API: pastebin get 0TnEBf2P t
- os.loadAPI("t")
- -- local args = {...}
- local versionNumber = "1.0"
- local programName = "StarDustChopper"
- local programNameShort = "SDChopper"
- local startInventory = 3
- local treeDistance = 1
- local refuelAmount = 80
- local distanceFromContainer = 0
- local saplingName = nil
- --if #args ~= 1 then
- -- print ("Usage: "..programNameShort.." (Amount of Simultaneous Trees)")
- -- return
- --else
- -- treeAmount = tonumber(args[1])
- -- if treeAmount < 1 then
- -- print("Amount Of trees must be positive")
- -- return
- -- end
- function Refuel(amountOfRequiredFuel)
- turtle.select(1)
- if (turtle.getFuelLevel() == "unlimited") then
- -- that's pretty neat dude.
- return
- end
- if (turtle.getFuelLevel() < amountOfRequiredFuel) then
- while (true) do
- if turtle.refuel(1) then
- if (turtle.getFuelLevel() > amountOfRequiredFuel) then
- break
- end
- else
- print("Turtle could not refuel. Please check why.")
- error()
- end
- end
- end
- end
- function CheckSaplings()
- turtle.select(2)
- if turtle.getItemDetail() then
- if saplingName ~= nil then
- if turtle.getItemDetail().name == saplingName then
- return true
- else
- print("Foreign object in Sapling Area. Looking for others.")
- turtle.transferTo(16)
- for i=1,16 do
- turtle.select(i)
- if turtle.getItemDetail() ~= nil then
- if turtle.getItemDetail().name == saplingName then
- turtle.transferTo(2)
- print("Found others. Continuing.")
- return true
- end
- end
- end
- print("Could not find more saplings.")
- CheckSaplings()
- end
- else
- saplingName = turtle.getItemDetail().name
- end
- else
- print("Please insert saplings. Retrying in 5 Seconds.")
- sleep(5)
- CheckSaplings()
- end
- end
- function CheckIfGrown()
- turtle.select(2)
- if not turtle.detect() then
- CheckSaplings()
- t.place(2)
- return false
- elseif turtle.compare() then
- return false
- else
- return true
- end
- end
- function CutTree()
- turtle.select(2)
- t.dig()
- t.forward()
- t.digUp()
- t.up()
- t.digUp()
- t.up()
- local upCount = 2
- while turtle.detectUp() do
- t.digUp()
- t.up()
- upCount = upCount + 1
- t.dig()
- t.right()
- t.dig()
- t.right()
- t.dig()
- t.right()
- t.dig()
- t.right()
- end
- t.down(upCount)
- t.back()
- end
- function EmptyInventory()
- local itemsDepositedCount = 0
- for i=startInventory,16 do
- turtle.select(i)
- itemsDepositedCount = itemsDepositedCount + turtle.getItemCount()
- if turtle.getItemCount() == 0 then
- --twiddle your thumbs
- elseif not turtle.drop() then
- print("Container full. Please empty it.")
- error()
- end
- end
- print("Deposited "..itemsDepositedCount.." Items.")
- end
- function CheckInventory()
- turtle.select(6)
- if turtle.getItemCount() > 0 then
- t.turnAround()
- t.forward(distanceFromContainer)
- EmptyInventory()
- t.turnAround()
- t.forward(distanceFromContainer)
- end
- end
- function Farm()
- if CheckSaplings() then
- if CheckIfGrown() then
- CutTree()
- if CheckSaplings() then
- CheckIfGrown()
- end
- end
- end
- end
- -- INITIAL SETUP FASE
- term.clear()
- term.setCursorPos(1,1)
- print("Welcome to"..programName.."Version "..versionNumber.." !")
- print("(Coded by MrHG using RobustTurtleAPI)")
- print("")
- sleep(1)
- print("Insert Fuel in slot 1")
- print("Insert Sapling in slot 2")
- Refuel(80)
- CheckSaplings()
- t.turnAround()
- for i=1,5 do
- if turtle.detect() then
- print("Block found. Assuming it is Container.")
- t.turnAround()
- t.forward(distanceFromContainer)
- break
- else
- t.forward()
- distanceFromContainer = distanceFromContainer + 1
- end
- if i == 5 then
- print("No container within reach.")
- print("Would you like to proceed without one? (y/n)")
- if read() == "y" then
- print("Understood. Proceeding without container.")
- t.turnAround()
- t.forward(distanceFromContainer)
- distanceFromContainer = 0
- else
- print("Please install container within reach before continuing.")
- t.turnAround()
- t.forward(distanceFromContainer)
- error()
- end
- end
- end
- function moveStraight()
- t.strafeRight(treeDistance)
- Refuel(refuelAmount)
- Farm()
- end
- function moveCorner()
- t.strafeRight(treeDistance)
- t.forward(2)
- t.left()
- Refuel(refuelAmount)
- Farm()
- end
- -- Main Block
- term.clear()
- term.setCursorPos(1,1)
- print("Commence Chopping!")
- print("")
- while true do
- -- AT START
- CheckInventory()
- Refuel(refuelAmount)
- Farm()
- -- OOO
- -- O O
- -- OXO
- moveStraight()
- -- OOO
- -- O O
- -- OOX
- moveCorner()
- -- OOO
- -- O X
- -- OOO
- moveStraight()
- -- OOX
- -- O O
- -- OOO
- moveCorner()
- -- OXO
- -- O O
- -- OOO
- moveStraight()
- -- XOO
- -- O O
- -- OOO
- moveCorner()
- -- OOO
- -- X O
- -- OOO
- moveStraight()
- -- OOO
- -- O O
- -- XOO
- moveCorner()
- -- OOO
- -- O O
- -- OXO
- if CheckSaplings() then
- local timesChecked = 0
- while not CheckIfGrown() do
- cursorPosx,cursorPosy = term.getCursorPos()
- if cursorPosy > 1 then
- term.setCursorPos(cursorPosx, 1)
- end
- term.setCursorPos(cursorPosx,cursorPosy-1)
- term.clearLine()
- print("Turtle has spun around "..timesChecked.." Times Since last harvest.")
- t.turnAround()
- t.turnAround()
- sleep(10)
- timesChecked = timesChecked + 1
- if timesChecked > 30 then
- print("This is taking a while.. Attempting Detection Override.")
- break
- end
- end
- CutTree()
- end
- end
Add Comment
Please, Sign In to add comment