Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tArgs = {...}
- local saplingSlot = 15
- local fuelSlot = 16
- local isRedwood = false
- local defaultRefuelAmount = 5
- function goUp(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- turtle.up()
- end
- end
- function goDown(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- turtle.down()
- end
- end
- function goForward(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- turtle.forward()
- end
- end
- function goBack(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- turtle.back()
- end
- end
- function digUp(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- while turtle.detectUp() == true do
- turtle.digUp()
- sleep(0.5)
- end
- if distance > 1 then
- goUp()
- end
- end
- end
- function dig(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- while turtle.detect() == true do
- turtle.dig()
- sleep(0.5)
- end
- end
- end
- function digDown(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- turtle.digDown()
- sleep(0.5)
- if distance > 1 then
- goDown()
- end
- end
- end
- function getFuel()
- return turtle.getFuelLevel()
- end
- function getFuelCount()
- return turtle.getItemCount(fuelSlot)
- end
- function refuel(amount)
- if amount == nil then amount = defaultRefuelAmount end
- turtle.select(fuelSlot)
- turtle.refuel(amount)
- turtle.select(1)
- end
- function dropLoad()
- print("Dropping off load of wood")
- shell.run("turn", "around")
- for i = 1, 14 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- shell.run("turn", "around")
- end
- function returnToGround()
- print("returning to ground level")
- while turtle.detectDown() == false do
- turtle.down()
- end
- end
- function waitForGrowth()
- if turtle.detect() == false then
- --print("TICK")
- return false
- else
- print("Tree has grown!")
- return true
- end
- end
- function chopTree(redwood)
- print("Chopping down tree")
- if redwood == true then
- dig()
- goForward()
- while turtle.detectUp() == true do
- shell.run("turn", "right")
- dig()
- shell.run("turn", "left")
- dig()
- goForward()
- shell.run("turn", "right")
- dig()
- shell.run("turn", "left")
- goBack()
- digUp()
- goUp()
- end
- if turtle.detect() == true then
- shell.run("turn", "right")
- dig()
- shell.run("turn", "left")
- dig()
- goForward()
- shell.run("turn", "right")
- dig()
- shell.run("turn", "left")
- goBack()
- end
- returnToGround()
- goBack()
- dropLoad()
- else
- dig()
- goForward()
- while turtle.detectUp() == true do
- turtle.digUp()
- goUp()
- end
- returnToGround()
- goBack()
- dropLoad()
- end
- end
- function coreRoutine()
- while true do
- while waitForGrowth() == false do
- sleep(60)
- end
- if waitForGrowth() == true then
- if fuelStockCritical() == true then
- goToRefuelChest()
- end
- if getFuel() < 50 then
- refuel()
- end
- goDown()
- chopTree(isRedwood)
- plantSaplings(isRedwood)
- goUp()
- end
- end
- end
- function plantSaplings(redwood)
- print("planting saplings")
- if redwood == true then
- if turtle.getItemCount(saplingSlot) == 0 then
- print("Out of Saplings!")
- return false
- elseif turtle.getItemCount(saplingSlot) < 4 then
- print("Insufficient Saplings")
- return false
- else
- turtle.select(saplingSlot)
- turtle.up()
- turtle.forward()
- turtle.placeDown()
- turtle.forward()
- turtle.placeDown()
- turtle.turnRight()
- turtle.forward()
- turtle.placeDown()
- turtle.turnRight()
- turtle.forward()
- turtle.placeDown()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- turtle.down()
- turtle.select(1)
- end
- else
- if turtle.getItemCount(saplingSlot) == 0 then
- print("Out of Saplings!")
- else
- turtle.select(saplingSlot)
- turtle.up()
- turtle.forward()
- turtleplaceDown()
- turtle.back()
- turtle.down()
- turtle.select(1)
- end
- end
- end
- function fuelStockCritical()
- if getFuelCount() <= 5 then
- return true
- else
- return false
- end
- end
- function goToRefuelChest()
- if turtle.detectDown() == true then
- goUp()
- else
- returnToGround()
- goUp()
- end
- shell.run("turn", "around")
- goForward(3)
- turtle.select(fuelSlot)
- turtle.suckDown()
- turtle.select(1)
- shell.run("turn", "around")
- goForward(3)
- returnToGround()
- end
- if tArgs[1] == nil then
- if fuelStockCritical() == true then
- print("Fuel stock low, going to grab more fuel")
- goToRefuelChest()
- end
- if getFuel() < 50 then
- refuel()
- end
- isRedwood = false
- if turtle.detect() == false then
- plantSaplings()
- else
- turtle.up()
- if turtle.detect() == true then
- turtle.down()
- chopTree()
- plantSaplings()
- end
- end
- elseif tArgs[1] == "redwood" then
- if fuelStockCritical() == true then
- print("Fuel stock low, going to grab more fuel")
- goToRefuelChest()
- end
- if getFuel() < 50 then
- refuel()
- end
- isRedwood = true
- if turtle.detect() == false then
- plantSaplings(true)
- else
- turtle.up()
- if turtle.detect() == true then
- turtle.down()
- chopTree(true)
- plantSaplings(true)
- end
- end
- end
- print("Starting main routine")
- if turtle.detectDown() == true then
- goUp()
- end
- coreRoutine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement