Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _G["xPos"] = 0
- _G["yPos"] = 0
- _G["dir"] = 0
- _G["xSize"] = 0
- _G["ySize"] = 0
- _G["requiredFuel"] = 0
- _G["farmTime"] = 0
- args = {...}
- if args[0] == nil then
- xSize = 9
- ySize = 9
- farmTime = 60
- elseif args[0] ~= nil then
- if #args > 1 then
- xSize = tonumber(args[1])
- ySize = tonumber(args[2])
- farmTime = tonumber(args[3])
- if farmTime == nil then
- farmTime = 60
- end
- if xSize == nil or ySize == nil then
- print("Usage: "..shell.getRunningProgram().." [<xSize> <ySize>] [secondsToWait]")
- return
- end
- else
- farmTime = tonumber(args[1])
- if farmTime == nil then
- print("Usage: "..shell.getRunningProgram().." [secondsToWait]")
- end
- end
- end
- requiredFuel = xSize * ySize + xSize + ySize
- function moveForward()
- while not turtle.forward() do
- sleep(1)
- end
- if dir == 0 then
- yPos = yPos + 1
- elseif dir == 1 then
- xPos = xPos + 1
- elseif dir == 2 then
- yPos = yPos - 1
- elseif dir == 3 then
- xPos = xPos - 1
- end
- end
- function moveBack()
- while not turtle.back() do
- sleep(1)
- end
- if dir == 0 then
- yPos = yPos - 1
- elseif dir == 1 then
- xPos = xPos - 1
- elseif dir == 2 then
- yPos = yPos + 1
- elseif dir == 3 then
- xPos = xPos + 1
- end
- end
- function turnLeft()
- turtle.turnLeft()
- dir = (dir + 1) % 4
- end
- function turnRight()
- turtle.turnRight()
- dir = (dir - 1) % 4
- end
- function faceDirection(n)
- while dir ~= n do
- if dir < n then
- if math.abs(dir - n) < 2 then
- turnLeft()
- else
- turnRight()
- end
- else
- if math.abs(dir - n) < 2 then
- turnRight()
- else
- turnLeft()
- end
- end
- end
- end
- function returnHome()
- faceDirection(2)
- for i = 1,yPos do
- turtle.forward()
- end
- faceDirection(3)
- for i = 1,xPos do
- turtle.forward()
- end
- faceDirection(0)
- xPos = 0
- yPos = 0
- end
- function dumpItems()
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 then
- if string.find(turtle.getItemDetail(i).name, "charcoal") == nil then
- turtle.select(i)
- turtle.dropDown()
- end
- end
- end
- end
- function placeCrop()
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 then
- if string.find(turtle.getItemDetail(i).name,"seed") then
- turtle.select(i)
- turtle.placeDown()
- break
- end
- end
- end
- end
- function harvestCrop()
- found, block = turtle.inspectDown()
- if found then
- if block["state"]["age"] then
- if block["state"]["age"] == 7 then
- turtle.digDown()
- placeCrop()
- end
- end
- end
- end
- function awaitFuel()
- rs.setOutput("top", true)
- for i = 1,16 do
- turtle.select(i)
- turtle.refuel()
- if turtle.getFuelLevel() >= requiredFuel then
- break
- end
- end
- rs.setOutput("top", false)
- end
- while true do
- if turtle.getFuelLevel() >= requiredFuel then
- moveForward()
- harvestCrop()
- for x = 1,9 do
- for y = 1,8 do
- moveForward()
- harvestCrop()
- end
- if x ~= 9 then
- faceDirection(1)
- moveForward()
- harvestCrop()
- if x % 2 == 0 then
- faceDirection(0)
- else
- faceDirection(2)
- end
- end
- end
- returnHome()
- parallel.waitForAll(
- function()
- sleep(farmTime)
- end,
- function()
- dumpItems()
- end)
- else
- awaitFuel()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment