Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #############################
- -- Right-hand Farming
- -- version 0.1
- -- http://hevohevo.hatenablog.com/
- -- Features:
- -- - Implements Right-hand Maze algorithm
- -- - Requires redstone signal for detecting right side wall
- -- - Turtle can restart from the last interruption, if this program's name is "startup"
- -- TOP View(o: millets, R: redstone signal, T: Home position)
- -- RRRRRRRRRR
- -- RooRooRooR
- -- RooRooRooR
- -- RooRooRooR
- -- RooRooRooR
- -- R R
- -- RRRRRRRRTR
- -- RRR
- -- config
- MIN_FUEL_LEVEL = 1000
- SLEEP_TIME = 300
- -- functions
- function count_items()
- local sum = 0
- for i=1,16 do
- sum = sum + turtle.getItemCount(i)
- end
- return sum
- end
- function drop_all()
- for i=1,16 do
- turtle.select(i)
- turtle.dropUp()
- end
- turtle.select(1)
- end
- function fwd_and_dig()
- if rs.getInput("front") then return end
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- end
- function get_fuel()
- if turtle.getFuelLevel() < MIN_FUEL_LEVEL then
- turtle.suck()
- turtle.refuel()
- if turtle.getFuelLevel() < MIN_FUEL_LEVEL then
- error("More fuel!")
- end
- end
- end
- -- main
- turtle.select(1)
- while true do
- while true do
- -- Home Position
- if turtle.detectUp() and count_items() > 0 then
- print('drop')
- drop_all()
- get_fuel()
- turtle.turnRight()
- turtle.turnRight()
- os.sleep(SLEEP_TIME)
- fwd_and_dig()
- break
- end
- if not rs.getInput("right") then
- turtle.turnRight()
- fwd_and_dig()
- break
- end
- if rs.getInput("front") then
- turtle.turnLeft()
- fwd_and_dig()
- break
- end
- fwd_and_dig()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement