Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- List of keywords that the turtle will use to figure out what to plant
- local ACCEPTABLE_SEEDS = {
- "seed",
- "minecraft:carrot",
- "minecraft:potato",
- "minecraft:nether_wart"
- }
- -- List of keywords that the turtle will use to figure out what to break
- local ACCEPTABLE_PLANTS = {
- "croptopia:",
- "carrot",
- "wheat",
- "beetroot",
- "potato",
- "nether_wart"
- }
- local posLib = require("posLib")
- local invLib = require("invLib")
- local farmX, farmY, farmZ, farmHeading, length, width, direction
- function getCoordinatesFromFile()
- local farmSettings = fs.open("FARM_STATS", "r")
- farmX = tonumber(farmSettings.readLine())
- farmY = tonumber(farmSettings.readLine())
- farmZ = tonumber(farmSettings.readLine())
- farmSettings.close()
- return farmX, farmY, farmZ
- end
- function getHeadingFromFile()
- local farmSettings = fs.open("FARM_STATS", "r")
- for _ = 1, 3 do
- farmSettings.readLine()
- end
- farmHeading = tonumber(farmSettings.readLine())
- farmSettings.close()
- return farmHeading
- end
- function getDimensionsFromFile()
- local farmSettings = fs.open("FARM_STATS", "r")
- for _ = 1, 4 do
- farmSettings.readLine()
- end
- length = tonumber(farmSettings.readLine())
- width = tonumber(farmSettings.readLine())
- farmSettings.close()
- return length, width
- end
- function getDirectionFromFile()
- local farmSettings = fs.open("FARM_STATS", "r")
- for _ = 1, 6 do
- farmSettings.readLine()
- end
- direction = farmSettings.readLine()
- farmSettings.close()
- return direction
- end
- function getAllInformationFromFile()
- local farmSettings = fs.open("FARM_STATS", "r")
- local farminfo = {}
- farminfo["farmX"] = tonumber(farmSettings.readLine())
- farminfo["farmY"] = tonumber(farmSettings.readLine())
- farminfo["farmZ"] = tonumber(farmSettings.readLine())
- farminfo["farmHeading"] = tonumber(farmSettings.readLine())
- farminfo["length"] = tonumber(farmSettings.readLine())
- farminfo["width"] = tonumber(farmSettings.readLine())
- farminfo["direction"] = farmSettings.readLine()
- farmSettings.close()
- return farminfo
- end
- local farmInfo = getAllInformationFromFile()
- local firstTurn
- if (farmInfo["direction"] == "LEFT") then
- firstTurn = posLib.turnLeft
- else
- firstTurn = posLib.turnRight
- end
- local lastSeedIndex = findSlot(ACCEPTABLE_SEEDS, 1, 16)
- function moveToStart()
- posLib.moveTo(farmInfo["farmX"], farmInfo["farmY"], farmInfo["farmZ"])
- posLib.faceHeading(farmInfo["farmHeading"])
- end
- function plantSeed()
- if (not lastSeedIndex) then
- lastSeedIndex = findSlot(ACCEPTABLE_SEEDS, 1, 16)
- if (not lastSeedIndex) then
- return
- end
- end
- turtle.select(lastSeedIndex)
- turtle.placeDown()
- end
- function harvestBlock()
- local isBlock, blockData = turtle.inspectDown()
- if (isBlock) then
- for index, name in ACCEPTABLE_PLANTS do
- if (blockData['name'] == name and blockData['age'] == 7) then
- turtle.digDown()
- plantSeed()
- break
- end
- end
- return
- end
- plantSeed()
- end
- -- RUNS = MATH.MIN(length, width)*2 - 1
- -- TURNS = RUNS - 1
- -- 0 -1 -1 -2 -2 -3 -3 ...
- -- START AT 0, THE NEXT TWO ARE ONE LESS PERMANENTLY
- -- ALWAYS ENDS ON LENGTH IF STARTS BY LENGTH
- function riceFarm()
- local l = length
- while (l > 0) do
- posLib.forward()
- harvestBlock()
- l = l - 1
- end
- local w = width - 1
- if (w <= 0) then return end
- firstTurn()
- while (w > 0) do
- posLib.forward()
- harvestBlock()
- w = w - 1
- end
- firstTurn()
- length = length - 1
- width = width - 1
- return riceFarm()
- end
- return { getCoordinatesFromFile = getCoordinatesFromFile, getHeadingFromFile = getHeadingFromFile,
- getDimensionsFromFile = getDimensionsFromFile, getDirectionFromFile = getDirectionFromFile,
- getAllInformationFromFile = getAllInformationFromFile, moveToStart = moveToStart, plantSeed = plantSeed,
- harvestBlock = harvestBlock, riceFarm = riceFarm }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement