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
- local inventoryFull = false
- 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
- if CheckFuel() then
- down()
- else
- print("No fuel available! :(")
- return
- end
- turtle.placeUp()
- end
- print("Reached target y-level.. start mining")
- end
- local function moveToTop(amount)
- turtle.select(fuelSlot + 1)
- for i = 1, amount do
- if CheckFuel() then
- up()
- else
- print("No fuel available! :(")
- return
- end
- turtle.placeDown()
- end
- print("Reached start level.. empting inventory")
- end
- -- Returns false if inventory full
- local function ContinueDigging()
- -- Check inventory
- if (turtle.getItemCount(16) > 0) then
- return false
- end
- return true
- end
- local function CheckFuel()
- if (turtle.getFuelLevel() >= 100) then
- return true
- else
- local oldSlot = turtle.getSelectedSlot()
- turtle.select(FuelSlot)
- if turtle.refuel(100) then
- turtle.select(oldSlot)
- return true
- else
- turtle.select(oldSlot)
- return false
- end
- 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() and CheckFuel() then
- DigRow()
- digDeepIndex = digDeepIndex + 1
- -- print("digDeepIndex = "..digDeepIndex)
- else
- break
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- while (digDeepIndex > 1) do
- forward()
- digDeepIndex = digDeepIndex - 1
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- local function MiningLoop(amount)
- for i = 1, amount do
- stripeIndex = i
- FirstMining(digDeepAmount)
- if ContinueDigging() and CheckFuel() then
- -- print("Successfully mined stripe #"..i)
- else
- print("Full inventory or out of fuel, aborted mining stripe #"..i)
- inventoryFull = true
- 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
- local function Main()
- inventoryFull = false
- FindChest()
- mineToBase(digDownAmount)
- MiningLoop(stripeAmount)
- moveToTop(digDownAmount)
- EmptyInventory()
- if not inventoryFull then
- print ("Run successfully!")
- return
- else
- print ("Run partially, another iteration starting...")
- Main()
- end
- end
- print("Place fuel reserves in slot 1 (upper left) if desired and hit any key to start")
- os.pullEvent("key")
- Main()
Advertisement
Add Comment
Please, Sign In to add comment