Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function digToNextFloor()
- turtle.down()
- turtle.digDown()
- turtle.down()
- turtle.digDown()
- turtle.down()
- turtle.digDown()
- end
- local function moveUp3()
- turtle.up()
- turtle.up()
- turtle.up()
- end
- local function moveDown3()
- turtle.down()
- turtle.down()
- turtle.down()
- end
- local function turnBack()
- turtle.turnRight()
- turtle.turnRight()
- end
- local function digForward()
- if turtle.detect() then
- turtle.dig()
- end
- end
- local function digUpAndDown()
- if turtle.detectUp() then
- turtle.digUp()
- end
- if turtle.detectDown() then
- turtle.digDown()
- end
- end
- local function moveForward()
- while turtle.detect() do
- turtle.dig()
- sleep(0.3)
- end
- if turtle.detect() == false then
- turtle.forward()
- end
- end
- local function startNextTunnel()
- if direction == "FORWARD" then
- turtle.turnRight()
- moveForward()
- digUpAndDown()
- turtle.turnRight()
- direction = "BACKWARD"
- else
- turtle.turnLeft()
- moveForward()
- digUpAndDown()
- turtle.turnLeft()
- direction = "FORWARD"
- end
- end
- local function inventoryFull()
- for i = 1,16 do
- if turtle.getItemCount(i) == 0 then
- return false
- end
- end
- return true
- end
- local function moveUp()
- print("Moving up " .. heightFromStart * 3 .. " blocks")
- input = io.read()
- if heightFromStart > 0 then
- for i = 1, heightFromStart do
- moveUp3()
- end
- end
- end
- local function moveBackToPosition()
- print("Moving back to position " .. lengthFromStart .. " length")
- input = io.read()
- for i = 1, lengthFromStart do
- moveForward()
- end
- turtle.turnRight()
- print("Moving back to position " .. widthFromStart .. " width")
- input = io.read()
- for i = 1,widthFromStart do
- moveForward()
- end
- print("Moving back to position " .. heightFromStart .. " height")
- input = io.read()
- for i = 1, heightFromStart do
- moveDown3()
- end
- if direction == "FORWARD" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- print("Position done")
- input = io.read()
- end
- local function goToSliceStartPostion()
- print("Moving to start position")
- input = io.read()
- if widthFromStart > 0 then
- if direction == "FORWARD" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- print("Moving for " .. widthFromStart.. " blocks (width)")
- input = io.read()
- for i = 1, widthFromStart do
- moveForward()
- end
- else
- turtle.turnLeft()
- end
- turtle.turnLeft()
- print("Moving for " .. lengthFromStart .. " blocks (length)")
- input = io.read()
- for i = 1, lengthFromStart do
- moveForward()
- end
- turnBack()
- print("Done")
- input = io.read()
- end
- local function moveAboveChest()
- turtle.back()
- print("Moved above chest")
- input = io.read()
- end
- local function moveFromChest()
- moveForward()
- end
- local function dumpInventory()
- local firstItem,lastItem = 1,16
- for i=firstItem,lastItem do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- local function refuel()
- --check current fuel level, find coal in inventory add to fuel level
- while turtle.getFuelLevel() < (length * 2) + 10 do
- for i = 1, 16 do -- loop through the slots
- turtle.select(i) -- change to the slot
- if turtle.refuel(0) then -- if it's valid fuel
- local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot
- turtle.refuel(halfStack) -- consume half the stack as fuel
- break
- end
- end
- end
- end
- local function digSlice()
- while widthLeft > 0 do
- digForward()
- moveForward()
- digUpAndDown()
- lengthLeft = lengthLeft - 1
- if direction == "FORWARD" then
- lengthFromStart = lengthFromStart + 1
- else
- lengthFromStart = lengthFromStart - 1
- end
- refuel()
- if inventoryFull() then
- goToSliceStartPostion()
- moveUp()
- moveAboveChest()
- dumpInventory()
- moveFromChest()
- moveBackToPosition()
- end
- if lengthLeft == 0 then
- lengthLeft = length - 1
- if widthLeft > 1 then
- startNextTunnel()
- widthFromStart = widthFromStart + 1
- end
- widthLeft = widthLeft - 1
- end
- end
- end
- local function digTunnels()
- digForward()
- moveForward()
- digUpAndDown()
- for level = 1, height do
- widthFromStart = 0
- lengthFromStart = 0
- lengthLeft = lengthLeft - 1
- digSlice()
- goToSliceStartPostion()
- heightLeft = heightLeft - 1
- widthLeft = width
- lengthLeft = length
- digToNextFloor()
- heightFromStart = heightFromStart + 1
- direction = "FORWARD"
- end
- end
- --START--
- print("Mining program")
- print("Length of tunnel: ")
- input = io.read()
- length = tonumber(input)
- lengthLeft = length
- lengthFromStart = 0
- print("Width of tunnel: ")
- input = io.read()
- width = tonumber(input)
- widthLeft = width
- widthFromStart = 0
- print("Height of tunnel: ")
- input = io.read()
- height = tonumber(input)
- heightLeft = height
- heightFromStart = 0
- direction = "FORWARD"
- refuel()
- digTunnels()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement