Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function turtle.forwards(numForw)
- for i = 1, numForw do
- turtle.forward()
- end
- end
- function turtle.upwards(numUpw)
- for i = 1, numUpw do
- turtle.up()
- end
- end
- function turtle.downwards(numDownw)
- for i = 1, numDownw do
- turtle.down()
- end
- end
- function turtle.turns180()
- for i = 1, 2 do
- turtle.turnRight()
- end
- end
- function inventoryCheck()
- for i = 1, 16 do
- if turtle.getItemCount(i) ~= 0 then
- return false
- end
- end
- return true
- end
- local startX, startY, startZ = 0, 0, 0
- local currX, currY, currZ = startX, startY, startZ
- local currDir = "north"
- function updatePosition(newX, newY, newZ)
- currX, currY, currZ = newX, newY, newZ
- end
- function updateDirection(newDir)
- currDir = newDir
- end
- function turnTo(dir)
- if dir == "north" then
- if currDir == "east" then
- turtle.turnLeft()
- elseif currDir == "south" then
- turtle.turn180()
- elseif currDir == "west" then
- turtle.turnRight()
- end
- elseif dir == "east" then
- if currDir == "north" then
- turtle.turnRight()
- elseif currDir == "south" then
- turtle.turnLeft()
- elseif currDir == "west" then
- turtle.turn180()
- end
- elseif dir == "south" then
- if currDir == "north" then
- turtle.turn180()
- elseif currDir == "east" then
- turtle.turnRight()
- elseif currDir == "west" then
- turtle.turnLeft()
- end
- elseif dir == "west" then
- if currDir == "north" then
- turtle.turnLeft()
- elseif currDir == "east" then
- turtle.turn180()
- elseif currDir == "south" then
- turtle.turnRight()
- end
- end
- updateDirection(dir)
- end
- function returnToStart()
- while currX ~= startX or currY ~= startY or currZ ~= startZ do
- if currY > startY then
- turtle.down()
- updatePosition(currX, currY - 1, currZ)
- elseif currY < startY then
- turtle.up()
- updatePosition(currX, currY + 1, currZ)
- elseif currZ > startZ then
- turnTo("north")
- turtle.forward()
- updatePosition(currX, currY, currZ - 1)
- elseif currZ < startZ then
- turnTo("south")
- turtle.forward()
- updatePosition(currX, currY, currZ + 1)
- elseif currX > startX then
- turnTo("west")
- turtle.forward()
- updatePosition(currX - 1, currY, currZ)
- elseif currX < startX then
- turnTo("east")
- turtle.forward()
- updatePosition(currX + 1, currY, currZ)
- end
- end
- end
- function inventoryTest()
- while true do
- if inventoryCheck() then
- returnToStart()
- turtle.turns180()
- for i = 1, 16 do
- turtle.select(i)
- if turtle.getItemCount() ~= 0 then
- turtle.drop()
- end
- end
- turtle.turns180()
- else
- sleep(0.1)
- end
- end
- end
- turtle.forwards(5)
- turtle.turnLeft()
- turtle.forwards(2)
- inventoryTest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement