Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local curr_depth = 0
- local radius = 0
- local ORE = {
- ["minecraft:cobblestone"] = true
- }
- local DIRECTION = {
- Front = 0,
- Right = 1,
- Back = 2,
- Left = 3,
- Up = 4,
- Down = 5
- }
- function markVec(mineDepth, direction)
- return {mineDepth=mineDepth, direction=direction}
- end
- function isOre(direction)
- local hasBlock, blockInfo
- if (direction == DIRECTION.Up) then
- hasBlock, blockInfo = turtle.inspectUp()
- elseif (direction == DIRECTION.Down) then
- hasBlock, blockInfo = turtle.inspectDown()
- else
- hasBlock, blockInfo = turtle.inspect()
- end
- return hasBlock and ORE[blockInfo.name]
- end
- function reverseTurns(mineDepth, turnList)
- while (#turnList > 0 and turnList[#turnList].mineDepth == mineDepth) do
- local vec = table.remove(turnList)
- if (vec.direction == DIRECTION.Right) then
- turtle.turnLeft()
- elseif (vec.direction == DIRECTION.Left) then
- turtle.turnRight()
- end
- end
- end
- function correctTurn(direction, mineDepth, turnList)
- if (direction == DIRECTION.Left) then
- turtle.turnLeft()
- table.insert(turnList, markVec(mineDepth, DIRECTION.Left))
- elseif (direction == DIRECTION.Right) then
- turtle.turnRight()
- table.insert(turnList, markVec(mineDepth, DIRECTION.Right))
- elseif (direction == DIRECTION.Back) then
- turtle.turnRight()
- turtle.turnRight()
- table.insert(turnList, markVec(mineDepth, DIRECTION.Right))
- table.insert(turnList, markVec(mineDepth, DIRECTION.Right))
- end
- end
- function reverseMoves(mineDepth, origin, moveList, turnList)
- while (mineDepth ~= origin) do
- while (#moveList > 0 and moveList[#moveList].mineDepth == mineDepth - 1) do
- local vec = table.remove(moveList)
- if (vec.direction == DIRECTION.Front) then
- turtle.back()
- elseif (vec.direction == DIRECTION.Up) then
- turtle.down()
- elseif (vec.direction == DIRECTION.Down) then
- turtle.up()
- end
- end
- mineDepth = mineDepth - 1
- reverseTurns(mineDepth, turnList)
- end
- end
- function mine(direction, mineDepth, moveList)
- if (direction == DIRECTION.Up) then
- while (turtle.digUp()) do end
- turtle.up()
- table.insert(moveList, markVec(mineDepth, DIRECTION.Up))
- elseif (direction == DIRECTION.Down) then
- while (turtle.digDown()) do end
- turtle.down()
- table.insert(moveList, markVec(mineDepth, DIRECTION.Down))
- else
- while (turtle.dig()) do end
- turtle.forward()
- table.insert(moveList, markVec(mineDepth, DIRECTION.Front))
- end
- end
- function veinMine(direction)
- local mineList = {} --Stores list of ores
- local moveList = {} --Keeps track of movement
- local turnList = {} --Keeps track of turns
- local mineDepth = 0 --Keep track of # of mines in a vein
- --Adds current position into list for mining
- table.insert(mineList, markVec(mineDepth, direction))
- while (#mineList > 0) do
- local vec = table.remove(mineList)
- reverseMoves(mineDepth, vec.mineDepth, moveList, turnList)
- mineDepth = vec.mineDepth
- correctTurn(vec.direction, mineDepth, turnList)
- if (isOre(vec.direction)) then
- mine(vec.direction, mineDepth, moveList)
- mineDepth = mineDepth + 1
- if (isOre(DIRECTION.Front)) then
- table.insert(mineList, markVec(mineDepth, DIRECTION.Front))
- end
- if (isOre(DIRECTION.Up)) then
- table.insert(mineList, markVec(mineDepth, DIRECTION.Up))
- end
- if (isOre(DIRECTION.Down)) then
- table.insert(mineList, markVec(mineDepth, DIRECTION.Down))
- end
- turtle.turnRight()
- if (isOre(DIRECTION.Front)) then
- table.insert(mineList, markVec(mineDepth, DIRECTION.Right))
- end
- turtle.turnRight()
- if (isOre(DIRECTION.Front)) then
- table.insert(mineList, markVec(mineDepth, DIRECTION.Back))
- end
- turtle.turnRight()
- if (isOre(DIRECTION.Front)) then
- table.insert(mineList, markVec(mineDepth, DIRECTION.Left))
- end
- turtle.turnRight()
- else
- reverseTurns(mineDepth, turnList)
- end
- end
- --Go back to before vein mining
- reverseMoves(mineDepth, 0, moveList, turnList)
- end
- function triggerVeinMine(direction)
- if (isOre(direction)) then
- veinMine(direction)
- end
- end
- function inspectBlock()
- triggerVeinMine(DIRECTION.Front)
- turtle.turnRight()
- triggerVeinMine(DIRECTION.Front)
- turtle.turnRight()
- triggerVeinMine(DIRECTION.Front)
- turtle.turnRight()
- triggerVeinMine(DIRECTION.Front)
- turtle.turnRight()
- end
- function mineDownUp()
- --Going down
- while (turtle.digDown()) do end
- while (turtle.down()) do
- curr_depth = curr_depth + 1
- inspectBlock()
- while (turtle.digDown()) do end
- end
- --Going up
- while (curr_depth > 0) do
- while (turtle.digUp()) do end
- turtle.up()
- curr_depth = curr_depth - 1
- end
- end
- function advance()
- --Face center after advancing to next radius
- for o = 1, 4 do
- while (turtle.dig()) do end
- turtle.forward()
- end
- turtle.turnRight()
- turtle.turnRight()
- radius = radius + 2
- end
- mineDownUp()
- for i = 1, 0 do
- advance()
- for u = 1, 4 do
- for k = 1, radius do
- mineDownUp();
- if (radius ~= 0) then
- --Go to next diagonal
- for l = 1, 2 do
- while (turtle.dig()) do end
- turtle.forward()
- end
- turtle.turnLeft()
- for p = 1, 2 do
- while (turtle.dig()) do end
- turtle.forward()
- end
- turtle.turnRight()
- else
- return true
- end
- end
- turtle.turnRight()
- end
- turtle.turnRight()
- turtle.turnRight()
- end
Advertisement
Add Comment
Please, Sign In to add comment