Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("TurtleLib/generalLibrary")
- SEED_LIST = { "croptopia", "seed", "carrot" }
- SEED_LIST_SIZE = tableLength(SEED_LIST)
- function getSeedIndex()
- return findSlot(SEED_LIST)
- end
- function checkForCrop(data)
- for value in ipairs(SEED_LIST) do
- if (string.match(data['name'], value) == true and data['state']['age'] == 7) then return true end
- end
- return false
- end
- function getCrop()
- local isBlock, data = turtle.inspectDown()
- if (isBlock) then
- if (checkForCrop(data)) then
- turtle.digDown()
- else
- return
- end
- end
- local seedIndex = getSeedIndex()
- if (seedIndex ~= -1) then
- turtle.select(seedIndex)
- turtle.placeDown()
- end
- end
- function resetPos()
- local file = fs.open("Settings", "r")
- local startX = tonumber(file.readLine())
- local startY = tonumber(file.readLine())
- local startZ = tonumber(file.readLine())
- file.readLine()
- file.readLine()
- file.readLine()
- local direction = file.readLine()
- file.close()
- moveTo(startX, startY, startZ)
- faceDirection(direction)
- end
- function checkPos()
- local startX, startY, startZ = getCoordinates()
- local startDirection = getDirection()
- os.sleep(1)
- local file = fs.open("Settings", "r")
- local posX = file.readLine()
- local posY = file.readLine()
- local posZ = file.readLine()
- skipLines(file, 3)
- local posDirection = file.readLine()
- if (startX == posX and startY == posY and startZ == posZ and startDirection == posDirection) then
- return true
- else
- return false
- end
- end
- function farm()
- local file = fs.open("Settings", "r")
- skipLines(file, 3)
- local length = file.readLine()
- local width = file.readLine()
- local orientation = file.readLine()
- local firstTurn
- if (orientation == "LEFT") then
- firstTurn = turtle.turnLeft
- else
- firstTurn = turtle.turnRight
- end
- keepDigging()
- turtle.forward()
- firstTurn()
- for row = 1, length do
- for col = 1, width - 1 do
- getCrop()
- keepDigging()
- turtle.forward()
- end
- getCrop()
- oppositeTurn(firstTurn)
- turtle.forward()
- firstTurn = oppositeTurn(firstTurn)
- end
- resetPos()
- if (not checkPos()) then
- error("TURTLE HAS NOT GONE TO ORIGINAL FARMING COORDINATES! ANALYZE CODE!")
- else
- printColor(colors.green, "TURTLE HAS SUCCESSFULLY RESET ITS POSITION!\n\nREADY TO RESTART...")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement