Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print( "Usage: bridge <length>" )
- return
- end
- -- Initial Fueling
- turtle.refuel(1)
- -- variable to tell main function when to stop
- local o = 1
- j = 2
- -- Function to get the fuel level of the robot as a number
- fcount = function()
- return turtle.getFuelLevel()
- end
- -- Move forward, Fuel Check and Refuel function. also places down block for every movement.
- forwardCheck = function(num)
- for i=1,num do
- if not turtle.detectDown() then
- findSlot()
- turtle.placeDown()
- end
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- turtle.attackUp()
- if fcount() < 1 then
- turtle.select(1)
- print ("Attempting to eat my fuel...")
- if turtle.getItemCount(1) < 1 then
- print ("I am out of fuel...")
- o = 0
- end
- turtle.refuel(1)
- turtle.select(j)
- end
- turtle.digUp()
- end
- end
- findSlot()
- if fcount() < 1 then
- turtle.select(1)
- print ("Attempting to eat my fuel...")
- if turtle.getItemCount(1) < 1 then
- print ("I am out of fuel...")
- o = 0
- end
- turtle.refuel(1)
- turtle.select(j)
- end
- end
- --Finds an inventory slot with a block that is not slot 1
- findSlot = function()
- while turtle.getItemCount(j) == 0 do
- if j < 16 then
- j = j+1
- else
- print("Out of blocks")
- end
- end
- turtle.select(j)
- end
- placeBehind = function()
- turtle.turnLeft()
- turtle.turnLeft()
- findSlot()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- end
- rightBridge = function(i)
- turtle.turnRight()
- findSlot()
- turtle.placeUp()
- forwardCheck(1)
- placeBehind()
- forwardCheck(3)
- findSlot()
- turtle.placeUp()
- turtle.turnLeft()
- forwardCheck(1)
- placeBehind()
- end
- leftBridge = function(i)
- turtle.turnLeft()
- forwardCheck(1)
- placeBehind()
- forwardCheck(3)
- turtle.turnRight()
- forwardCheck(1)
- placeBehind()
- end
- --First line of bridge to establish pattern
- initLine = function()
- turtle.turnLeft()
- forwardCheck(2)
- turtle.placeUp()
- turtle.turnRight()
- turtle.turnRight()
- forwardCheck(1)
- placeBehind()
- forwardCheck(3)
- turtle.placeUp()
- turtle.turnLeft()
- forwardCheck(1)
- placeBehind()
- end
- niceBridge = function(length)
- initLine()
- for i=1,(length-1)/2 do
- leftBridge()
- rightBridge()
- end
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- for i=1,length do
- turtle.forward()
- end
- end
- niceBridge(tonumber(tArgs[1]))
Advertisement
Add Comment
Please, Sign In to add comment