Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- to come back to original values after one whole loop
- local backupX
- local backupY
- local timesx
- local timesy
- local timesxBackup = 0 -- save value for each row
- local timesyBackup = 0
- -- if work interrupted by anything, continue on position
- local returnPointX = 0
- local returnPointY = 0
- local Totaltimes = 0
- local checkpointDigs
- local isDown = false
- -- return to chest and deposit
- function Return()
- checkpointDigs = 200 -- reset checkpoint counter
- print("Master, im full. Heading back to deposit.")
- returnPointX = timesx
- returnPointY = timesy
- if isDown == false then -- if straight
- print("up")
- turtle.turnLeft()
- if (timesyBackup - timesy) >= 1 then
- for i=0,(timesyBackup - timesy - 1) do
- turtle.forward()
- end
- end
- turtle.turnLeft()
- local iBackx = (timesxBackup - timesx)
- for i=0,iBackx do
- turtle.forward()
- end
- turtle.turnRight()
- turtle.turnRight()
- else -- if turtle comes down
- -- when not at 0 we need to add 1 step
- local down = timesx
- if not timesx == 0 then
- down = down + 1
- end
- for i=0,down do
- turtle.forward()
- end
- turtle.turnRight()
- local iBacky = (timesyBackup - timesy)
- if iBacky >= 1 then
- for i=0,(timesyBackup - timesy - 1) do
- turtle.forward()
- end
- else
- for i=0,timesyBackup - 1 do
- turtle.forward()
- end
- end
- turtle.turnRight()
- end
- -- back to chest
- --turtle.back()
- turtle.down()
- turtle.down()
- turtle.turnRight()
- turtle.turnRight()
- local invcount = 1
- repeat
- turtle.select(1+invcount)
- turtle.drop()
- invcount = invcount + 1
- until invcount == 16
- turtle.select(1)
- turtle.turnRight()
- turtle.turnRight()
- turtle.up()
- end
- -- continue where it left
- function Continue()
- -- used for counting
- local tempX = returnPointX
- local tempY = returnPointY
- print("Going back to work at:",returnPointX, returnPointY)
- -- if straight
- if isDown == false then
- for i=0, (timesxBackup - returnPointX) do
- turtle.forward()
- end
- turtle.turnRight()
- if (timesyBackup - returnPointY) >= 1 then
- for i=0, (timesyBackup - returnPointY) do
- turtle.forward()
- end
- end
- turtle.turnLeft()
- -- if turtle comes dow
- else
- turtle.turnRight()
- if (timesyBackup - returnPointY) > 1 then
- for i=0, (timesyBackup - returnPointY - 1) do
- turtle.forward()
- end
- elseif (timesyBackup - returnPointY) == 1 then
- turtle.forward()
- end
- turtle.turnLeft()
- for i=0, returnPointX do
- turtle.forward()
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- -- restore pos
- timesx = returnPointX
- timesy = returnPointY
- end
- -- place, till and farm
- function work(inTransition)
- inTransition = inTransition or false
- -- print("X Y: ", timesx, timesy)
- -- print("Blocks before return: ", checkpointDigs)
- if (checkpointDigs == 0 and inTransition == false) then
- Return()
- Continue()
- -- print("restored: ", timesx, timesy)
- end
- local success, data = turtle.inspectDown()
- if data.name == "minecraft:wheat" then -- try to place crop
- turtle.digDown() -- till
- turtle.placeDown() -- place crop
- turtle.suckDown() -- suck it up
- elseif data.name == "minecraft:water" then -- when air just dig
- -- maybe print soemthing?
- else -- if just dirt or sth
- turtle.digDown() -- till
- turtle.placeDown() -- place crop
- end
- end
- -- do everything
- function Start()
- isDown = false
- if timesy == 0 then
- timesy = timesx -- make square
- end
- backupX = timesx
- backupY = timesy
- while true do
- Totaltimes = Totaltimes + 1
- timesx = backupX
- timesy = backupY
- turtle.down() -- try to move down initially
- turtle.up()
- turtle.forward()
- turtle.select(1) -- select crops
- timesxBackup = timesx -- save value for each row
- timesyBackup = timesy
- repeat -- until horizonal line complete
- repeat -- until straight line complete
- timesx = timesx -1
- turtle.forward()
- work()
- checkpointDigs = checkpointDigs -1 -- count sucks (can only suck 256 times then he might be full: 64x16=1024 / 4 = 256)
- until timesx == 0
- -- turn around <
- if (timesyBackup - timesy)%2 == 0 then -- if EVEN turn right
- turtle.turnRight()
- turtle.forward()
- work(true)
- turtle.turnRight()
- isDown = true
- else -- odd turn left
- turtle.turnLeft()
- turtle.forward()
- work(true)
- turtle.turnLeft()
- isDown = false
- end
- -- > turn around
- timesx = timesxBackup
- timesy = timesy -1
- until timesy == 0
- Return()
- print("Im done Master. Sleeping for 30 min. Please dont hurt me.")
- print("I already farmed so many times: ", Totaltimes)
- os.sleep(1800)
- end
- end
- print("Please place seeds in the first slot")
- print("How long (vertical)?")
- local input
- input = io.read()
- timesx = tonumber(input)
- print("How far to the right (horizontal)? 0 for square")
- input = io.read()
- timesy = tonumber(input)
- checkpointDigs = 200
- Start()
Add Comment
Please, Sign In to add comment