Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Mik's Funct
- --Function to empty inventory into chest
- function emptyInventory()
- local returnX = turtleX
- local returnY = turtleY
- local returnZ = turtleZ
- local returnDirection = turtleDirection
- goHome()
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- checkCounter = 16
- turtleGoTo(returnX,returnY,returnZ,returnDirection)
- end
- --Function to send turtle to a specific location
- function turtleGoTo(intX, intY, intZ, intDirection)
- while intY > turtleY do
- goUp()
- end
- if turtleX ~= intX then
- while turtleDirection ~= 1 do
- rightFace()
- end
- while turtleX < intX do
- goForward()
- end
- end
- if turtleZ ~= intZ then
- while turtleDirection ~= 2 do
- rightFace()
- end
- while turtleZ < intZ do
- goForward()
- end
- end
- while turtleDirection ~= intDirection do
- rightFace()
- end
- end
- --Function to determine how many inventory slots are empty
- function emptySlots()
- empty = 0
- for i=1,16 do
- count = turtle.getItemCount(i)
- if count == 0 then
- empty = empty + 1
- end
- end
- return empty
- end
- --Turn turtle to the left and update turtle direction
- function leftFace()
- turtle.turnLeft()
- updateFacing( "left" )
- end
- --Turn turtle to the right and update turtle direction
- function rightFace()
- turtle.turnRight()
- updateFacing( "right" )
- end
- -- Ensure turtle goes up
- function goUp()
- while not turtle.up() do
- upDig()
- end
- turtleY = turtleY + 1
- end
- --Ensure turtle goes down
- function goDown()
- while not turtle.down() do
- downDig()
- end
- turtleY = turtleY - 1
- end
- -- Ensure turtle moves forward
- function goForward()
- while not turtle.forward() do
- forwardDig()
- end
- updatePos()
- end
- -- Dig forward
- function forwardDig()
- while turtle.detect() do
- turtle.dig()
- checkInventory()
- end
- end
- -- Dig up
- function upDig()
- while turtle.detectUp() do
- turtle.digUp()
- checkInventory()
- end
- end
- -- Dig Down
- function downDig()
- turtle.digDown()
- checkInventory()
- end
- -- Function to update turtle position relative to starting location
- function updatePos()
- if turtleDirection == 1 then
- turtleX = turtleX + 1
- elseif turtleDirection == 2 then
- turtleZ = turtleZ + 1
- elseif turtleDirection == 3 then
- turtleX = turtleX - 1
- elseif turtleDirection == 4 then
- turtleZ = turtleZ - 1
- end
- print( "UpdatePos: X = " .. turtleX .. " Y = " .. turtleY .. " Z = " .. turtleZ )
- end
- --Function to update turtle facing direction relative to starting facing direction
- function updateFacing(turnValue)
- if ( turnValue == "left" ) then
- turtleDirection = turtleDirection - 1
- elseif ( turnValue == "right" ) then
- turtleDirection = turtleDirection + 1
- else
- print( "Invalid input to updateFacing" .. turnValue )
- end
- if turtleDirection == 5 then
- turtleDirection = 1
- end
- if turtleDirection == 0 then
- turtleDirection = 4
- end
- print("UpdateFacing: " .. turtleDirection )
- end
- --Function to return turtle to starting area.
- function goHome()
- while turtleY > 2 do
- goDown()
- end
- while ( turtleDirection ~= 4 ) do
- rightFace()
- sleep(.1)
- print( turtleDirection )
- end
- while turtleZ > 1 do
- goForward()
- end
- leftFace()
- while turtleX > 1 do
- goForward()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement