Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local currentDirection = nil
- local sideLogs = {}
- local numberOfSideLogs = 0
- local logName = "minecraft:cherry_log"
- local leavesName = "minecraft:cherry_leaves"
- function getCurrentDirection()
- local tp1X, tp1Y, tp1Z = gps.locate()
- turtle.back()
- local tp2X, tp2Y, tp2Z = gps.locate()
- turtle.forward()
- if (tp1X == tp2X)
- then
- if (tp1Z > tp2Z)
- then
- currentDirection = "South"
- else
- currentDirection = "North"
- end
- else
- if (tp1X > tp2X)
- then
- currentDirection = "East"
- else
- currentDirection = "West"
- end
- end
- end
- function turnLeft()
- if (currentDirection == "North")
- then
- currentDirection = "West"
- elseif (currentDirection == "West")
- then
- currentDirection = "South"
- elseif (currentDirection == "South")
- then
- currentDirection = "East"
- else
- currentDirection = "North"
- end
- turtle.turnLeft()
- end
- function turnRight()
- if (currentDirection == "North")
- then
- currentDirection = "East"
- elseif (currentDirection == "East")
- then
- currentDirection = "South"
- elseif (currentDirection == "South")
- then
- currentDirection = "West"
- else
- currentDirection = "North"
- end
- turtle.turnRight()
- end
- function checkSideLogs()
- local index = 0
- while (index < 4)
- do
- local currentSideStatus, currentSideData = turtle.inspect()
- if (currentSideStatus and currentSideData.name == logName)
- then
- turtle.dig()
- turtle.forward()
- local hasSideLogs = false
- local tempStatus, tempData = turtle.inspectUp()
- if (tempStatus and tempData.name == logName)
- then
- hasSideLogs = true
- else
- local index2 = 0
- while (index2 < 4)
- do
- local tempSideStatus, tempSideData = turtle.inspect()
- if (tempSideStatus and tempSideData.name == logName)
- then
- hasSideLogs = true
- end
- index2 = index2 + 1
- end
- local tempSideStatus, tempSideData = turtle.inspectDown()
- if (tempSideStatus and tempSideData.name == logName)
- then
- hasSideLogs = true
- end
- end
- if (hasSideLogs)
- then
- tempGPSX, tempGPSY, tempGPSZ = gps.locate()
- sideLogs[numberOfSideLogs] = {
- x = tempGPSX,
- y = tempGPSY,
- Z = tempGPSZ
- }
- numberOfSideLogs = numberOfSideLogs + 1
- end
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- index = index + 1
- turtle.turnLeft()
- end
- local currentSideStatus, currentSideData = turtle.inspectDown()
- if (currentSideStatus and currentSideData.name == logName)
- then
- turtle.digDown()
- turtle.down()
- tempGPSX, tempGPSY, tempGPSZ = gps.locate()
- sideLogs[numberOfSideLogs] = {
- x = tempGPSX,
- y = tempGPSY,
- Z = tempGPSZ
- }
- numberOfSideLogs = numberOfSideLogs + 1
- turtle.up()
- end
- end
- function gotoSideLog()
- local clX, clY, clZ = gps.locate()
- local slX = sideLogs[0].x
- local slY = sideLogs[0].y
- local slZ = sideLogs[0].Z
- while (clY ~= slY)
- do
- if (clY > slY)
- then
- local currentSideStatus, currentSideData = turtle.inspectDown()
- if (currentSideStatus == false)
- then
- turtle.down()
- else
- if (currentSideData.name == leavesName)
- then
- turtle.digDown()
- turtle.down()
- elseif (currentSideData.name == logName)
- then
- turtle.digDown()
- turtle.down()
- tempGPSX, tempGPSY, tempGPSZ = gps.locate()
- sideLogs[numberOfSideLogs] = {
- x = tempGPSX,
- y = tempGPSY,
- Z = tempGPSZ
- }
- numberOfSideLogs = numberOfSideLogs + 1
- end
- end
- else
- local currentSideStatus, currentSideData = turtle.inspectUp()
- if (currentSideStatus == false)
- then
- turtle.up()
- else
- if (currentSideData.name == leavesName)
- then
- turtle.digUp()
- turtle.up()
- elseif (currentSideData.name == logName)
- then
- turtle.digUp()
- turtle.up()
- tempGPSX, tempGPSY, tempGPSZ = gps.locate()
- sideLogs[numberOfSideLogs] = {
- x = tempGPSX,
- y = tempGPSY,
- Z = tempGPSZ
- }
- numberOfSideLogs = numberOfSideLogs + 1
- end
- end
- end
- clX, clY, clZ = gps.locate()
- end
- while (clX ~= slX)
- do
- if (clX > slX)
- then
- while (currentDirection ~= "West")
- do
- turnLeft()
- end
- else
- while (currentDirection ~= "East")
- do
- turnLeft()
- end
- end
- local currentSideStatus, currentSideData = turtle.inspect()
- if (currentSideStatus == false)
- then
- turtle.forward()
- else
- if (currentSideData.name == leavesName)
- then
- turtle.dig()
- turtle.forward()
- elseif (currentSideData.name == logName)
- then
- turtle.dig()
- turtle.forward()
- tempGPSX, tempGPSY, tempGPSZ = gps.locate()
- sideLogs[numberOfSideLogs] = {
- x = tempGPSX,
- y = tempGPSY,
- Z = tempGPSZ
- }
- numberOfSideLogs = numberOfSideLogs + 1
- end
- end
- clX, clY, clZ = gps.locate()
- end
- while (clZ ~= slZ)
- do
- if (clZ > slZ)
- then
- while (currentDirection ~= "North")
- do
- turnLeft()
- end
- else
- while (currentDirection ~= "South")
- do
- turnLeft()
- end
- end
- local currentSideStatus, currentSideData = turtle.inspect()
- if (currentSideStatus == false)
- then
- turtle.forward()
- else
- if (currentSideData.name == leavesName)
- then
- turtle.dig()
- turtle.forward()
- elseif (currentSideData.name == logName)
- then
- turtle.dig()
- turtle.forward()
- tempGPSX, tempGPSY, tempGPSZ = gps.locate()
- sideLogs[numberOfSideLogs] = {
- x = tempGPSX,
- y = tempGPSY,
- Z = tempGPSZ
- }
- numberOfSideLogs = numberOfSideLogs + 1
- end
- end
- clX, clY, clZ = gps.locate()
- end
- end
- function lumberUntilSideLogsGone()
- getCurrentDirection()
- oX, oY, oZ = gps.locate()
- checkSideLogs()
- local looperStatus, looperData = turtle.inspectUp()
- while (looperStatus and looperData.name == logName) or (numberOfSideLogs ~= 0)
- do
- local upStatus, upData = turtle.inspectUp()
- if (upStatus and (upData.name == logName))
- then
- turtle.digUp()
- turtle.up()
- checkSideLogs()
- else
- gotoSideLog()
- numberOfSideLogs = numberOfSideLogs - 1
- table.remove(sideLogs, 0)
- checkSideLogs()
- end
- looperStatus, looperData = turtle.inspectUp()
- end
- local cX, cY, cZ = gps.locate()
- while (cY ~= oY)
- do
- if (cY > oY)
- then
- local currentSideStatus, currentSideData = turtle.inspectDown()
- if (currentSideStatus == false)
- then
- turtle.down()
- else
- if (currentSideData.name == logName)
- then
- tempGPSX, tempGPSY, tempGPSZ = gps.locate()
- sideLogs[numberOfSideLogs] = {
- x = tempGPSX,
- y = tempGPSY,
- Z = tempGPSZ
- }
- lumberUntilSideLogsGone()
- end
- turtle.digDown()
- turtle.down()
- end
- else
- local currentSideStatus, currentSideData = turtle.inspectUp()
- if (currentSideStatus == false)
- then
- turtle.up()
- else
- if (currentSideData.name == logName)
- then
- tempGPSX, tempGPSY, tempGPSZ = gps.locate()
- sideLogs[numberOfSideLogs] = {
- x = tempGPSX,
- y = tempGPSY,
- Z = tempGPSZ
- }
- lumberUntilSideLogsGone()
- end
- turtle.digUp()
- turtle.up()
- end
- end
- cX, cY, cZ = gps.locate()
- end
- turtle.up()
- end
- lumberUntilSideLogsGone()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement