SoundChaos

LavaCast

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