Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --test miner
- currentFacing = 0
- currentlySelectedSlot = 1
- fuelLevelToRefuelAt = 5
- dirtBlockCount = 0
- tunnelLength = 64
- torchesEvery = 10
- function main()
- getDirtBlock() -- init dirt blocks
- while getDirtBlock()==0 do
- awaitFix("No dirst blocks in 1sts slots")
- end
- local tunPos = 0
- local lastTorch = 0
- local fromSlot = dirtBlockCount + 1
- while tunPos < tunnelLength do
- print("tunPos: "..tunPos)
- --first fwd
- go('forward', true)
- --turn left and look
- turnLeft()
- if not checkEmpty('fwd') then
- if not checkDirt('fwd') then
- dig("fwd")
- putDirtBlock("fwd")
- end
- end
- go('up', true)
- if not checkEmpty('fwd') then
- if not checkDirt('fwd') then
- dig("fwd")
- putDirtBlock("fwd")
- end
- end
- go('up', true)
- if not checkEmpty('fwd') then
- if not checkDirt('fwd') then
- dig("fwd")
- putDirtBlock("fwd")
- end
- end
- if lastTorch >=torchesEvery then --torches
- turnLeft() --turn back
- placeTorch() --back
- turnRight()
- lastTorch = 0
- end
- if not checkEmpty('up') then --look up
- if not checkDirt('up') then
- while not checkEmpty('up') do
- dig("up")
- end
- putDirtBlock("up")
- end
- end
- turnRight()
- turnRight()
- if not checkEmpty('fwd') then
- if not checkDirt('fwd') then
- dig("fwd")
- putDirtBlock("fwd")
- end
- end
- go('down', true)
- if not checkEmpty('fwd') then
- if not checkDirt('fwd') then
- dig("fwd")
- putDirtBlock("fwd")
- end
- end
- go('down', true)
- if not checkEmpty('fwd') then
- if not checkDirt('fwd') then
- dig("fwd")
- putDirtBlock("fwd")
- end
- end
- turnLeft()
- if not checkEmpty('down') then
- if not checkDirt('down') then
- print("oh! dig down")
- dig("down")
- putDirtBlock("down")
- end
- else
- print("making bridge")
- putDirtBlock("down") -- for fucking peoples
- end
- --and repeat process
- tunPos = tunPos + 1
- lastTorch = lastTorch + 1
- end
- print("Ohh.. fin! I go back")
- turnLeft()
- turnLeft()
- while tunPos > 1 do
- go('forward', true)
- tunPos = tunPos - 1
- end
- putDirtBlock("up") --close tunnel
- go('forward', true)
- tunPos = tunPos - 1
- if checkEmpty("fwd")==false then --oh! chest!
- print("Unloading..")
- for i=fromSlot,14,1 do
- selectSlot(i)
- turtle.drop()
- end
- end
- end
- function placeTorch()
- if turtle.getItemCount(15) <=1 then
- print("I have no torches...")
- return false
- else
- selectSlot(15)
- if not turtle.place() then
- print("Can't place torch!")
- end
- end
- end
- function putDirtBlock(side)
- ensureFuel()
- local toSelect = 1
- toSelect = getDirtBlock()
- if toSelect==false then
- return false
- end
- selectSlot(toSelect)
- if side=="up" then
- return turtle.placeUp()
- elseif side=="down" then
- return turtle.placeDown()
- else
- return turtle.place()
- end
- return false
- end
- function getDirtBlock()
- if dirtBlockCount==0 then
- selectSlot(1)
- while turtle.getItemCount(currentlySelectedSlot)~=0 do
- dirtBlockCount = dirtBlockCount + 1
- selectSlot(currentlySelectedSlot + 1)
- end
- end
- if dirtBlockCount==0 then
- return false
- end
- local fromSlot = dirtBlockCount + 1
- for i=fromSlot,16,1 do
- if turtle.getItemCount(i)>1 then
- selectSlot(i)
- for j=1,dirtBlockCount,1 do
- if turtle.compareTo(j) then
- return i
- end
- end
- end
- end
- return false
- end
- function checkDirt(side)
- local result = false
- if dirtBlockCount==0 then
- getDirtBlock()
- end
- for j=1,dirtBlockCount,1 do
- selectSlot(j)
- if side=="up" then
- result = turtle.compareUp()
- elseif side=="down" then
- result = turtle.compareDown()
- else
- result = turtle.compare()
- end
- if result then
- return result
- end
- end
- return result
- end
- function checkEmpty(side)
- local result = false
- if side=="up" then
- result = not turtle.detectUp()
- elseif side=="down" then
- result = not turtle.detectDown()
- else
- result = not turtle.detect()
- end
- return result
- end
- function selectSlot(x)
- if x<1 then
- x = 1
- elseif x > 16 then
- x = 16
- end
- turtle.select(x)
- currentlySelectedSlot = x
- end
- function ensureFuel()
- -- Determine whether a refuel is required
- local fuelLevel = turtle.getFuelLevel()
- if (fuelLevel ~= "unlimited") then
- if (fuelLevel < fuelLevelToRefuelAt) then
- -- Need to refuel
- selectSlot(16)
- local fuelItems = turtle.getItemCount(16)
- -- Do we need to impact the emergency fuel to continue? (always
- -- keep one fuel item in slot 16)
- if (fuelItems == 0) then
- awaitFix("I want more fuel!")
- elseif (fuelItems == 1) then
- --load fuel from another slot
- local fueled = false
- local fromSlot = dirtBlockCount + 1
- for i=fromSlot,15,1 do
- selectSlot(i)
- if (turtle.compareTo(16)) then
- print("refueling from slot "+i)
- turtle.refuel(1)
- turtle.transferTo(16)
- fueled = true
- end
- end
- if not fueled then
- print("completely out of fuel!")
- end
- else
- print("refueling some")
- turtle.refuel(1)
- end
- end
- end
- end
- function turnFacing(facing)
- while facing ~= currentFacing do
- turnRight()
- end
- end
- function turnLeft()
- ensureFuel()
- turtle.turnLeft()
- currentFacing = currentFacing - 1
- if currentFacing < 0 then
- currentFacing = 3
- end
- end
- function turnRight()
- ensureFuel()
- turtle.turnRight()
- currentFacing = currentFacing + 1
- if currentFacing >= 4 then
- currentFacing = 0
- end
- end
- function dig(direction)
- local result = false
- local tries = 0
- selectSlot(dirtBlockCount + 1)
- while (not result) and (tries < 10) do
- ensureFuel()
- if direction=="up" then
- result = turtle.digUp()
- elseif direction=="down" then
- result = turtle.digDown()
- else
- result = turtle.dig()
- end
- tries = tries + 1
- end
- if not result then
- print ("can't dig in "..direction)
- end
- return result
- end
- function go(direction, allowDig)
- if direction=="right" then
- turnRight()
- direction="forward"
- end
- if direction=="left" then
- turnLeft()
- direction="forward"
- end
- if direction=="forward" then
- while turtle.detect() do
- if allowDig then
- ensureFuel()
- turtle.dig()
- else
- awaitFix("can't forward")
- end
- end
- while not turtle.forward() do
- ensureFuel()
- turtle.dig()
- end
- end
- if direction=="up" then
- while turtle.detectUp() do
- if allowDig then
- ensureFuel()
- turtle.digUp()
- else
- awaitFix("can't up")
- end
- end
- while not turtle.up() do
- ensureFuel()
- turtle.digUp()
- end
- end
- if direction=="down" then
- while turtle.detectDown() do
- if allowDig then
- ensureFuel()
- turtle.digDown()
- else
- awaitFix("can't down")
- end
- end
- while not turtle.down() do
- ensureFuel()
- turtle.digDown()
- end
- end
- end
- function awaitFix(message)
- print("I have problem: " .. message)
- print("Please fix it and press Enter to continue")
- io.read()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment