Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("clear")
- print("== MATIX'S FARMING SCRIPT ==\nThanks for using Matix's farming script.\n\nLogs:")
- Directions = {
- LEFT = 0,
- RIGHT = 1
- }
- -- Checks the fuel and refills the turtle
- function CheckFuel()
- if turtle.getFuelLevel() < 2 then
- if turtle.getItemCount(1) > 0 then
- print("INFO: Refilling")
- turtle.select(1)
- turtle.refuel(1)
- else
- print("WARN: OUT OF FUEL! Need fuel refill in first slot.")
- -- loop and wait for refuel
- repeat
- sleep(1)
- until turtle.getItemCount(1) > 0
- end
- end
- end
- -- Till the block below the turtle
- function TillBelow()
- if not turtle.detectDown() then
- turtle.digDown()
- end
- end
- function PickupItems()
- turtle.select(2)
- turtle.suckDown()
- end
- local notifiedAboutEmptyCrops = false
- -- Place and farm crops
- function PlaceAndFarm()
- BlockDetected, BlockData = turtle.inspectDown()
- if BlockDetected then
- if BlockData.state.age == 7 then
- turtle.select(2)
- turtle.digDown()
- sleep(0.2)
- end
- end
- if not turtle.detectDown() then
- if turtle.getItemCount(2) > 0 then
- notifiedAboutEmptyCrops = false
- turtle.select(2)
- turtle.placeDown()
- else
- if not notifiedAboutEmptyCrops then
- notifiedAboutEmptyCrops = true
- print("WARN: NO SEEDS OR CROPS in slot 2 of turtle inventory.")
- end
- end
- end
- end
- -- Check if block is above turtle. If a block is above the turtle, then it assumes it is a chest.
- function PlaceItemsInChest()
- if turtle.detectUp() then
- print("INFO: Placing items in chest")
- for slot = 3, 16 do
- turtle.select(slot)
- turtle.dropUp()
- end
- end
- end
- local lastDirection = Directions.RIGHT
- -- Checks the turtles position and moves it
- function PerformMovement()
- if turtle.detect() then
- if lastDirection == Directions.RIGHT then
- lastDirection = Directions.LEFT
- turtle.turnLeft()
- if not turtle.detect() then
- turtle.forward()
- turtle.turnLeft()
- else
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- lastDirection = Directions.RIGHT
- end
- else
- lastDirection = Directions.RIGHT
- turtle.turnRight()
- if not turtle.detect() then
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnRight()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- lastDirection = Directions.LEFT
- end
- end
- else
- turtle.forward()
- end
- end
- print("INFO: Starting main loop...")
- -- Main loop
- repeat
- CheckFuel()
- TillBelow()
- PlaceAndFarm()
- PickupItems()
- PlaceItemsInChest()
- PerformMovement()
- until false
- print("ERROR: Farming script ended natrually. THIS SHOULD NOT HAPPEN!")
Add Comment
Please, Sign In to add comment