Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- #######################################################
- # Author: Fat_Cobra #
- # Version: 2.0 #
- # Date: 4/16/2022 #
- #######################################################
- USAGE:
- 1) Seeds to be planted should be placed in top left slot (1).
- 2) Place a single seed in the bottom right slot (16) for identification.
- --]]
- function init ()
- term.clear()
- term.setCursorPos(1,1)
- -- check what the turtle is planting
- local data = turtle.getItemDetail(16)
- if data then
- planting = data.name
- else
- print("-F- I don't know what to plant.")
- error()
- end
- -- Make sure the turtle has items to plant
- local data = turtle.getItemDetail(1)
- if data and data.name == planting then
- else
- print("-F- I have nothing to plant.")
- error()
- end
- -- Set up global variables
- direction = 1
- title = os.getComputerLabel()
- farming = false
- sTime = 300
- ageCheck = 7
- if string.match(data.name, "finallyfarmabledyes") then
- ageCheck = 3
- end
- if not title then
- title = planting
- os.setComputerLabel(title)
- end
- print("Hello,")
- print("My name is '", title, "'.")
- print("I am planting:")
- print(" ", planting)
- end
- function rTurn ()
- turtle.turnRight()
- direction = direction + 1
- if direction > 4 then
- direction = 1
- end
- end
- function lTurn ()
- turtle.turnLeft()
- direction = direction - 1
- if direction < 1 then
- direction = 4
- end
- end
- function findHome()
- notHome = true
- while notHome do
- if not turtle.forward() then
- local success,data = turtle.inspect()
- if success and string.match(string.lower(data.name), "chest") then
- notHome = false
- else
- turtle.turnLeft()
- end
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- isHome()
- end
- function isHome ()
- rTurn()
- rTurn()
- local success, data = turtle.inspect()
- if success and string.match(string.lower(data.name), "chest") then
- lTurn()
- lTurn()
- direction = 1
- return true
- else
- findHome()
- end
- end
- function sortInventory ()
- for i=15,2,-1 do
- turtle.select(i)
- if turtle.compareTo(16) then
- turtle.transferTo(1)
- end
- end
- end
- function unloadInventory ()
- if isHome() then
- rTurn()
- rTurn()
- for i=15,2,-1 do
- turtle.select(i)
- turtle.drop()
- end
- rTurn()
- rTurn()
- end
- end
- function goF ()
- if turtle.forward() then
- local success, data = turtle.inspectDown()
- if success then
- if data.state["age"] >= ageCheck then
- turtle.select(1)
- turtle.digDown()
- turtle.placeDown()
- end
- else
- turtle.digDown()
- turtle.placeDown()
- end
- turtle.suckDown()
- return true
- else
- return false
- end
- end
- function farm ()
- if isHome() then
- farming = true
- turtle.select(1)
- else
- error()
- end
- while farming do
- if not goF() then
- if direction == 1 then
- rTurn()
- if goF() then
- rTurn()
- else
- farming = false
- end
- elseif direction == 3 then
- lTurn()
- if goF() then
- lTurn()
- else
- farming = false
- end
- else
- error()
- end
- end
- end
- lTurn()
- lTurn()
- findHome()
- end
- --[[
- Main program
- ]]--
- init()
- isHome()
- sortInventory()
- unloadInventory()
- while true do
- farm()
- sortInventory()
- unloadInventory()
- sleep(sTime)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement