Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --=======================================Standard Lbrary=====================================--
- function smartFuel()
- if turtle.getFuelLevel() <= 0 then
- onSlot = turtle.getSelectedSlot()
- while not turtle.refuel(1) do
- onSlot = onSlot + 1
- if onSlot == 17 then
- onSlot = 1
- end
- turtle.select(onSlot)
- end
- end
- end
- function smartFor()
- while not turtle.forward() do
- turtle.attack()
- turtle.dig()
- smartFuel()
- end
- end
- function smartUp()
- while not turtle.up() do
- turtle.attackUp()
- turtle.digUp()
- smartFuel()
- end
- end
- function smartDown()
- while not turtle.down() do
- turtle.attackDown()
- turtle.digDown()
- smartFuel()
- end
- end
- function smartMove(dir)
- if dir == -1 then
- turtle.turnLeft()
- smartFor()
- elseif dir == 1 then
- turtle.turnRight()
- smartFor()
- elseif dir == 2 then
- smartFor()
- elseif dir == -2 then
- turtle.turnRight()
- turtle.turnRight()
- smartFor()
- elseif dir == 3 then
- smartUp()
- elseif dir == -3 then
- smartDown()
- end
- end
- --=======================================CoodLibrary==========================-
- --start with "initCoords
- --====initCoords=====--
- function initCoords()
- x = 0
- y = 0
- z = 0
- --0 is forwards, 1 is left, goes clockwise to 3
- facing = 0
- --used to remember location before returning to origin
- tempX = 0
- tempY = 0
- tempZ = 0
- tempFacing = 0
- end
- function trackedFor()
- smartFor()
- if facing == 0 then
- y = y+1
- elseif facing == 1 then
- x = x+1
- elseif facing == 2 then
- y = y-1
- elseif facing == 3 then
- x = x-1
- end
- end
- function trackedUp()
- smartUp()
- z = z+1
- end
- function trackedDown()
- smartDown()
- z = z-1
- end
- function trackedRight()
- changeFacing(1)
- turtle.turnRight()
- end
- function trackedLeft()
- changeFacing(-1)
- turtle.turnLeft()
- end
- function trackedMove(dir)
- if dir == -1 then
- trackedLeft()
- trackedFor()
- elseif dir == 1 then
- trackedRight()
- trackedFor()
- elseif dir == 2 then
- trackedFor()
- elseif dir == -2 then
- trackedRight()
- trackedRight()
- trackedFor()
- elseif dir == 3 then
- trackedUp()
- elseif dir == -3 then
- trackedDown()
- end
- end
- function changeFacing(change)
- facing = facing + change
- facing = facing % 4
- end
- function face(targetFacing)
- while facing ~= targetFacing do
- turtle.turnRight()
- changeFacing(1)
- end
- end
- function toCoords(tarX,tarY,tarZ,tarFace)
- if z > tarZ then
- for i=tarZ+1,z do
- trackedMove(-3)
- end
- elseif z < tarZ then
- for i=z,tarZ-1 do
- trackedMove(3)
- end
- end
- if y > tarY then
- face(2)
- for i=tarY+1,y do
- trackedMove(2)
- end
- elseif y < tarY then
- face(0)
- for i=y,tarY-1 do
- trackedMove(2)
- end
- end
- if x > tarX then
- face(3)
- for i=tarX+1,x do
- trackedMove(2)
- end
- elseif x < tarX then
- face(1)
- for i=x,tarX-1 do
- trackedMove(2)
- end
- end
- face(tarFace)
- end
- function saveCoords()
- tempX = x
- tempY = y
- tempZ = z
- tempFacing = facing
- end
- function toSavedCoords()
- toCoords(tempX,tempY,tempZ,tempFacing)
- end
- --============================Function Start=============================--
- initCoords()
- toCoords(2,2,2,0)
- saveCoords()
- toCoords(0,0,0,0)
- toSavedCoords()
- print(x .. " " .. y .. " " .. z .. " " ..facing)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement