Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --pastebin get JWrTxV1z MakeRoom
- --pastebin get SpEd82Jp StripLayer
- --pastebin get 7JMXTNu5 TallTunnel
- --pastebin get Yrsn4Wne Roadie
- --Roadie.lua 10 1
- --Roadie.lua 128
- local tArgs = { ... }
- if #tArgs >= 3 or #tArgs == 0 then
- print( "Usage: Roadie <length> <follow terrain flag> <use anything flag>" )
- print("<length> should be between 1 and 128 or positive number")
- print("<follow terrain flag> (default: 0) 1: if there is an obstruction it will make the road one layer higher.")
- print(" if there is air below the center it will make the road one layer lower.")
- print(" 0: the road will be flat and it will tunnel stright through.")
- print("<use anything flag> (default: 0) 1: it will use what it collects to go farther than 128 and use slots 5-16 as building sources.")
- print( "Row 1 should contain fuel (and empty slots)" )
- print( "Row 2 should contain the road edge blocks" )
- print( "Row 3 should contain the road inside blocks" )
- print( "Row for should be inside, inside, empty, empty" )
- return
- end
- local length = tonumber( tArgs[1] )
- local followGround = tonumber( tArgs[2] )
- if followGround == nil then
- followGround = 0
- end
- local useAnything = tonumber( tArgs[3] )
- if useAnything == nil then
- useAnything = 0
- end
- local tall = 2
- --print (useAnything)
- if useAnything == 0 and length > 128 then
- print( "Road is longer than supplies." )
- return
- end
- if length < 1 then
- print( "Road length must be positive" )
- return
- end
- local depth = 0
- local collected = 0
- local unloaded = 0
- local innerBlocks = {}
- local outerBlocks = {}
- local innerSource = 1
- local outerSource = 1
- if useAnything == 0 then
- for n=1,4 do
- local nCount = turtle.getItemCount(n + 4)
- outerBlocks[n] = nCount
- end
- for n=1,6 do
- local nCount = turtle.getItemCount(n + 8)
- innerBlocks[n] = nCount
- end
- end
- local function collect()
- collected = collected + 1
- if math.fmod(collected, 25) == 0 then
- print( "Mined "..collected.." items." )
- end
- end
- local function isFull()
- local bFull = true
- local nTotalItems = 0
- for n=1,16 do
- local nCount = turtle.getItemCount(n)
- if nCount == 0 then
- bFull = false
- end
- nTotalItems = nTotalItems + nCount
- end
- if bFull then
- print( "No empty slots left." )
- return true
- end
- return false
- end
- local function unload()
- print( "Unloading items..." )
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(3)
- turtle.place()
- --1: Flooring
- --2: Fuel
- --3: Chests
- --4: Torches
- for n=5,16 do
- unloaded = unloaded + turtle.getItemCount(n)
- turtle.select(n)
- turtle.drop()
- end
- --collected = 0
- turtle.select(1)
- turtle.turnRight()
- turtle.turnRight()
- end
- local function tryDig()
- while turtle.detect() do
- if turtle.dig() then
- collect()
- --sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryDigUp()
- while turtle.detectUp() do
- if turtle.digUp() then
- collect()
- --sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryDigDown()
- while turtle.detectDown() do
- if turtle.digDown() then
- collect()
- --sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- 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 Road." )
- end
- end
- local function tryUp()
- refuel()
- while not turtle.up() do
- if turtle.detectUp() then
- if not tryDigUp() then
- return false
- end
- elseif turtle.attackUp() then
- collect()
- else
- sleep( 0.1 )
- end
- end
- return true
- end
- local function tryDown()
- refuel()
- while not turtle.down() do
- if turtle.detectDown() then
- if not tryDigDown() then
- return false
- end
- elseif turtle.attackDown() then
- collect()
- else
- sleep( 0.1 )
- end
- end
- return true
- end
- local function tryForward()
- refuel()
- --if isFull() then
- -- unload()
- --end
- while not turtle.forward() do
- if turtle.detect() then
- if not tryDig() then
- return false
- end
- elseif turtle.attack() then
- collect()
- else
- sleep( 0.1 )
- end
- end
- return true
- end
- local function placeAny()
- for n=5,16 do
- if turtle.getItemCount(n) > 0 then
- turtle.select(n)
- if turtle.placeDown() then
- turtle.select(1)
- return true
- end
- end
- end
- turtle.select(1)
- return false
- end
- local function placeOuter()
- local cnt = 0
- while not turtle.detectDown() do
- cnt = 0
- for n=1,4 do
- cnt = cnt + outerBlocks[n]
- if outerBlocks[n] > 0 then
- turtle.select(n + 4)
- if turtle.placeDown() then
- outerBlocks[n] = outerBlocks[n] - 1
- turtle.select(1)
- return true
- end
- end
- end
- turtle.select(1)
- if cnt == 0 then
- return false
- end
- end
- end
- local function placeInner()
- local cnt = 0
- while not turtle.detectDown() do
- cnt = 0
- for n=1,6 do
- cnt = cnt + innerBlocks[n]
- if innerBlocks[n] > 0 then
- turtle.select(n + 8)
- if turtle.placeDown() then
- innerBlocks[n] = innerBlocks[n] - 1
- turtle.select(1)
- return true
- end
- end
- end
- turtle.select(1)
- if cnt == 0 then
- return false
- end
- end
- end
- local function turnDir(dir)
- if dir == 1 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- local function terrainTest(dir)
- turnDir(dir)
- --if there is dirt next to the road, we need to go up.
- if turtle.detect() then
- turnDir(-1 * dir)
- return 1
- end
- if not tryDown() then
- turnDir(-1 * dir)
- return 0
- end
- --If there is air below the road, we need to go down.
- if not turtle.detect() then
- turnDir(-1 * dir)
- tryUp()
- return -1
- end
- --This should really always work.
- turnDir(-1 * dir)
- tryUp()
- return 0
- end
- local terrainMemory = 0
- local function hallway(hallLength)
- for n=1,hallLength do
- tryDigDown()
- if followGround ~= 0 and n == math.floor((hallLength + 1) / 2) then
- terrainMemory = terrainTest(dir)
- end
- if useAnything ~= 0 then
- --print("Placing Any")
- placeTest = placeAny()
- elseif n == 1 or n == hallLength then
- --print("Placing Outer")
- placeTest = placeOuter()
- else
- --print("Placing Inner")
- placeTest = placeInner()
- end
- if placeTest == false then
- print("Ran out of supplies!")
- return false
- end
- tryDigUp()
- if n<hallLength then
- tryDig()
- if not tryForward() then
- print("Unable to move forward.")
- return false
- end
- else
- return true
- end
- end
- end
- local function road(roadLength)
- turtle.turnRight()
- tryForward()
- tryForward()
- turtle.turnRight()
- turtle.turnRight()
- dir = 1
- for n=1,roadLength do
- hallTest = hallway(5)
- if not hallTest then
- return false
- end
- if n < roadLength then
- if dir == 1 then
- turtle.turnRight()
- stepTest = tryForward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- stepTest = tryForward()
- turtle.turnLeft()
- end
- dir = -1 * dir
- if terrainMemory > 0 then
- stepTest = stepTest and tryUp()
- elseif terrainMemory < 0 then
- stepTest = stepTest and tryDown()
- end
- terrainMemory = 0
- if not stepTest then
- print("Unable to move forward.")
- return false
- end
- end
- end --loop
- turtle.turnRight()
- turtle.turnRight()
- tryForward()
- tryForward()
- if dir ~= 1 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- return true
- end --road
- print( "Roading..." )
- if road(length) then
- print( "Road complete." )
- else
- print( "Road is not complete!")
- end
- print( "Mined "..collected.." items total." )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement