Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --pastebin get Wn9kYJcT farm
- local lenght,width = 9,9
- local pos = {
- ["x"] = 0,
- ["y"] = -1,
- }
- local direction = {
- ["forw"] = 1,
- ["right"] = 2,
- ["back"] = 3,
- ["left"] = 4,
- }
- local dir = direction.forw
- local function farm()
- turtle.digDown()
- turtle.placeDown()
- end
- local function takeSeeds()
- turtle.select(1)
- local ammount = lenght * width
- if ammount > 64 then ammount = 64 end
- if turtle.getItemCount(1) < ammount then
- print("Don't have seeds")
- end
- while turtle.getItemCount(1) < ammount do
- turtle.suckDown()
- os.sleep(1)
- end
- print("I took the seeds")
- end
- local function returnSupplies()
- for i = 2,16 do
- if turtle.getItemCount(i)>0 then
- turtle.select(i)
- turtle.drop()
- end
- end
- turtle.select(1)
- end
- local function turnRight()
- dir = dir + 1
- if dir == 5 then dir = direction.forw end
- -- saveState()
- turtle.turnRight()
- end
- local function turnLeft()
- dir = dir - 1
- if dir == 0 then dir = direction.left end
- -- saveState()
- turtle.turnLeft()
- end
- local function forward()
- turtle.forward()
- if dir == direction.forw then
- pos.y = pos.y + 1
- elseif dir == direction.right then
- pos.x = pos.x + 1
- elseif dir == direction.back then
- pos.y = pos.y - 1
- elseif dir == direction.left then
- pos.x = pos.x - 1
- end
- end
- function goTo( x, y, d)
- if pos.x > x then
- while dir ~= direction.left do
- turnRight()
- end
- while pos.x > x do
- forward()
- end
- elseif pos.x < x then
- while dir ~= direction.right do
- turnRight()
- end
- while pos.x < x do
- forward()
- end
- end
- if pos.y > y then
- while dir ~= direction.back do
- turnLeft()
- end
- while pos.y > y do
- forward()
- end
- elseif pos.y < y then
- while dir ~= direction.forw do
- turnLeft()
- end
- while pos.y < y do
- forward()
- end
- end
- while d ~= dir do
- turnLeft()
- end
- end
- local function endFarm()
- return (pos.x == width - 1) and ((pos.y == lenght - 1 and math.fmod(pos.x,2) == 0) or (pos.y == 0 and math.fmod(pos.x,2) == 1))
- end
- local function main()
- while not endFarm() do
- if math.fmod(pos.x,2) == 0 then -- 010101
- if pos.y == lenght-1 then
- if dir == direction.forw then
- turnRight()
- elseif dir == direction.right then
- forward()
- farm()
- end
- elseif pos.y == 0 and dir == direction.right then
- turnLeft()
- else
- forward()
- farm()
- end
- else
- if pos.y == 0 then
- if dir == direction.back then
- turnLeft()
- elseif dir == direction.right then
- forward()
- farm()
- end
- elseif pos.y == lenght-1 and dir == direction.right then
- turnRight()
- else
- forward()
- farm()
- end
- end
- end
- goTo( 0, -1, direction.back)
- returnSupplies()
- goTo( 0, -1, direction.forw)
- end
- while true do
- if redstone.getInput("top") == true then
- takeSeeds()
- main()
- end
- os.sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement