Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local digDownAmount
- local digDeepAmount
- local stripeAmount
- local fuelSlot = 1
- local stripeIndex = 1
- local digDeepIndex = 1
- if not (#tArgs == 3) then
- print ("You need exactly three parameter!")
- return
- else
- digDownAmount = tonumber(tArgs[1])
- digDeepAmount = tonumber(tArgs[2])
- stripeAmount = tonumber(tArgs[3])
- end
- local function forward()
- while not turtle.forward() do
- if not turtle.dig() then
- turtle.attack()
- sleep(0.5)
- end
- end
- end
- local function up()
- while not turtle.up() do
- if not turtle.digUp() then
- turtle.attackUp()
- sleep(0.5)
- end
- end
- end
- local function down()
- while not turtle.down() do
- if not turtle.digDown() then
- turtle.attackDown()
- sleep(0.5)
- end
- end
- end
- local function FindChest()
- while not ChestFound do
- for i = 1, 4 do
- if turtle.detect() then
- print("Chest found... starting mine operation!")
- return
- else
- turtle.turnRight()
- end
- end
- print("No Chest found.. place a chest near turtle to start mining")
- sleep(3)
- end
- end
- local function mineToBase(amount)
- turtle.select(fuelSlot + 1)
- for i = 1, amount do
- down()
- turtle.placeUp()
- end
- print("Arrived at mining level.. start mining")
- end
- local function moveToTop(amount)
- turtle.select(fuelSlot + 1)
- for i = 1, amount do
- up()
- turtle.placeDown()
- end
- print("Arrived at starting level.. empting inventory")
- end
- -- Returns false if inventory full
- local function ContinueDigging()
- -- Check inventory
- if (turtle.getItemCount(16) >= 0) then
- return false
- end
- end
- local function DigRow()
- turtle.dig()
- forward()
- turtle.digDown()
- turtle.digUp()
- end
- local function EmptyInventory()
- if not turtle.detect() then
- print("No Block to place items into")
- return
- end
- -- Fuel is in slot 1, never empty this
- for i = 2, 16 do
- turtle.select(i)
- turtle.drop()
- end
- print("Inventory successfully emptied")
- end
- local function FirstMining(amount)
- for i = 1, amount do
- if ContinueDigging() then
- DigRow()
- digDeepAmount = digDeepAmount + 1
- else
- break
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- while (digDeepAmount > 1) do
- forward()
- digDeepAmount = digDeepAmount - 1
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- local function MiningLoop(amount)
- for i = 1, amount do
- stripeIndex = i
- FirstMining(digDeepAmount)
- if continueDigging() then
- print("Successfully mined stripe #"..i)
- else
- print("Full inventory, aborted mining stripe #"..i)
- break
- end
- if (i < amount) then
- turtle.turnRight()
- for j = 1, 3 do
- forward()
- end
- turtle.turnLeft()
- end
- end
- turtle.turnLeft()
- for i = 1, (stripeIndex - 1) * 3 do
- forward()
- end
- turtle.turnRight()
- end
- FindChest()
- mineToBase(digDownAmount)
- MiningLoop(stripeAmount)
- moveToTop(digDownAmount)
- EmptyInventory()
- print ("Run successfully!")
Advertisement
Add Comment
Please, Sign In to add comment