Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --SugarCane farm by janek222
- --Version 1.0 Beta
- --Variables
- local fuel = turtle.getFuelLevel()
- local distance
- local readlength
- local length = tonumber(readlength)
- local i = 1
- local success, data = turtle.inspect()
- local busy = false
- local cane = turtle.getItemCount(1)
- --Functions
- function start()
- busy = true
- turtle.digDown()
- turtle.select(8)
- turtle.placeDown()
- --Place chest /\
- turtle.forward()
- turtle.digDown()
- turtle.select(13)
- turtle.placeDown()
- --1
- turtle.forward()
- turtle.digDown()
- turtle.turnLeft()
- --2
- turtle.forward()
- turtle.digDown()
- turtle.select(14)
- turtle.placeDown()
- turtle.turnLeft()
- --3
- turtle.forward()
- turtle.digDown()
- turtle.turnLeft()
- --4
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- --2x2 infinite water source
- for i = 1,length do
- turtle.digDown()
- turtle.forward()
- end
- --Left row
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- for i = 1,length do
- turtle.forward()
- end
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- --Center
- turtle.back()
- turtle.select(13)
- turtle.place()
- os.sleep(1)
- turtle.select(14)
- turtle.place()
- --Refill buckets
- repeat
- turtle.forward()
- turtle.select(13)
- turtle.placeDown()
- turtle.forward()
- turtle.select(14)
- turtle.placeDown()
- distance = distance + 2
- turtle.back()
- turtle.select(13)
- turtle.placeDown()
- os.sleep(1)
- turtle.select(14)
- turtle.placeDown()
- turtle.forward()
- turtle.forward()
- until distance > length
- --Water rows
- for i = 1,length do
- turtle.back()
- turtle.turnLeft()
- turtle.select(3)
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnLeft()
- busy = false
- end
- end
- function harvest()
- term.clear()
- print("Waiting for canes to grow... It'll take 10 minutes.")
- os.sleep(600)
- print("Harvesting...")
- busy = true
- turtle.up()
- turtle.up()
- for i = 1,length do
- turtle.forward()
- turtle.turnLeft()
- if data.name == minecraft:reeds then
- turtle.dig()
- print("Harvested 1 sugarcane block")
- end
- turtle.turnRight()
- turtle.turnRight()
- if data.name == minecraft:reeds then
- turtle.dig()
- print("Harvested 1 sugarcane block")
- end
- turtle.turnLeft()
- end
- turtle.down()
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1,length do
- turtle.turnLeft()
- if data.name == minecraft:reeds then
- turtle.dig()
- print("Harvested 1 sugarcane block")
- end
- turtle.turnRight()
- turtle.turnRight()
- if data.name == minecraft:reeds then
- turtle.dig()
- print("Harvested 1 sugarcane block")
- end
- turtle.turnLeft()
- turtle.forward()
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- busy = false
- end
- function chest()
- busy = true
- repeat
- turtle.back()
- until data.name == minecraft:chest
- turtle.select(1)
- turtle.dropDown()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- busy = false
- end
- end
- function getfuel()
- busy = true
- turtle.select(5)
- repeat
- turtle.back()
- until data.name == minecraft:chest
- turtle.suckDown()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- busy = false
- end
- --Code
- print("SugarCane farm by janek222")
- write("Enter length of farm:")
- local readlength = read()
- term.clear()
- print("Need fuel for startup. Add it to slot 5 and press any key to continue.")
- os.pullEvent("key")
- repeat
- turtle.select(5)
- if turtle.refuel(0) then
- turtle.refuel(1)
- end
- until fuel > 3000
- term.clear()
- print("Materials needed:")
- print("Slot 3 - Sugar Cane")
- print("Slot 13,14 - Water Bucket")
- print("Slot 8 - Chest (1)")
- print("Slot 5 - Fuel")
- print("Beware! If you don't give the turtle enough materials it may behave very weird")
- print("Press any key to continue...")
- os.pullEvent("key")
- term.clear()
- start()
- while true do
- if fuel < 1000 and busy = false then
- print("Low fuel! Attempt to refuel...")
- turtle.select(5)
- repeat
- turtle.refuel(1)
- until fuel > 1500
- getfuel()
- else
- harvest()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment