Untitled


SUBMITTED BY: jokeriscrazy

DATE: Aug. 21, 2022, 11:28 a.m.

FORMAT: Text only

SIZE: 3.0 kB

HITS: 459

  1. -- 3 wide bridge v2.0 by SparkVGX
  2. --Variables
  3. distance = 0
  4. blocksPlaced = 0
  5. fuel = 1
  6. torches = 2
  7. spaceCounter = 7
  8. -- Clears screen for instructions or not
  9. function clear(test) -- function to reset screen
  10. term.clear()
  11. term.setCursorPos(1,1)
  12. if test == nil then -- easy way to decide whether to display text or not
  13. print("Place me on the ground just in front of where you want the bridge.")
  14. print()
  15. print("Fuel goes in slot 1, Torches in two, and blocks everywhere else.")
  16. print()
  17. print("Press any key to start..")
  18. end
  19. end
  20. function anyKey()
  21. while not bEnd do
  22. local event, key = os.pullEvent("key")
  23. if (key ~= 1) and (key ~= 42) then
  24. bEnd = true
  25. end
  26. end
  27. end
  28. -- If I need fuel, I will try use refuel
  29. function checkFuel()
  30. if turtle.getFuelLevel() <= 5 then
  31. turtle.select(1) --fuel goes in this slot
  32. turtle.refuel(1)
  33. end
  34. end
  35. -- Place torch
  36. function pTorch()
  37. turtle.select(2)
  38. turtle.up()
  39. turtle.place()
  40. turtle.down()
  41. end
  42. -- Select blocks to place
  43. -- only slots 3-16 should have blocks
  44. function selectBlock()
  45. for slot=3,16 do
  46. if turtle.getItemCount(slot)~=0 then
  47. turtle.select(slot)
  48. break
  49. end
  50. end
  51. end
  52. -- Select blocks and place them if possible, otherwise if out of blocks, wait.
  53. function placeB()
  54. selectBlock()
  55. if turtle.detect() == false then
  56. if turtle.place() == false then
  57. print("Need blocks")
  58. sleep(5)
  59. placeB()
  60. end
  61. blocksPlaced = blocksPlaced + 1
  62. end
  63. end
  64. -- pretty simple.. you turn around
  65. function turnAround()
  66. turtle.turnLeft()
  67. turtle.turnLeft()
  68. end
  69. --initial start to get turtle in position
  70. function runOnce()
  71. checkFuel()
  72. while turtle.detectDown() == true do
  73. turtle.forward()
  74. distance = distance + 1
  75. end
  76. turtle.down()
  77. turtle.turnLeft()
  78. placeB()
  79. turnAround()
  80. placeB()
  81. turtle.turnRight()
  82. end
  83. -- takes the turtle back where it started
  84. function goHome()
  85. turtle.up()
  86. selectBlock()
  87. turtle.placeDown()
  88. blocksPlaced = blocksPlaced + 1
  89. turtle.up()
  90. for i=1,distance do
  91. turtle.forward()
  92. end
  93. turnAround()
  94. turtle.down()
  95. print("All done!")
  96. print("I went " .. distance .. " meters and placed " .. blocksPlaced .. " blocks.")
  97. end
  98. --The main code to run
  99. function start()
  100. runOnce()
  101. --checks fuel, places blocks behind and on the sides.
  102. while turtle.back() do
  103. checkFuel()
  104. placeB()
  105. turtle.turnLeft()
  106. placeB()
  107. turnAround()
  108. placeB()
  109. turtle.turnLeft()
  110. spaceCounter = spaceCounter + 1
  111. distance = distance + 1
  112. -- every so often, places a torch and
  113. -- resets the counter
  114. if spaceCounter == 8 then
  115. pTorch()
  116. spaceCounter = 0
  117. end
  118. end
  119. -- all done? return to start
  120. goHome()
  121. end
  122. clear()
  123. anyKey()
  124. start()

comments powered by Disqus