Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Simple program that mines forward along a 1x2 passageway until
- -- it detects a block corresponding to the block in (tstslt) then it returns
- -- to the start. It then outputs the number of blocks to the required block
- -- v03
- -- by LN
- local travld = 0 -- How many blocks we travel
- local dist = 0 -- As above
- local done = 0 -- when 1 indicates block matching tstslt matched
- local job = "Counter"
- local tstslt = 16 -- Slot to compare against (1-16)
- local function refuel()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" or fuelLevel > 0 then
- return
- end
- local function tryRefuel()
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- turtle.select(n)
- if turtle.refuel(1) then
- turtle.select(1)
- return true
- end
- end
- end
- turtle.select(1)
- return false
- end
- if not tryRefuel() then
- print( "Add more fuel to continue." )
- while not tryRefuel() do
- sleep(1)
- end
- print( "Resuming..." ..job)
- end
- end
- local function tryDigDown()
- while turtle.detectDown() do
- turtle.digDown()
- sleep(0.5)
- end
- end
- local function tryDig()
- while turtle.detect() do
- turtle.dig()
- sleep(0.5)
- end
- end
- local function tryForward()
- refuel()
- while not turtle.forward() do
- if turtle.detect() then
- if not tryDig() then
- return false
- end
- elseif turtle.attack() then
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local function testDown()
- end
- local function reverse()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- local function travel()
- while done ~= 1 do
- turtle.select(16)
- if turtle.compareDown() then
- done = 1
- -- travld = travld + 1
- print("True")
- else
- done = 0
- print("False")
- if (done == 0) then
- tryDigDown()
- tryDig()
- tryForward()
- travld = travld + 1
- end
- end
- turtle.select(1)
- print("Done = " .. done)
- end
- end
- local function rtb()
- reverse()
- dist = travld
- while dist > 0 do
- tryForward()
- dist = dist - 1
- end
- reverse()
- end
- -- Program...
- travel()
- rtb()
- print("This Turtle Counted a total of: " .. travld .. " blocks before RTB.")
Advertisement
Add Comment
Please, Sign In to add comment