Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --todo list
- --make the turtle return to it's origin when done. Possibly start planting again
- --let it refill saplings and maybe coal from chests
- --let it drop it's load of wood off into the water when full
- --maybe make it burn logs when out of fuel
- --asign each turtle their own row or something like that for speed.
- --at least more than one turtle at a time
- --maybe make it cook the coal. Could be done easier with pipes. hmm
- function restack()
- if turtle.getItemCount(2) > 1 then
- turtle.select(2)
- turtle.transferTo(1, (turtle.getItemCount(2) - 1))
- end
- if turtle.getItemCount(2) <= 1 then
- turtle.select(3)
- turtle.transferTo(2, (turtle.getItemCount(3) - 1))
- end
- turtle.select(1)
- end
- --moves the turtle forward, digging through blocks if necessary.
- --if it fails for some reason it keeps trying until it gets through
- --also keeps count of the amount it's moved for location purposes
- function digforward(n)
- if turtle.getItemCount(1) <= 1 then restack() end
- if turtle.getItemCount(1) > 1 then turtle.placeDown() end
- for i = 1, n do
- repeat
- if turtle.detect() then turtle.dig() end
- until turtle.forward()
- movedcount = movedcount + 1
- end
- end
- --turn right
- --move forward
- --for slots 4, 16 drop everything
- --turn left twice
- --go forward
- --turn right
- --select the first slot again
- function dumpinventory()
- print("Dumping inventory.")
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.dig()
- for i = 4, 16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- end
- --start count at 0
- --if there is no block above, exit loop and decend back down
- --break block above, move up until sucessful, add 1 to height
- --DECENDING BACK DOWN
- --if height =< 0 exit loop
- --break block below, move down until sucessful, subtract 1 from height
- function treeharvest()
- height = 0
- turtle.digDown()
- while true do
- if not turtle.detectUp() then break end
- repeat
- if turtle.detectUp() then turtle.digUp() end
- until turtle.up()
- height = height + 1
- end
- while true do
- if height <= 0 then break end
- repeat
- if turtle.detectDown() then turtle.digDown() end
- until turtle.down()
- height = height - 1
- end
- if turtle.getItemCount(16) >= 32 then dumpinventory() end
- if turtle.getFuelLevel() < 300 then refuel() end
- end
- --turn the turtle right
- --add 1 to the direction (cyclying back to 1 if greater than 4
- function turnright()
- turtle.turnRight()
- direction = direction + 1
- if direction > 4 then direction = 0 end
- end
- function turnleft()
- turtle.turnLeft()
- direction = direction - 1
- if direction < 1 then direction = 4 end
- end
- --if facing north or east, turn right
- --else turn left
- function turn()
- print(rotation)
- if rotation < 2 then turtle.turnRight() end
- if rotation >= 2 then turtle.turnLeft() end
- rotation = rotation + 1
- if rotation >= 4 then rotation = 0 end
- end
- --refuels the turtle with anything consumable in it's inventory
- --goes back to selecting slot 1
- function refuel()
- print("Refueling turtle.")
- for i = 4, 16 do
- turtle.select(i)
- turtle.refuel()
- end
- turtle.select(1)
- print("Turtle has " .. turtle.getFuelLevel() .. " fuel left.")
- end
- function iseven(n)
- if math.modf(n, 2) == 0 then return true
- else return false end
- end
- --GoHome(numberofrows)
- --Go to the origin
- --turn right
- --calculate the number of spaces to go forward
- -- the number of rows plus ((the number of rows - 1) * 4)
- --go that many spaces forward minus one (you are on that row)
- --turn right
- function GoHome(numberofrows)
- print("Returning to origin.")
- if iseven(numberofrows) then turtle.turnRight()
- else turtle.turnLeft() end
- spacestohome = numberofrows + ((numberofrows - 1) * 4)
- digforward(spacestohome - 1)
- turtle.turnRight()
- end
- --rows = 0, travelled = 0
- --dig forward
- --if spot with a block above, perform treeharvest()
- --add one to count of distance travelled.
- --if distance travelled is equal to or greater than distance, exit loop
- --goto 3
- --add 1 to the number of rows done
- --if rowsdone is equal to or greater than rows, return(), end program
- --turn()
- --digforward(5)
- --turn()
- -- travelled = 0
- --goto line 3
- function harvest(distance, rows)
- rowsdone, travelled, rotation = 0, 1, 0
- while true do
- while true do
- if turtle.detectUp() then treeharvest() end
- digforward(1)
- travelled = travelled + 1
- if travelled >= distance then break end
- end
- if turtle.detectUp() then treeharvest() end
- rowsdone = rowsdone + 1
- if rowsdone >= rows then break end
- turn()
- digforward(5)
- turn()
- travelled = 1
- end
- GoHome(rows)
- end
- print("Number of rows? ")
- rowstodo = tonumber(io.read())
- print("Number of times? ")
- loops = tonumber(io.read())
- direction = 1
- rotation = 0
- movedcount = 0
- refuel()
- print("Beginning harvest.")
- for z = 1, loops do
- harvest(30, rowstodo)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement