Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fuelComparisonSlotNumber = 1
- local torchComparisonSlotNumber = 2
- local freeSpaceSlotNumber = 3
- local returnToBase = false
- local reachedLimit = false
- local limit = 0
- local fwdMoves = 0
- local maxMoves = 0
- function cls()
- term.clear()
- term.setCursorPos(1,1)
- end
- function hasTorchesLeft()
- for i = freeSpaceSlotNumber, 16 do
- turtle.select(i)
- if turtle.compareTo(torchComparisonSlotNumber) then return true end
- end
- return false
- end
- function hasFuelLeft()
- for i = freeSpaceSlotNumber, 16 do
- turtle.select(i)
- if turtle.compareTo(fuelComparisonSlotNumber) then return true end
- end
- return false
- end
- function inventoryFull()
- local result = true
- for i = freeSpaceSlotNumber, 16 do
- if turtle.getItemCount(i) == 0 then
- result = false
- end
- end
- return result
- end
- function recalculateMaxMoves()
- maxMoves = turtle.getFuelLevel()
- end
- function refuel()
- for i = freeSpaceSlotNumber, 16 do
- turtle.select(i)
- if turtle.compareTo(fuelComparisonSlotNumber) then turtle.refuel() end
- end
- recalculateMaxMoves()
- turtle.select(freeSpaceSlotNumber)
- end
- function placeTorch()
- for i = freeSpaceSlotNumber, 16 do
- turtle.select(i)
- if turtle.compareTo(torchComparisonSlotNumber) then break end
- end
- turtle.placeDown()
- turtle.select(freeSpaceSlotNumber)
- end
- function deposit()
- for i = freeSpaceSlotNumber, 16 do
- turtle.select(i)
- if (turtle.compareTo(fuelComparisonSlotNumber) == false) and (turtle.compareTo(torchComparisonSlotNumber) == false) then
- turtle.dropDown()
- end
- end
- --Indefinite Calls Below!
- if reachedLimit == false then
- if hasTorchesLeft() and hasFuelLeft() then
- returnToBase = false
- mine()
- end
- end
- end
- function mine()
- refuel()
- --Refuel turtle.
- turtle.turnLeft()
- --Turn left.
- turtle.up()
- recalculateMaxMoves()
- --Move turtle up one and recalculate fuel levels.
- while returnToBase == false do
- if turtle.detect() then turtle.dig() end
- --If there's a block infront then dig it.
- if turtle.forward() then
- recalculateMaxMoves()
- fwdMoves = fwdMoves + 1
- end
- --If the turtle succeeded in moving forward, then add on 1 to fwdMoves and recalculate
- --Fuel consumption.
- if turtle.detectUp() then turtle.digUp() end
- --If there is a block above the turtle, dig up.
- if turtle.detectDown() then turtle.digDown() end
- --If there is a block below the turtle, dig down.
- if fwdMoves % 5 == 0 then placeTorch() end
- --If the turtle has moved 5 places then place a torch.
- if maxMoves <= fwdMoves + 1 then
- cls()
- print("Ran out of fuel!")
- returnToBase = true
- end
- --If the max amount of moves is less than or equal to the amount
- --the turtle has moved forward, then return back.
- if inventoryFull() then
- cls()
- print("Inventory full!")
- returnToBase = true
- end
- --If the inventory is full, return back.
- if hasTorchesLeft() == false then
- cls()
- print("Ran out of torches!")
- returnToBase = true
- end
- --If the turtle has run out of torches, return back.
- if fwdMoves >= limit then
- cls()
- print("Turtle has reached limit!")
- returnToBase = true
- reachedLimit = true
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- --Rotate the turtle 180 degrees.
- for i = 1, fwdMoves do
- local fwdSuccess = false
- while fwdSuccess == false do
- if turtle.detect() then turtle.dig() end
- fwdSuccess = turtle.forward()
- end
- end
- --Go back to base.
- fwdMoves = 0
- --Reset fwdMoves
- turtle.down()
- --Go back down to ground level.
- turtle.turnLeft()
- --Face forward.
- deposit()
- --Deposit all items except coal and torches.
- end
- function start()
- print("Strip Mining Program")
- print("(Items will drop here!)")
- os.sleep(2)
- cls()
- print("How far would you like the turtle to go?")
- limit = tonumber(read())
- cls()
- print("Beginning mining process...")
- os.sleep(3)
- cls()
- mine()
- end
- start()
- cls()
- print("Program end.")
Advertisement
Add Comment
Please, Sign In to add comment