Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Sap farming turtle.
- local rows = 1
- local compass = 0
- local x = 0
- local y = 0
- local z = 0
- function spin()
- print "spinning"
- turtle.turnRight()
- turtle.turnRight()
- compass = (compass + 2) % 4
- end
- function forward()
- print "going forward"
- if turtle.detect() then
- return false
- end
- while not turtle.forward() do:
- sleep(1)
- end
- if compass == 0 then
- x = x + 1
- elseif compass == 1 then
- y = y + 1
- elseif compass == 2 then
- x = x - 1
- elseif compass == 3 then
- y = y - 1
- else
- print "what are you doing!?! Not a valid compass value."
- end
- return true
- end
- function up()
- --print "going up"
- if turtle.up() then
- z = z + 1
- return true
- else
- return false
- end
- end
- function down()
- --print "going down"
- if turtle.down() then
- z = z - 1
- return true
- else
- return false
- end
- end
- function turnRight()
- --print "turning right"
- if turtle.turnRight() then
- compass = (compass + 1) % 4
- return true
- else
- return false
- end
- end
- function turnLeft()
- --print "turning left"
- if turtle.turnLeft() then
- compass = math.abs((compass - 1) % 4)
- return true
- else
- return false
- end
- end
- function emptyInv() -- may as well empty our inventory while we're here.
- end
- function recharge() --Find and use turtle recharging station.
- end
- function returnToBase()
- --This code will go up to a respectable Z, then go to 0 x and 0 y, then drop down to 0 z. This is the starting point, and should be where we keep the recharging station and ender chest.
- for i = 0, 20 do
- up()
- end
- print (x, "x")
- print (y, "y")
- print (z, "z")
- repeat
- turnRight()
- until compass == 2
- while x ~= 0 do
- forward()
- end
- turnRight()
- while y ~= 0 do
- forward()
- end
- turnRight()
- while z ~= 0 do
- down()
- end
- emptyInv()
- recharge()
- end
- function rotateCounterClockwise()
- --print "rotating counter clockwise"
- turnRight()
- forward()
- turnLeft()
- forward()
- turnLeft()
- end
- function rotateClockwise()
- --print "rotating clockwise"
- turnLeft()
- forward()
- turnRight()
- forward()
- turnRight()
- end
- function harvestFrontBack()
- repeat
- turtle.dig()
- if not up() then
- turtle.digUp()
- up()
- end
- until not turtle.detect()
- forward()
- forward()
- spin()
- while z > 0 do
- if not down() then
- print "breaking to go down"
- turtle.digDown()
- down()
- end
- turtle.dig()
- end
- end
- function harvestTree() --Starting with turtle facinga a tree, it gets all the resin from each side of the tree and returns to its start position.
- print "Starting"
- harvestFrontBack()
- rotateCounterClockwise()
- harvestFrontBack()
- rotateClockwise()
- end
- function turn(var)
- print ("var",var)
- if var % 2 == 1 then
- turnLeft()
- elseif var % 2 == 0 then
- turnRight()
- end
- end
- function nextRow()
- local dir = 3
- print ("dir ",dir)
- if rows % 2 == 0 then
- dir = 2
- turn(dir)
- else
- dir = 3
- turn(dir)
- end
- print ("dir ",dir)
- forward()
- forward()
- local rowFound = false
- print ("dir ",dir)
- while not rowFound do
- print ("dir ",dir)
- if not turtle.forward() then
- returnToBase()
- sleep(3600)
- end
- print ("dir",dir)
- turn(dir)
- if turtle.detect() then
- break
- end
- turn(dir - 1)
- end
- rows = rows + 1
- rotateCounterClockwise()
- end
- function nextTree()
- local detectTree = false
- repeat
- turtle.turnRight()
- if not turtle.forward() then
- nextRow()
- break
- end
- turnLeft()
- until turtle.detect()
- end
- function main()
- while true do
- harvestTree()
- nextTree()
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement