Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local saplingSlot = 1
- local logSlot = 2
- local length = 20
- local rows = 2
- local treeSpacing = 4
- local rowsSpacing = 4
- local endOfLineOffset = 3
- local maxCuttingHeight = 10
- local repeats = 1
- local function forward()
- while (not turtle.forward()) do
- if (turtle.detect()) then
- turtle.dig()
- else
- turtle.attack()
- end
- end
- end
- local function turn(curRow)
- if (curRow%2 == 1) then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- local function detectTree()
- if (turtle.detectUp()) then
- turtle.select(logSlot)
- if (turtle.compareUp()) then
- return true
- end
- end
- return false
- end
- local function cutTree()
- local height = 0
- turtle.digDown()
- while (detectTree()) do
- turtle.digUp()
- if (height < maxCuttingHeight) then
- while (not turtle.up()) do
- if (turtle.detectUp()) then
- turtle.digUp()
- else
- turtle.attackUp()
- end
- end
- end
- height = height +1
- end
- for i=1, height do
- while (not turtle.down()) do
- if (turtle.detectDown()) then
- turtle.digDown()
- else
- turtle.attackDown()
- end
- end
- end
- end
- local function plantSapling()
- turtle.select(saplingSlot)
- turtle.placeDown()
- turtle.suckDown()
- end
- local function moveLoop()
- for r=1, rows do
- for i=1, endOfLineOffset do
- forward()
- end
- for i=1, length do
- if (i%treeSpacing == 0 and turtle.getItemCount(saplingSlot)>1 ) then
- plantSapling()
- end
- forward()
- if (detectTree()) then
- cutTree()
- end
- end
- for i=1, endOfLineOffset do
- forward()
- end
- if (r ~= rows) then
- turn(r)
- for i=1, rowsSpacing do
- forward()
- end
- turn(r)
- end
- end
- end
- local function returnBase()
- local distanceToBase = (rows-1) * rowsSpacing -1
- local distanceToRowStart = 0
- if (rows%2 == 1) then
- distanceToRowStart = length+2*endOfLineOffset-1
- turn(1)
- forward()
- turn(1)
- for i=0, distanceToRowStart do
- forward()
- end
- turn(1)
- forward()
- else
- turn(1)
- end
- for i=0, distanceToBase do
- forward()
- end
- turn(1)
- end
- local function messageNeedSapplings()
- term.clear()
- print("Please put the correct sort of saplings in the first slot\nor in the chest the turtle is currently facing.")
- os.sleep(30)
- end
- local function manageInventory()
- local logDropCount = turtle.getItemCount(2)-1
- local fuelNeeded = ((length + (2*endOfLineOffset) + rowsSpacing) * rows + ((length/treeSpacing) * rows * maxCuttingHeight) ) - turtle.getFuelLevel()
- local saplingsNeeded = (length/treeSpacing*rows) - turtle.getItemCount(1)
- turtle.turnLeft()
- if (saplingsNeeded >0) then
- turtle.select(1)
- while (saplingsNeeded >0) do
- if (turtle.suck(saplingsNeeded)) then
- saplingsNeeded = (length/treeSpacing*rows) - turtle.getItemCount(1)
- if (saplingsNeeded > 0) then
- messageNeedSapplings()
- end
- else
- messageNeedSapplings()
- end
- end
- end
- turtle.select(2)
- turtle.dropDown(logDropCount)
- for i=3, 16 do
- turtle.select(i)
- if (turtle.compareTo(1)) then
- turtle.drop()
- else
- turtle.dropDown()
- end
- end
- while (fuelNeeded > 0) do
- if (turtle.suckUp()) then
- print("Refuelling...")
- else
- term.clear()
- print("Waiting for fuel in the last inventory slot\nor in an inventory on top.")
- os.sleep(30)
- end
- turtle.refuel()
- fuelNeeded = ((length + (2*endOfLineOffset) + rowsSpacing) * rows + ((length/treeSpacing) * rows * maxCuttingHeight) ) - turtle.getFuelLevel()
- end
- turtle.turnRight()
- end
- local function mainLoop()
- local i=0
- if (args[1] > 1) then
- repeats = args[1]
- end
- while (i<repeats) do
- term.clear()
- print("Managing inventory")
- manageInventory()
- print("Starting move loop")
- moveLoop()
- print("Returning base")
- returnBase()
- --~ Real line:
- os.sleep(300)
- i = i+1
- end
- end
- mainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement