Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print( "Usage: road <length>" )
- return
- end
- local length = tonumber( tArgs[1] )
- if length < 1 then
- print( "Road length must be positive" )
- return
- end
- -- initialize starting position
- local x = 0
- local y = 0
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function Dig()
- while turtle.detect() do
- turtle.dig()
- sleep(0.5)
- end
- end
- local function DigDown()
- while turtle.detectDown() do
- turtle.digDown()
- sleep(0.5)
- end
- end
- local function DigUp()
- while turtle.detectUp() do
- turtle.digUp()
- end
- end
- local function refuel()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" or fuelLevel > 5 then
- return
- end
- local function tryRefuel()
- for i = 1 , 16, 1 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- if turtle.refuel(1) then
- return true
- end
- end
- end
- return false
- end
- if not tryRefuel() then
- print( "Add more fuel to continue." )
- while not tryRefuel() do
- sleep(1)
- end
- end
- end
- local function Up()
- refuel()
- while not turtle.up() do
- if turtle.detectUp() then
- DigUp()
- else
- turtle.attackUp()
- sleep(0.5)
- end
- end
- end
- local function Down()
- refuel()
- while not turtle.down() do
- if turtle.detectDown() then
- DigDown()
- else
- turtle.attackDown()
- sleep(0.5)
- end
- end
- end
- local function Forward()
- refuel()
- while not turtle.forward() do
- if turtle.detect() then
- Dig()
- else
- turtle.attack()
- sleep(0.5)
- end
- end
- end
- local function Back()
- refuel()
- if not turtle.back() then
- turtle.turnLeft()
- turtle.turnLeft()
- Forward()
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- cslot = 1
- function placeBlock()
- if turtle.getItemCount(cslot) == 0 then
- foundSlot = false
- while not foundSlot do
- for i = 9,15 do
- if turtle.getItemCount(i) > 0 then
- foundSlot = i
- break
- end
- end
- if not foundSlot then
- -- No resources
- print("Out of building materials. Please refill and press enter to continue.")
- io.read()
- end
- end
- cslot = foundSlot
- turtle.select(foundSlot)
- end
- turtle.placeDown()
- end
- local function Road()
- turtle.select(1)
- Dig()
- Forward()
- DigDown()
- placeBlock()
- end
- local function roadway()
- for i = 1, length, 1 do
- Road()
- end
- x = x + 1
- unload()
- end
- x = 0
- y = 0
- local function start()
- print("Add fuel in last slot")
- sleep(4)
- refuel()
- print("Starting Road")
- end
- clear()
- start()
- roadway()
Advertisement
Add Comment
Please, Sign In to add comment