Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --functions
- function initialise()
- currentX = 0
- currentY = 0
- currentZ = 0
- currentDir = 0
- fuelThreshold = 10
- fuelSlot = 1
- firstBlockSlot = 2
- canContinue = true
- end
- function checkFuel()
- if turtle.getFuelLevel() < fuelThreshold then
- turtle.select(fuelSlot)
- if turtle.refuel(1) == false then
- print ("Waiting for fuel...")
- end
- while turtle.refuel(1) == false do
- end
- else
- print ("No fuel necessary, foolish human")
- end
- print ("I have " .. turtle.getFuelLevel() .. " fuulez")
- end
- function getNextSlot()
- local i=turtle.getSelectedSlot()
- while turtle.getItemCount(i) == 0 do
- i = i + 1
- if i > 16 then
- i = firstBlockSlot
- end
- turtle.select(i)
- end
- end
- function moveNPlace()
- moveBackwardsXWait()
- turtle.place()
- end
- function turnCorner
- moveBackwardsYWait()
- turtle.place()
- function moveBackwardsXWait()
- while moveBackwardsX(1) ~= 1 do
- end
- end
- function moveBackwardsYWait()
- while moveBackwardsY(1) ~= 1 do
- end
- end
- function whereAmI()
- print ("I am at" .. " " .. currentX .. "X" .. "," .. currentY .. "Y" .. "," .. currentZ .. "Z," .. " Direction:" .. currentDir)
- end
- function moveUp(a)
- local i=1
- for i=1,a do
- if turtle.up() == true then
- currentZ = currentZ + 1
- end
- end
- whereAmI()
- end
- function moveDown(a)
- local i=1
- for i=1,a do
- if turtle.down() == true then
- currentZ = currentZ - 1
- end
- end
- whereAmI()
- end
- function moveZ(a)
- if a < 0 then
- moveDown(-a)
- elseif a > 0 then
- moveUp(a)
- else
- end
- end
- function turnRight(a)
- local i=1
- for i=1,a do
- turtle.turnRight()
- currentDir = currentDir + 1
- if currentDir == 4 then
- currentDir = 0
- end
- end
- whereAmI()
- end
- function turnLeft(a)
- local i=1
- for i=1,a do
- turtle.turnLeft()
- currentDir = currentDir - 1
- if currentDir == -1 then
- currentDir = 3
- end
- end
- whereAmI()
- end
- function setDirection(a)
- local diffTurn = a - currentDir
- if diffTurn < 0 then
- diffTurn = diffTurn + 4
- end
- if diffTurn ~= 0 then
- turnRight(diffTurn)
- end
- end
- function moveForwardX(a)
- local i=1
- if a > 0 then
- setDirection(0)
- for i=1,a do
- if turtle.forward() == true then
- currentX = currentX + 1
- end
- end
- elseif a < 0 then
- setDirection(2)
- for i=-1,a,-1 do
- if turtle.forward() == true then
- currentX = currentX - 1
- end
- end
- else
- end
- whereAmI()
- end
- function moveBackwardsX(a)
- local i=1
- local howfar=0
- if a > 0 then
- setDirection(0)
- for i=1,a do
- if turtle.back() == true then
- currentX = currentX - 1
- howfar = howfar + 1
- end
- end
- elseif a < 0 then
- setDirection(2)
- for i=-1,a,-1 do
- if turtle.back() == true then
- currentX = currentX + 1
- howfar = howfar + 1
- end
- end
- else
- end
- whereAmI()
- return howfar
- end
- function moveForwardY(a)
- local i=1
- if a > 0 then
- setDirection(1)
- for i=1,a do
- if turtle.forward() == true then
- currentY = currentY + 1
- end
- end
- elseif a < 0 then
- setDirection(3)
- for i=-1,a,-1 do
- if turtle.forward() == true then
- currentY = currentY - 1
- end
- end
- else
- end
- whereAmI()
- end
- function moveBackwardsY(a)
- local i=1
- local howfar = 0
- if a > 0 then
- setDirection(3)
- for i=1,a do
- if turtle.back() == true then
- currentY = currentY - 1
- howfar = howfar + 1
- end
- end
- elseif a < 0 then
- setDirection(1)
- for i=-1,a,-1 do
- if turtle.back() == true then
- currentY = currentY + 1
- howfar = howfar + 1
- end
- end
- else
- end
- whereAmI()
- return howfar
- end
- function goTo(x,y,z)
- local diffX = x - currentX
- local diffY = y - currentY
- local diffZ = z - currentZ
- moveForwardX(diffX)
- moveForwardY(diffY)
- moveZ(diffZ)
- end
- initialise()
- while true do
- moveBackwardsXWait()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement