Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- startHeight = args[1]
- flatBedrock = args[2]
- moveSeq = {}
- moveSeq[1] = 0
- moveSeq[2] = 3
- moveSeq[3] = 1
- moveSeq[4] = 4
- moveSeq[5] = 2
- chestSlot = 16
- cobbleSlot = 1
- digDir = nil
- minLevel = 5
- if flatBedrock then
- minLevel = 2
- end
- ------------------
- --MOVEMENT METHODS
- ------------------
- --Just runs turtle.forward()
- --until the specified amount toMov
- --is met. Digs block if unable to move
- function mF(toMov, action)
- if not toMov then
- toMov = 1
- end
- for i = 1, toMov do
- while not (turtle.forward()) do
- turtle.dig()
- end
- if action then action() end
- end
- end
- --Runst turtle.back() toMov times
- function mB(toMov, action)
- if not toMov then
- toMov = 1
- end
- for i = 1, toMov do
- while not turtle.back() do
- sleep(.1)
- end
- if action then action() end
- end
- end
- --Runs turtle.up() toMov times
- --and digs up if unable to move up.
- function mU(toMov, action)
- if not toMov then
- toMov = 1
- end
- for i = 1, toMov do
- while not (turtle.up()) do
- turtle.digUp()
- end
- if action then action() end
- end
- end
- --Runs turtle.down() toMov times
- -- and digs down if unable to move down
- function mD(toMov, action)
- if not toMov then
- toMov = 1
- end
- for i = 1, toMov do
- while not (turtle.down()) do
- turtle.digDown()
- end
- if action then action() end
- end
- end
- --Turns the turtle 180 degrees
- function turnAround()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- ------------------
- ------------------
- --UTILITY METHODS
- ------------------
- ------------------
- function fuelCheck()
- pokeBlocks = startHeight - minLevel + 1
- pokeMove = pokeBlocks * 52
- tranMove = 16 * 16
- totalMove = tranMove + pokeMove
- print("Current Fuel:", turtle.getFuelLevel())
- print("Estimated Fuel:", totalMove + 100)
- if (totalMove + 100) >= turtle.getFuelLevel() then
- print("Need more fuel for requested chunkmine.")
- return false
- end
- return true
- end
- function dropSide(slotNum, side)
- turtle.select(slotNum)
- side = string.lower(side)
- success = false
- if side == "front" then
- success = turtle.drop()
- elseif side == "top" then
- success = turtle.dropUp()
- elseif side == "bottom" then
- success = turtle.dropDown()
- else
- success = turtle.drop()
- end
- return success
- end
- function emptyInv(slotsToEmpty, side)
- oldSlot = turtle.getSelectedSlot()
- if not side then
- side = "back"
- end
- if not slotsToEmpty then
- count = 16
- else
- count = table.getn(slotsToEmpty)
- end
- for i = 1, count do
- dropSide(slotsToEmpty[i], side)
- end
- turtle.select(oldSlot)
- end
- function doChest()
- turtle.select(chestSlot)
- while not turtle.placeUp() do
- turtle.digUp()
- sleep(.1)
- end
- slotsToEmpty = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
- emptyInv(slotsToEmpty, "top")
- turtle.select(chestSlot)
- turtle.digUp()
- turtle.select(cobbleSlot)
- end
- ------------------
- ------------------
- --MINING METHODS
- ------------------
- ------------------
- function checkOre()
- success, block = turtle.inspect()
- if not success then return false end
- name = string.lower(block.name)
- return (string.match(name, "ore"))
- end
- function scan()
- for i=1, 4 do
- if checkOre() then
- turtle.dig()
- end
- turtle.turnRight()
- end
- end
- function poke()
- turtle.select(cobbleSlot)
- for i=1+minLevel, startHeight do
- digDir(1, scan)
- if (i == minLevel + 2 and digDir == mD) then turtle.placeUp() end
- end
- if digDir == mD then
- digDir = mU
- else
- turtle.placeDown()
- digDir = mD
- end
- doChest()
- end
- function doRow(startMove)
- mF(startMove)
- moveAmount = 15 - startMove
- poke()
- while moveAmount >= 5 do
- mF(5)
- moveAmount = moveAmount - 5
- poke()
- end
- mF(moveAmount)
- end
- function doChunk()
- moveIndex = 1
- for i=1, 16 do
- evenRow = (i % 2 == 0)
- startMove = moveSeq[moveIndex]
- if evenRow and startMove ~= 0 then startMove = 5 - startMove end
- doRow(startMove)
- if evenRow and i ~= 16 then
- turtle.turnLeft()
- mF(1)
- turtle.turnLeft()
- elseif i ~= 16 then
- turtle.turnRight()
- mF(1)
- turtle.turnRight()
- end
- moveIndex = moveIndex + 1
- if moveIndex > 5 then moveIndex = 1 end
- end
- end
- function start()
- digDir = mD
- if fuelCheck() then
- doChunk()
- end
- turnAround()
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement