Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variable decleration.
- local cycleCount
- local inFront, blockInfo = turtle.inspect()
- local blocksMoved = 0
- local freeSlots
- local selectedSlotItemInfo1
- local isBlockInFront, blockInfoInFront = turtle.inspect()
- local isBlockAbove, blockInfoAbove = turtle.inspectUp()
- local isBlockBelow, blockInfoBelow = turtle.inspectDown()
- -- Functions.
- function digSuckMove(direction)
- if direction == "up" then
- if turtle.detectUp() == true then
- print("Block above! Mining, picking up and moving up!")
- turtle.digUp()
- turtle.suckUp()
- turtle.up()
- else
- print("Nothing above! Moving up!")
- turtle.up()
- end
- elseif direction == "down" then
- if turtle.detectDown() == true then
- print("Block below! Mining, picking up and moving down!")
- turtle.digDown()
- turtle.suckDown()
- turtle.Down()
- else
- print("Nothing below! Moving down!")
- turtle.Down()
- end
- elseif direction == "forward" then
- if turtle.detect() == true then
- print("Block in front! Mining, picking up and moving forward!")
- turtle.dig()
- turtle.suck()
- turtle.forward()
- else
- print("Nothing in front! Moving forward!")
- turtle.forward()
- end
- else
- print("Invalid argument!")
- end
- end
- function returnToStart(wasHalted)
- local x
- turtle.turnLeft()
- turtle.turnLeft()
- if wasHalted == true then
- x = blocksMoved
- else
- x = cycleCount
- end
- for i3 = 1, x, 1 do
- while turtle.detect() do
- print("Can't move back!")
- os.sleep(1)
- end
- turtle.forward()
- print("Still need to move back "..cycleCount-i3.." times.")
- end
- print("Dumping items!")
- for i3 = 1, 16, 1 do
- turtle.select(i3)
- turtle.drop()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function isSpaceForItem(directionOfMining)
- -- Is there a free slot available?
- freeSlots = 0
- for i = 1, 16, 1 do
- if turtle.getItemCount(i) == 0 then
- freeSlots = freeSlots + 1
- end
- end
- if freeSlots == 9 or freeSlots > 9 then
- return true
- end
- -- Is there space for the same item then?
- if directionOfMining == "forward" then
- for i = 1, 16, 1 do
- selectedSlotItemInfo1 = turtle.getItemDetail(i)
- if blockInfoInFront.name == selectedSlotItemInfo1.name and turtle.getItemCount(i) < 55 then
- return true
- end
- end
- elseif
- directionOfMining == "up" then
- for i = 1, 16, 1 do
- selectedSlotItemInfo1 = turtle.getItemDetail(i)
- if blockInfoAbove.name == selectedSlotItemInfo1.name and turtle.getItemCount(i) < 55 then
- return true
- end
- end
- elseif
- directionOfMining == "down" then
- for i = 1, 16, 1 do
- selectedSlotItemInfo1 = turtle.getItemDetail(i)
- if blockInfoBelow.name == selectedSlotItemInfo1.name and turtle.getItemCount(i) < 55 then
- return true
- end
- end
- else
- -- No space available!
- return false
- end
- end
- -- Main Program.
- -- Read the cycle count.
- print("How many cycles to run?")
- cycleCount = read()
- -- Check if there is space for a maximum yeild of the cycle.
- if isSpaceForItem() == true then
- -- Run the cycle.
- for i = 1, cycleCount, 1 do
- -- Print the current cycle number.
- print("Running cycle number "..i..".")
- digSuckMove("forward")
- blocksMoved = blocksMoved + 1
- digSuckMove("up")
- digSuckMove("up")
- turtle.turnLeft()
- for i2 = 1, 2, 1 do
- turtle.dig()
- turtle.down()
- end
- turtle.dig()
- turtle.turnRight()
- turtle.turnRight()
- for i2 = 1, 2, 1 do
- turtle.dig()
- turtle.up()
- end
- turtle.dig();
- turtle.turnLeft()
- turtle.down()
- turtle.down()
- -- End of for.
- end
- print("Run completed successfuly! Returning to base!")
- returnToStart(false)
- print("Returned to starting position! Press any button to clear screen!")
- os.pullEvent('key')
- term.clear()
- term.setCursorPos(1,1)
- else
- print("Not enough free space for a max cycle yield! Returning to base!")
- returnToStart(true)
- print("Returned to starting position! Press any button to clear screen!")
- os.pullEvent('key')
- term.clear()
- term.setCursorPos(1,1)
- end
- -- Prevent instant termination.
- -- read()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement