Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Created by jakimfett
- --todo: multi level excavations
- --place torches under development
- --Please note that the slots for item tests (gravel, cobble, dirt) have shifted to allow torch placement
- os.setComputerLabel("yourusername")
- turtle.select(1)
- local direction = "forward"
- local targetFuelLevel = 10
- local digDelay = 1 --Wait time to allow gravel/sand to fall
- local fuelSlot = 16
- local chestSlot = 15
- local torchSlot = 14
- local cobbleSlot = 13
- local gravelSlot = 12
- local dirtSlot = 11
- local maxSlot = 10 --must be one less than the garbage slot
- local placeChests = 1
- local discardDirt = 1
- local discardCobble = 1
- local discardGravel = 1
- --Defining the size of hole to dig
- --Using the Cartesian coordinate system
- --The "Y" axis is up and down, multiplied by 3 (the turtle digs 3 high tunnels)
- --The "X" axis is left and right
- --The "Z" axis is forward and back
- local sizeY = 0
- local sizeX = 0
- local sizeZ = 0
- local sizeDirection = "left"
- local torchCountX = 1
- local torchCountZ = 1
- local placeTorchEvery = 6
- function verifyReady()
- if discardDirt == 1 then
- if turtle.getItemCount(dirtSlot) == 0 then
- print("Please put some dirt in slot:")
- print(dirtSlot)
- os.sleep(5)
- os.reboot()
- end
- end
- if discardCobble == 1 then
- if turtle.getItemCount(cobbleSlot) == 0 then
- print("Please put some cobble in slot:")
- print(cobbleSlot)
- os.sleep(5)
- os.reboot()
- end
- end
- if discardGravel == 1 then
- if turtle.getItemCount(gravelSlot) == 0 then
- print("Please put some gravel in slot:")
- print(gravelSlot)
- os.sleep(5)
- os.reboot()
- end
- end
- turtle.select(1)
- end
- function userInput()
- term.clear()
- term.setCursorPos(1, 1)
- print("Please input a length:")
- sizeZ = read()
- print("Please input a width:")
- sizeX = read()
- print("Direction to excavate (left/right):")
- sizeDirection = read()
- end
- function refuel()
- local currentFuelLevel = turtle.getFuelLevel()
- if currentFuelLevel <= targetFuelLevel then
- turtle.select(fuelSlot)
- turtle.refuel()
- end
- turtle.select(1)
- end
- function digForward(distance)
- local count = 0
- repeat
- local cleared = 0
- repeat --Loop dig and detect because of gravel and sand
- turtle.dig()
- os.sleep(digDelay)
- until turtle.detect() == false
- turtle.forward()
- turtle.digDown()
- turtle.digUp()
- if turtle.detectUp() then --If digging up released gravel or sand
- repeat
- turtle.digUp()
- os.sleep(digDelay)
- until turtle.detectUp() == false
- end
- if turtle.getItemCount(10) ~= 0 then
- garbageCollect()
- turtle.select(1)
- end
- count = count + 1
- torchCountZ = torchCountZ + 1
- if torchCountZ > placeTorchEvery then
- if torchCountX > placeTorchEvery then
- placeTorchHere()
- torchCountX = 1
- end
- torchCountZ = 1
- end
- until count == distance
- turtle.select(1)
- end
- function placeTorchHere()
- turtle.select(torchSlot)
- turtle.placeDown()
- turtle.select(1)
- end
- function turn(direction)
- if direction == "right" then
- turtle.turnRight()
- elseif direction == "left" then
- turtle.turnLeft()
- end
- end
- function chestDump()
- if placeChests == 1 then
- --garbageCollect()
- turtle.select(chestSlot)
- turtle.placeDown()
- local count = 1
- repeat
- turtle.select(count)
- turtle.dropDown()
- count = count + 1
- until count == maxSlot + 1
- turtle.select(1)
- end
- end
- function garbageCollect()
- if discardDirt == 1 then
- local dirtCount = 1
- repeat
- turtle.select(dirtCount)
- if turtle.compareTo(dirtSlot) then
- turtle.drop()
- end
- dirtCount = dirtCount + 1
- until dirtCount == maxSlot + 1
- end
- if discardCobble == 1 then
- local cobbleCount = 1
- repeat
- turtle.select(cobbleCount)
- if turtle.compareTo(cobbleSlot) then
- turtle.drop()
- end
- cobbleCount = cobbleCount + 1
- until cobbleCount == maxSlot + 1
- end
- if discardGravel == 1 then
- local gravelCount = 1
- repeat
- turtle.select(gravelCount)
- if turtle.compareTo(gravelSlot) then
- turtle.drop()
- end
- gravelCount = gravelCount + 1
- until gravelCount == maxSlot + 1
- end
- compactInventory()
- compactInventory()
- if turtle.getItemCount(maxSlot - 1) ~= 0 then
- chestDump()
- end
- turtle.select(1)
- end
- function compactInventory()
- local compaceCount = 1
- repeat
- local countMove = 2
- repeat
- turtle.select(countMove)
- turtle.transferTo(countMove - 1)
- countMove = countMove + 1
- until countMove == maxSlot + 1
- compaceCount = compaceCount + 1
- until compaceCount > 1
- end
- function excavateLevel()
- local nextTurn = sizeDirection
- local count = 1
- repeat
- refuel()
- sizeZ = sizeZ + 0
- digForward(sizeZ)
- turtle.select(1)
- turn(nextTurn)
- digForward(1)
- torchCountX = torchCountX + 1
- turn(nextTurn)
- if nextTurn == "left" then
- nextTurn = "right"
- elseif nextTurn == "right" then
- nextTurn = "left"
- end
- count = count + 1
- until count >= sizeX + 0 --sizeX + 0 ensures that sizeX evaluated as number
- end
- verifyReady()
- userInput()
- excavateLevel()
Advertisement
Add Comment
Please, Sign In to add comment