SoundChaos

niceBridge

May 5th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. if #tArgs ~= 1 then
  4. print( "Usage: bridge <length>" )
  5. return
  6. end
  7.  
  8. -- Initial Fueling
  9. turtle.refuel(1)
  10.  
  11. -- variable to tell main function when to stop
  12. local o = 1
  13. j = 2
  14. -- Function to get the fuel level of the robot as a number
  15. fcount = function()
  16. return turtle.getFuelLevel()
  17. end
  18.  
  19. -- Move forward, Fuel Check and Refuel function. also places down block for every movement.
  20. forwardCheck = function(num)
  21. for i=1,num do
  22. if not turtle.detectDown() then
  23. findSlot()
  24. turtle.placeDown()
  25. end
  26.  
  27. while not turtle.forward() do
  28. turtle.dig()
  29. turtle.attack()
  30. turtle.attackUp()
  31. if fcount() < 1 then
  32. turtle.select(1)
  33. print ("Attempting to eat my fuel...")
  34. if turtle.getItemCount(1) < 1 then
  35. print ("I am out of fuel...")
  36. o = 0
  37. end
  38. turtle.refuel(1)
  39. turtle.select(j)
  40. end
  41. turtle.digUp()
  42. end
  43. end
  44.  
  45. findSlot()
  46.  
  47. if fcount() < 1 then
  48. turtle.select(1)
  49. print ("Attempting to eat my fuel...")
  50. if turtle.getItemCount(1) < 1 then
  51. print ("I am out of fuel...")
  52. o = 0
  53. end
  54. turtle.refuel(1)
  55. turtle.select(j)
  56. end
  57. end
  58.  
  59. --Finds an inventory slot with a block that is not slot 1
  60. findSlot = function()
  61. while turtle.getItemCount(j) == 0 do
  62. if j < 16 then
  63. j = j+1
  64. else
  65. print("Out of blocks")
  66. end
  67. end
  68. turtle.select(j)
  69. end
  70.  
  71. placeBehind = function()
  72. turtle.turnLeft()
  73. turtle.turnLeft()
  74. findSlot()
  75. turtle.place()
  76. turtle.turnRight()
  77. turtle.turnRight()
  78. end
  79.  
  80. rightBridge = function(i)
  81. turtle.turnRight()
  82. findSlot()
  83. turtle.placeUp()
  84. forwardCheck(1)
  85. placeBehind()
  86. forwardCheck(3)
  87. findSlot()
  88. turtle.placeUp()
  89. turtle.turnLeft()
  90. forwardCheck(1)
  91. placeBehind()
  92. end
  93.  
  94. leftBridge = function(i)
  95. turtle.turnLeft()
  96. forwardCheck(1)
  97. placeBehind()
  98. forwardCheck(3)
  99. turtle.turnRight()
  100. forwardCheck(1)
  101. placeBehind()
  102. end
  103.  
  104. --First line of bridge to establish pattern
  105. initLine = function()
  106. turtle.turnLeft()
  107. forwardCheck(2)
  108. turtle.placeUp()
  109. turtle.turnRight()
  110. turtle.turnRight()
  111. forwardCheck(1)
  112. placeBehind()
  113. forwardCheck(3)
  114. turtle.placeUp()
  115. turtle.turnLeft()
  116. forwardCheck(1)
  117. placeBehind()
  118. end
  119.  
  120. niceBridge = function(length)
  121. initLine()
  122. for i=1,(length-1)/2 do
  123. leftBridge()
  124. rightBridge()
  125. end
  126. turtle.turnLeft()
  127. turtle.forward()
  128. turtle.turnLeft()
  129. for i=1,length do
  130. turtle.forward()
  131. end
  132. end
  133.  
  134. niceBridge(tonumber(tArgs[1]))
Advertisement
Add Comment
Please, Sign In to add comment