Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- bridge <distance>
- -- needs building material in the first slot (eg. cobblestone)
- -- more building material can be supplied in other slots too if needed
- local WALL_SLOT = 1
- local args = { ... }
- local distance = 0
- if #args ~= 1 then
- print("Usage: bridge<distance>")
- error()
- end
- distance = args[1]
- if turtle.getFuelLevel() < 1*distance then
- print("Not enough fuel to build the specified distance")
- error()
- end
- -- ---------------------------------------------------------------------
- function reorderWalls()
- for i = 1,16 do
- if i~=WALL_SLOT then
- turtle.select(i)
- -- os.sleep(0.1)
- if turtle.compareTo(WALL_SLOT) and (turtle.getItemCount(i)>0) then
- while (turtle.getItemCount(i)>0) and (turtle.getItemCount(WALL_SLOT)<64) and (turtle.transferTo(WALL_SLOT,1)) do
- -- os.sleep(0.01)
- end
- end
- end
- end
- turtle.select(WALL_SLOT)
- end
- function suckAll()
- local i = 1
- while i <= 16 and (i==WALL_SLOT or turtle.getItemSpace(i)==0) do
- i = i + 1
- end
- if i <= 16 then
- turtle.select(i)
- turtle.suck()
- turtle.suckUp()
- turtle.suckDown()
- reorderWalls()
- end
- turtle.select(WALL_SLOT)
- end
- function wall()
- turtle.select(WALL_SLOT)
- while turtle.detect() and not turtle.compare() do
- turtle.dig()
- -- suckAll()
- end
- turtle.select(WALL_SLOT)
- if not turtle.compare() then
- while not turtle.place() do
- turtle.dig()
- end
- end
- end
- function wallDown()
- turtle.select(WALL_SLOT)
- while turtle.detectDown() and not turtle.compareDown() do
- turtle.digDown()
- -- suckAll()
- end
- turtle.select(WALL_SLOT)
- if not turtle.compareDown() then
- while not turtle.placeDown() do
- turtle.digDown()
- end
- end
- end
- -- ---------------------------------------------------------------------
- local stepsSinceReorder = 21
- for i=1,distance do
- if stepsSinceReorder>20 then
- reorderWalls()
- stepsSinceReorder = 0
- turtle.select(WALL_SLOT)
- if turtle.getItemCount() < 3 then
- print("not enough building blocks")
- error()
- end
- end
- while not turtle.forward() do
- turtle.dig()
- -- suckAll()
- end
- wallDown()
- while turtle.detectUp() do
- turtle.digUp()
- -- suckAll()
- end
- turtle.turnLeft()
- wall()
- turtle.turnRight()
- turtle.turnRight()
- wall()
- turtle.turnLeft()
- stepsSinceReorder = stepsSinceReorder+1
- end
- print("bridge built")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement