Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- A digging turtle program that will make a tunnel
- -- The tunnel will attempt to contour to the ground, but if it reaches a slope higher than 1 block
- -- it will start digging or placing filler blocks.
- -- The turtle will likely error out of it runs out of fuel or any type of block
- -- Cover blocks ( try glass! ) : Slots 1-4
- -- Filler blocks ( try gravel!) : Slots 5-6
- -- Floor blocks ( try stone bricks!) : Slots 7-9
- -- Note: Filler blocks must be affected by gravity for it to work ( ie. gravel, sand, etc. )
- -- Settings
- -- You can change how many slots to use of the inventory and for which types of blocks by changing these numbers
- local coverSpotEnd = 8
- local fillerSpotEnd = 10
- local floorSpotEnd = 12
- -- Change the height of the tunnel
- local height = 4
- -- Change the length of the tunnel
- local distance = 100
- -- Used by program
- local currentCover = 1
- local currentFiller = coverSpotEnd + 1
- local currentFloor = fillerSpotEnd + 1
- local FORWARD = 1
- local UP = 2
- function refuel()
- local slot = 1
- while ( turtle.getFuelLevel() < 100 and slot < 16 ) do
- slot = slot + 1
- turtle.select(slot)
- turtle.refuel(10)
- end
- turtle.select(1)
- end
- function goForward()
- refuel()
- if ( turtle.getFuelLevel() < 100 ) then
- print "Ran out of fuel!"
- os.exit()
- end
- while ( not turtle.forward() ) do
- turtle.dig()
- os.sleep(1)
- end
- end
- function goUp()
- refuel()
- if ( turtle.getFuelLevel() < 100 ) then
- print "Ran out of fuel!"
- os.exit()
- end
- while ( not turtle.up() ) do
- turtle.digUp()
- os.sleep(1)
- end
- end
- function goDown()
- refuel()
- if ( turtle.getFuelLevel() < 100 ) then
- print "Ran out of fuel!"
- os.exit()
- end
- while ( not turtle.down() ) do
- turtle.digDown()
- os.sleep(1)
- end
- end
- function PlaceFiller()
- turtle.select(currentFiller)
- while ( turtle.getItemCount(currentFiller) < 1 ) do
- currentFiller = currentFiller + 1
- if ( currentFiller > 16 or currentFiller > fillerSpotEnd ) then
- print( "Ran out of filler blocks!" )
- os.exit()
- end
- turtle.select(currentFiller)
- end
- turtle.placeDown()
- end
- function MoveForward()
- -- Block in front of us, go up
- if ( turtle.detect() ) then
- goUp()
- end
- goForward()
- -- Nothing below us, go down
- if ( not turtle.detectDown() ) then
- goDown()
- end
- -- Still nothing below us, drop filler
- while ( not turtle.detectDown() ) do
- PlaceFiller()
- end
- end
- function PlaceCover(direction)
- turtle.select(currentCover)
- while ( turtle.getItemCount(currentCover) < 1 ) do
- currentCover = currentCover + 1
- if ( currentCover > 16 or currentCover > coverSpotEnd ) then
- print( "Ran out of cover blocks!" )
- os.exit()
- end
- turtle.select(currentCover)
- end
- if (direction == FORWARD) then
- turtle.place()
- elseif ( direction == UP ) then
- turtle.placeUp()
- end
- end
- function BuildCover()
- for h = 1,height do
- turtle.turnLeft()
- PlaceCover(FORWARD)
- turtle.turnRight()
- turtle.turnRight()
- PlaceCover(FORWARD)
- turtle.turnLeft()
- goUp()
- end
- goDown()
- PlaceCover(UP)
- for h = 2,height do
- goDown()
- end
- end
- function BuildFloor()
- turtle.select(currentFloor)
- while ( turtle.getItemCount(currentFloor) < 1 ) do
- currentFloor = currentFloor + 1
- if ( currentFloor > 16 or currentFloor > floorSpotEnd ) then
- print( "Ran out of floor blocks!" )
- os.exit()
- end
- turtle.select(currentFloor)
- end
- turtle.digDown()
- turtle.placeDown()
- end
- function BuildTunnel()
- BuildCover()
- BuildFloor()
- end
- for dist = 1,distance do
- BuildTunnel()
- MoveForward()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement