Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Sugarcane Harvesting
- -- By fenthis
- depth = 15
- width = 15
- delay = 120 -- Delay in seconds between runs
- total_count = 0
- function do_left_or_right(dir)
- if dir then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- function is_odd(n)
- return ((n % 2) == 1)
- end
- function try_n(times)
- for i = 1, times do
- act.try()
- end
- end
- function harvest()
- -- Into first square
- turtle.up()
- act.try()
- -- Loop through the field.
- for r = 1,width do
- for x = 1,depth do
- turtle.digDown()
- if x ~= depth then
- act.try()
- end
- end
- if (r ~= width) then
- do_left_or_right(is_odd(r))
- act.try()
- do_left_or_right(is_odd(r))
- end
- end
- -- Return
- if not is_odd(width) then
- act.try()
- else
- -- In case it's regrown
- turtle.up()
- turtle.turnLeft()
- turtle.turnLeft()
- try_n(depth)
- turtle.down()
- end
- turtle.turnLeft()
- try_n(width - 1)
- turtle.down()
- -- Ok, chest time
- turtle.turnRight()
- count = 0
- for i = 1, 16 do
- items = turtle.getItemCount(i)
- count = count + items
- if items > 0 then
- turtle.select(i)
- turtle.drop()
- end
- end
- total_count = total_count + count
- turtle.turnLeft()
- turtle.turnLeft()
- print("Harvest complete, collected " .. count .. " items for a total of " ..
- total_count .. " with " .. turtle.getFuelLevel() .. " fuel remaining.")
- end
- -- Do something
- print("Running with a delay of " .. delay .. " seconds. Press Q to quit.")
- while true do
- -- First, go for it.
- harvest()
- -- Then wait
- os.startTimer(delay)
- repeat
- e, a1 = os.pullEvent()
- if e == "char" and (a1 == "Q" or a1 == "q") then
- print("Quitting!")
- return
- end
- until e == "timer"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement