Advertisement
vxste

ComputerCraft Bridger

Oct 8th, 2024 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. local function GetItemCount()
  2. local ItemCount = 0;
  3.  
  4. for i = 1, math.huge do
  5. local Success, Result = pcall(function()
  6. return turtle.getItemCount(i)
  7. end)
  8. ItemCount = ItemCount + (Success and Result or 0)
  9. if not Success then
  10. break;
  11. end
  12. end
  13.  
  14. return ItemCount;
  15. end
  16.  
  17. local function left(times)
  18. times = times or 1
  19. for _ = 1, times do
  20. turtle.turnLeft()
  21. end
  22. end
  23.  
  24. local function right(times)
  25. times = times or 1
  26. for _ = 1, times do
  27. turtle.turnRight()
  28. end
  29. end
  30.  
  31. local Blocks = GetItemCount();
  32.  
  33. local Settings = {
  34. LavaCheck = false
  35. }
  36.  
  37. local Output = string.format("Placing %d blocks, Approximate time: ~%.2f seconds", Blocks, Blocks * .85)
  38. print(Output)
  39.  
  40. local function Bridge()
  41. local function GetMostOwnedItem()
  42. local Items, Slot = 0, 0;
  43.  
  44. for i = 1, math.huge do
  45. local Success, Result = pcall(function()
  46. return turtle.getItemCount(i)
  47. end)
  48. if not Success then
  49. break;
  50. end
  51.  
  52. if Result > Items then
  53. Items = Result
  54. Slot = i
  55. end
  56. end
  57.  
  58. return Slot;
  59. end
  60.  
  61. local function Place()
  62. if not turtle.detectDown() then
  63. if turtle.getItemCount(turtle.getSelectedSlot()) == 0 and #GetItemCount() > 0 then
  64. turtle.select(GetMostOwnedItem())
  65. end
  66. turtle.placeDown()
  67. end
  68. end
  69.  
  70. local function MoveAndPlace(Steps)
  71. Steps = Steps or 1;
  72.  
  73. for _ = 1, Steps do
  74. turtle.forward()
  75. Place()
  76. end
  77. end
  78.  
  79. local function IsLava()
  80. local _, Data = turtle.inspect()
  81.  
  82. return Data.name == "minecraft:lava"
  83. end
  84.  
  85. local function Main()
  86. MoveAndPlace()
  87. if turtle.detect() then
  88. turtle.dig()
  89. end
  90. if turtle.detectUp() then
  91. turtle.digUp()
  92. end
  93. -- Check it's sides to see if there is any lava
  94. if Settings.LavaCheck then
  95. right()
  96. if IsLava() then
  97. turtle.place()
  98. end
  99. left(2)
  100. if IsLava() then
  101. turtle.place()
  102. end
  103. right()
  104. end
  105. end
  106.  
  107. -- Keep building until the turtle runs out of items
  108. while GetItemCount() ~= 0 do
  109. Main()
  110. end
  111. end
  112.  
  113. print("Do you wanna check for lava? (Y/N)")
  114.  
  115. Settings.LavaCheck = string.lower(read()) == "y" and true or false
  116.  
  117. print("LavaCheck:",Settings.LavaCheck)
  118.  
  119. Bridge()
  120.  
  121. print("Finished making bridge!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement