Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - --Created by makeo. All rights reserved.
 - --DO NOT EDIT
 - local ENDER_CHEST_SLOT = 1
 - local DIG_SLOT = 2
 - --save movements
 - function move(move, detect, dig, attack)
 - if needsPitstop() then
 - doPitstop()
 - end
 - local first = true
 - while not move() do
 - if detect() then
 - turtle.select(DIG_SLOT)
 - dig()
 - else
 - attack()
 - end
 - if not first then
 - sleep(0.5)
 - end
 - first = false
 - end
 - end
 - function moveForward()
 - move(turtle.forward, turtle.detect, turtle.dig, turtle.attack)
 - end
 - function moveBack()
 - if not turtle.back() then
 - turn180()
 - moveForward()
 - turn180()
 - end
 - end
 - function moveUp()
 - move(turtle.up, turtle.detectUp, turtle.digUp, turtle.attackUp)
 - end
 - function moveDown()
 - move(turtle.down, turtle.detectDown, turtle.digDown, turtle.attackDown)
 - end
 - function turn180()
 - turtle.turnLeft()
 - turtle.turnLeft()
 - end
 - --pitstop
 - function doPitstop()
 - if turtle.getItemDetail(ENDER_CHEST_SLOT) == nil then
 - if peripheral.getType("bottom") ~= "ender_chest" then
 - error("No ender chest found.")
 - end
 - else
 - if turtle.detectDown() then
 - turtle.select(DIG_SLOT)
 - turtle.digDown()
 - end
 - turtle.select(ENDER_CHEST_SLOT)
 - turtle.placeDown()
 - sleep(0.5)
 - end
 - local enderChest = peripheral.wrap("bottom")
 - if enderChest == nil then
 - error("Failed to wrap ender chest.")
 - end
 - if (not hasSpace()) or getMovingHome() then
 - for i = 3, 16, 1 do
 - while turtle.getItemCount(i) > 0 do
 - local moved = false
 - for j = 2, enderChest.getInventorySize(), 1 do
 - if enderChest.pullItem("up", i, 64, j) ~= 0 then
 - moved = true
 - end
 - end
 - sleep(0.5)
 - if not moved then
 - sleep(2)
 - end
 - end
 - end
 - end
 - turtle.select(ENDER_CHEST_SLOT)
 - turtle.digDown()
 - end
 - function needsPitstop()
 - return (not hasSpace())
 - end
 - function hasSpace()
 - local count = 0
 - for i = 3, 16, 1 do
 - if turtle.getItemCount(i) == 0 then
 - count = count + 1
 - end
 - end
 - return count > 1
 - end
 - function readNumber(minVal)
 - local num = -1
 - repeat
 - if num ~= -1 then
 - print("Text is not a number.")
 - end
 - num = tonumber(read())
 - if num ~= nil and num < minVal then
 - print("Number is out of bound.")
 - num = nil
 - end
 - until num ~= nil
 - return num
 - end
 - --ore stuff
 - function isOre()
 - local success, data = turtle.inspect()
 - return checkOre(success, data)
 - end
 - function isOreUp()
 - local success, data = turtle.inspectUp()
 - return checkOre(success, data)
 - end
 - function isOreDown()
 - local success, data = turtle.inspectDown()
 - return checkOre(success, data)
 - end
 - function checkOre(success, data)
 - if success then
 - local name = data["name"]
 - if name ~= nil then
 - --Alternative name bypass
 - if name == "Forestry:resources" or name == "TConstruct:SearedBrick"
 - or name == "denseores:block0" or name == "rftools:dimensionalShardBlock"
 - or name == "harvestcraft:salt" then
 - return true
 - end
 - local index = string.find(name, ":")
 - if index ~= nil then
 - local part = string.lower(string.sub(name, index))
 - local isOre = string.find(part, "ore")
 - return isOre ~= nil
 - end
 - end
 - end
 - return false
 - end
 - --vein stuff
 - function mineVein()
 - while true do
 - if isOre() then
 - veinMoveForward()
 - elseif isOreUp() then
 - veinMoveUp()
 - elseif isOreDown() then
 - veinMoveDown()
 - else
 - local success = false
 - for i = 1, 3, 1 do
 - veinMoveLeft()
 - if isOre() then
 - veinMoveForward()
 - success = true
 - break
 - end
 - end
 - if not success then
 - if not popVeinMovment() then
 - return
 - end
 - end
 - end
 - sleep(0.5)
 - end
 - end
 - function veinMoveForward()
 - moveForward()
 - pushToVeinStack(1)
 - end
 - function veinMoveUp()
 - moveUp()
 - pushToVeinStack(2)
 - end
 - function veinMoveDown()
 - moveDown()
 - pushToVeinStack(3)
 - end
 - function veinMoveLeft()
 - turtle.turnLeft()
 - pushToVeinStack(4)
 - end
 - function veinMoveRight()
 - turtle.turnRight()
 - pushToVeinStack(5)
 - end
 - function veinMoveBack()
 - moveBack()
 - pushToVeinStack(6)
 - end
 - function popVeinMovment()
 - local direction = getFromVeinStack()
 - if direction == nil then
 - return false
 - end
 - if direction == 1 then
 - moveBack()
 - elseif direction == 2 then
 - moveDown()
 - elseif direction == 3 then
 - moveUp()
 - elseif direction == 4 then
 - turtle.turnRight()
 - removeLastVeinStack()
 - return popVeinMovment()
 - elseif direction == 5 then
 - turtle.turnLeft()
 - removeLastVeinStack()
 - return popVeinMovment()
 - elseif direction == 6 then
 - moveForward()
 - end
 - removeLastVeinStack()
 - return true;
 - end
 - function pushToVeinStack(direction)
 - local stack = getVeinStack()
 - if stack == nil then
 - stack = {}
 - end
 - stack[#stack + 1] = direction
 - stack = optimizeVeinStack(stack)
 - saveVeinStack(stack, #stack)
 - end
 - function getFromVeinStack()
 - local data = getVeinStack()
 - if data ~= nil then
 - return data[#data]
 - end
 - return nil
 - end
 - function optimizeVeinStack(data)
 - local lastAction = 0
 - local actionCount = 0
 - local i = 1
 - while i <= #data do
 - --turn right and then left is somewhat useless
 - if (data[i] == 4 and lastAction == 5) or
 - (data[i] == 5 and lastAction == 4) then
 - data = moveArrayContent(data, i + 1, 2)
 - if #data < 1 then
 - break
 - end
 - i = 1
 - lastAction = 0
 - actionCount = 0
 - end
 - if data[i] ~= lastAction then
 - lastAction = 0
 - actionCount = 0
 - end
 - if data[i] == 4 then
 - lastAction = 4
 - actionCount = actionCount + 1
 - elseif data[i] == 5 then
 - lastAction = 5
 - actionCount = actionCount + 1
 - end
 - if actionCount == 3 then
 - local newAction = 4
 - if lastAction == 4 then
 - newAction = 5
 - end
 - data = moveArrayContent(data, i + 1, 2)
 - data[i - 2] = newAction
 - i = 0
 - lastAction = 0
 - actionCount = 0
 - end
 - i = i + 1
 - end
 - return data
 - end
 - function moveArrayContent(array, startIndex, amount)
 - local size = #array
 - for i = startIndex, size + amount, 1 do
 - array[i - amount] = array[i]
 - array[i] = nil
 - end
 - return array
 - end
 - function removeLastVeinStack()
 - local data = getVeinStack()
 - saveVeinStack(data, #data - 1)
 - end
 - function saveVeinStack(data, length)
 - if data ~= nil then
 - local dataLeng = #data
 - for i = length + 1, dataLeng, 1 do
 - data[i] = nil
 - end
 - end
 - if #data < 1 then
 - data = nil
 - end
 - setVeinStack(data)
 - end
 - function getVeinStack()
 - return getVariable("veinStack")
 - end
 - function setVeinStack(value)
 - setVariable("veinStack", value)
 - end
 - function getVariable(name)
 - local vars = getVariables()
 - if vars ~= nil then
 - return vars[name]
 - end
 - return nil
 - end
 - function setVariable(name, value)
 - local vars = getVariables()
 - if vars == nil then
 - vars = {}
 - end
 - vars[name] = value
 - local handle = fs.open("Vars.dat", "w")
 - handle.writeLine(textutils.serialize(vars))
 - handle.close()
 - end
 - function getVariables()
 - local handle = fs.open("Vars.dat", "r")
 - if handle ~= nil then
 - local raw = handle.readAll()
 - handle.close()
 - if raw ~= nil then
 - return textutils.unserialize(raw)
 - end
 - end
 - return nil
 - end
 - function getStripOnGround()
 - return getVariable("stripGround")
 - end
 - function setStripOnGround(value)
 - return setVariable("stripGround", value)
 - end
 - function getStripHasDug()
 - return getVariable("stripHasDug")
 - end
 - function setStripHasDug(value)
 - return setVariable("stripHasDug", value)
 - end
 - function digStrip(gotoStart)
 - if true then
 - while not getStripHasDug() do
 - mineVein()
 - if getStripHasDug() then
 - moveForward()
 - setStripHasDug(false)
 - else
 - if getStripOnGround() then
 - moveUp()
 - setStripOnGround(false)
 - else
 - moveDown()
 - setStripOnGround(true)
 - end
 - setStripHasDug(true)
 - end
 - end
 - end
 - mineVein()
 - if not getStripOnGround() then
 - moveDown()
 - setStripOnGround(true)
 - mineVein()
 - end
 - end
 - while true do
 - digStrip(true)
 - end
 
                    Add Comment                
                
                        Please, Sign In to add comment