Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (not fs.exists("posLib")) then shell.run("pastebin get https://pastebin.com/1DQsNF8k posLib") end
- if (not fs.exists("invLib")) then shell.run("pastebin get https://pastebin.com/019TAz4k invLib") end
- if (not fs.exists("FARM_STATS")) then
- shell.run("pastebin get https://pastebin.com/CRsg1kwR farmSetup")
- error("PLEASE RUN FARM SETUP!")
- end
- -- List of keywords that the turtle will use to figure out what to break & what to plant
- local ACCEPTABLE_SEEDS = {
- "croptopia:",
- "minecraft:carrot",
- "minecraft:potato",
- "minecraft:wheat",
- "minecraft:beetroot",
- "minecraft:nether_wart"
- }
- local posLib = require("posLib")
- local invLib = require("invLib")
- -- farmSetupTable refers to the (organized) listing of data that the turtle will use to figure out its base conditions before starting
- -- startX, startY, startZ, startHeading, length, width, direction)
- local farmStats = fs.open("FARM_STATS", "r")
- local farmSetupTable = {}
- local index = 1
- for line in io.lines("FARM_STATS") do
- farmSetupTable[index] = line
- index = index + 1
- end
- local length = tonumber(farmSetupTable[5])
- local width = tonumber(farmSetupTable[6])
- local farmDirection
- if (farmSetupTable[7] == "LEFT") then farmDirection = posLib.turnLeft else farmDirection = posLib.turnRight end
- function reorient()
- posLib.updateStats()
- local turtleX, turtleY, turtleZ = posLib.getCoordinates()
- print(turtleX .. " " .. turtleY .. " " .. turtleZ)
- local farmX = tonumber(farmSetupTable[1])
- local farmY = tonumber(farmSetupTable[2])
- local farmZ = tonumber(farmSetupTable[3])
- if (turtleX ~= farmSetupTable[1] or turtleY ~= farmSetupTable[2] or turtleZ ~= farmSetupTable[3]) then
- posLib.moveTo(farmX, farmY, farmZ)
- end
- local farmHeading = tonumber(farmSetupTable[4])
- posLib.faceHeading(farmHeading)
- end
- function harvestBlock()
- local isBlock, data = turtle.inspectDown()
- if (isBlock == true) then
- turtle.digDown()
- local seedIndex = findSlot(ACCEPTABLE_SEEDS)
- if (seedIndex ~= nil) then
- turtle.select(seedIndex)
- turtle.placeDown()
- end
- else
- local seedIndex = findSlot(ACCEPTABLE_SEEDS)
- turtle.select(seedIndex)
- turtle.placeDown()
- end
- 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
- farmDirection()
- while (w > 0) do
- posLib.forward()
- harvestBlock()
- w = w - 1
- end
- farmDirection()
- length = length - 1
- width = width - 1
- return riceFarm()
- end
- return { reorient = reorient, riceFarm = riceFarm }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement