Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local actx = 0
- local acty = 0
- local actz = 0
- local actyaw = 0
- local lastx = 0
- local lasty = 0
- local lastz = 0
- local lastyaw = 0
- local anwser = false
- forwardcounter = 0
- function items()
- for i = 1, 16 do
- actitem = turtle.getItemCount(i)
- allitems = allitems + actitem
- end
- return allitems
- end
- function createterm()
- term.setCursorPos(1,6)
- term.clearLine()
- print("------X Blocks left until end------")
- print("------X Fuellevel------")
- end
- function writeterm(msg,cursorlevel)
- cursorlevel = 6 + cursorlevel
- term.setCursorPos(1,cursorlevel)
- term.clearLine()
- print("------"..msg.."------")
- end
- function clearInv()
- for i = 1,16 do
- turtle.select(i)
- turtle.drop(turtle.getItemCount(i))
- end
- turtle.select(1)
- end
- function clearterm()
- term.clear()
- term.setCursorPos(1,1)
- end
- function usefuel(slotnum)
- turtle.select(slotnum)
- turtle.refuel(1)
- end
- function setPositionVars()
- lastx = actx
- lasty = acty
- lastz = actz
- lastyaw = actyaw
- end
- function turtledig()
- forwardcounter = forwardcounter + 1
- writeterm(turtle.getFuelLevel().." Fuellevel", 1)
- blocksleft = 0
- turtle.dig()
- if turtle.getItemCount(16) > 0 then
- setPositionVars()
- findBack(0,0,0,0,true)
- end
- end
- function turtledigup()
- forwardcounter = forwardcounter + 1
- writeterm(turtle.getFuelLevel().." Fuellevel", 1)
- blocksleft = 0
- turtle.digUp()
- end
- function turtledigdown()
- forwardcounter = forwardcounter + 1
- writeterm(turtle.getFuelLevel().." Fuellevel", 1)
- blocksleft = 0
- turtle.digDown()
- if turtle.getItemCount(16) > 0 then
- setPositionVars()
- findBack(0,0,0,0,true)
- end
- end
- function turtleup()
- if turtle.up() == false then
- while turtle.up() == false do
- turtledigup()
- end
- end
- acty = acty + 1
- writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
- end
- function turtledown()
- if turtle.down() == false then
- while turtle.down() == false do
- turtledigdown()
- end
- end
- acty = acty - 1
- end
- function goforward()
- if turtle.forward() == false then
- while turtle.forward() == false do
- turtledig()
- end
- end
- if actyaw == 0 then
- actx = actx + 1
- elseif actyaw == 1 then
- actz = actz - 1
- elseif actyaw == 2 then
- actx = actx - 1
- elseif actyaw == 3 then
- actz = actz + 1
- end
- writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
- end
- function findBack(x, y, z, yaw, anwser)
- if anwser ~= true then
- anwser = false
- end
- if x < actx then
- while actyaw ~= 2 do
- turtleleft()
- end
- elseif x > actx then
- while actyaw ~= 0 do
- turtleleft()
- end
- end
- while actx ~= x do
- goforward()
- end
- if z > actz then
- while actyaw ~= 3 do
- turtleleft()
- end
- elseif z < actz then
- while actyaw ~= 1 do
- turtleleft()
- end
- end
- while actz ~= z do
- goforward()
- end
- if y < acty then
- while acty ~= y do
- turtledown()
- end
- elseif y > acty then
- while acty ~= y do
- turtleup()
- end
- end
- while actyaw ~= yaw do
- turtleleft()
- end
- if anwser == true then
- turtleleft()
- turtleleft()
- clearInv()
- turtleleft()
- turtleleft()
- findBack(lastx, lasty, lastz, lastyaw, false)
- end
- end
- function turtleright()
- turtle.turnRight()
- actyaw = actyaw + 1
- if actyaw > 3 then
- actyaw = 0
- end
- writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
- end
- function turtleleft()
- turtle.turnLeft()
- actyaw = actyaw - 1
- if actyaw < 0 then
- actyaw = 3
- end
- writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
- end
- findBack(2,0,0,0,false)
- findBack(2,5,0,0,false)
- findBack(0,0,0,0,false)
- turtle.select(1)
- termclear()
Advertisement
Add Comment
Please, Sign In to add comment