Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local length = 18
- local width = 18
- local fuel_slot = 1
- local fuel_minimum = length*width+length+width+10
- local seed_slot = 2
- local seconds_to_wait = 600
- local wait_first = false
- local deposit = false
- local deposit_direction = 3
- local b = false
- local block = nil
- local farming = true
- local turn_adjust = 1
- os.loadAPI("grey_api/move.lua")
- os.loadAPI("grey_api/util.lua")
- function farm_wheat(length,width)
- if length==nil then length=9 end--length is the forward size of the wheat plot
- if width==nil then width=9 end--width is the right size of the wheat plot
- turn_adjust = 1-- 1=+x, -1=-x
- while farming do
- harvest_wheat()
- if move.get_x() >= length-1 and turn_adjust == 1 then
- if move.get_z() >= width-1 then
- move.return_to_home()
- end_run()
- else
- move.turn("right")
- move.go()
- harvest_wheat()
- move.turn("right")
- move.go()
- turn_adjust = turn_adjust * -1
- end
- elseif move.get_x() <= 0 and turn_adjust == -1 then
- if move.get_z() >= width-1 then
- move.return_to_home()
- end_run()
- else
- move.turn("left")
- move.go()
- harvest_wheat()
- move.turn("left")
- move.go()
- turn_adjust = turn_adjust * -1
- end
- else
- if not move.go() then
- return false
- end
- end
- end--end while farming
- end
- function end_run()
- if deposit then deposit() end
- util.wait(seconds_to_wait)
- turn_adjust = 1
- print("wait done")
- end
- function deposit()
- local item = nil
- move.face(deposit_direction)
- for i=1,16 do
- item = turtle.getItemDetail(i)
- if item ~= nil and (item["name"]=="minecraft:wheat_seeds" or item["name"]=="minecraft:wheat") then
- --print("dropped "..item["name"].. " from slot "..i)
- turtle.select(i)
- turtle.drop()
- end
- end
- move.face(0)
- end
- function harvest_wheat()
- b,block = turtle.inspectDown()
- if b == false then
- --print("No block at ("..move.get_x()..","..move.get_z()..")")
- find_seed_slot()
- turtle.select(seed_slot)
- if not turtle.placeDown() then
- print("unplantable block at ("..move.get_x()..","..move.get_z()..")")
- end
- elseif block['state']['age']==7 then
- turtle.digDown()
- --print("Harvested at ("..move.get_x()..","..move.get_z()..")")
- find_seed_slot()
- turtle.select(seed_slot)
- turtle.placeDown()
- else
- --print("age!=7 at ("..move.get_x()..","..move.get_z()..")")
- end
- if turtle.getFuelLevel() <= fuel_minimum then
- util.fuel(1)
- end
- end
- function find_seed_slot()
- for i=1,16 do
- local item = turtle.getItemDetail(i)
- if item ~= nil and item["name"] == "minecraft:wheat_seeds" then
- seed_slot = i
- return i
- end
- end
- return 0
- end
- if wait_first then
- util.wait(seconds_to_wait)
- end
- farm_wheat(length,width)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement