Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tArgs = {...}
- local torchSlot = 15
- local fuelSlot = 16
- local torchCompareSlot = 14
- local torchCounter = 0
- local torchPlacePoint = 7
- local currentLevel = 0
- function refuel(fuelAmount)
- if fuelAmount == nil then fuelAmount = 1 end
- turtle.select(fuelSlot)
- if turtle.refuel(fuelAmount) == true then
- turtle.select(1)
- return true
- else
- turtle.select(1)
- return false
- end
- end
- function getFuel()
- return turtle.getFuelLevel()
- end
- function turnRight(revolutions)
- if revolutions == nil then revolutions = 1 end
- for i =1, revolutions do
- turtle.turnRight()
- end
- end
- function turnLeft(revolutions)
- if revolutions == nil then revolutions = 1 end
- for i = 1, revolutions do
- turtle.turnLeft()
- end
- end
- function digLayer()
- dig()
- goForward(1)
- digUp(2)
- turnRight()
- dig()
- goForward()
- turnLeft()
- digDown(2)
- turnLeft()
- goForward(2)
- dig()
- goForward(1)
- turnRight()
- digUp(2)
- turnRight()
- goForward(1)
- turnLeft()
- goDown(2)
- end
- function goUp(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- turtle.up()
- currentLevel = currentLevel + 1
- end
- end
- function goDown(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- turtle.down()
- currentLevel = currentLevel - 1
- end
- end
- function goForward(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- turtle.forward()
- end
- end
- function goBack(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- turtle.back()
- end
- end
- function turnAround()
- turnRight(2)
- end
- function digUp(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- while turtle.detectUp() == true do
- turtle.digUp()
- slee(0.5)
- end
- if distance > 1 then
- goUp()
- end
- end
- end
- function dig(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- while turtle.detect() == true do
- turtle.dig()
- sleep(0.5)
- end
- end
- end
- function digDown(distance)
- if distance == nil then distance = 1 end
- for i = 1, distance do
- turtle.digDown()
- sleep(0.5)
- if distance > 1 then
- goDown()
- end
- end
- end
- function goToFloor()
- if currentLevel > 0 then
- while turtle.detectDown == false do
- goDown()
- if currentLevel == 0 then
- print("Possibly over a chasm. Breaking")
- return false
- end
- end
- end
- return true
- end
- function placeTorch()
- turtle.select(torchSlot)
- if turtle.compareTo(torchCompareSlot) == true then
- if turtle.detectDown() == true then
- turnAround()
- goForward(1)
- if turtle.detectDown() == true then
- goBack(1)
- turtle.place()
- turnAround()
- end
- else
- if goToFloor() == true then
- turnAround()
- goForward(1)
- if turtle.detectDown() == true then
- goBack(1)
- turtle.place()
- turnAround()
- end
- end
- end
- else
- print("Out of torches!")
- end
- turtle.select(1)
- end
- function returnToStart(distance)
- turnAround()
- goForward(distance)
- turnAround()
- end
- function checkTorchPlacement()
- torchCounter = torchCounter + 1
- if torchCounter == torchPlacePoint then
- placeTorch()
- torchCounter = 0
- end
- end
- function dropLoad()
- for i = 1, 13 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- end
- if tArgs[1] == nil then
- print("Usage: miner <length of shaft")
- else
- shaftLength = tonumber(tArgs[1])
- for i = 1, shaftLength do
- print("Working on layer "..i)
- digLayer()
- checkTorchPlacement()
- if getFuel() == 0 then
- refuel(5)
- end
- end
- returnToStart(shaftLength)
- turnAround()
- dropLoad()
- turnAround()
- print("Job Done!")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement