s3ptum

floor placement loop

Aug 28th, 2021 (edited)
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Notes
  2.  
  3. --Slot 1 = Fuel
  4. --Slot 2 = Torch (Not yet Used)
  5. --Slot 3-16 = Cobble
  6.  
  7.  
  8.  
  9. --Find slot with something in it. Cobble.
  10. --Needs to be enhanced
  11. function findBlock()
  12.     for slot = 3,16 do
  13.     if turtle.getItemCount(slot) >0 then
  14.             turtle.select(slot)
  15.             break
  16.     end
  17.     end
  18. end
  19.  
  20. --Simple detect block in front, if false then move one block forward
  21. function moveForward()
  22.     if turtle.detect() == false then
  23.         place()
  24.         turtle.forward()
  25.   end
  26. end
  27.  
  28. --detect if block below and place
  29. function place()
  30.     if turtle.detectDown() == false then
  31.     turtle.placeDown()
  32.     end
  33. end
  34.  
  35. --refuel from slot 1
  36. function refuel()
  37.     turtle.select(1)
  38.     turtle.refuel()
  39.    
  40. end
  41.  
  42. --turn right
  43. function turnRight()
  44.     turtle.turnRight()
  45.         turtle.forward()
  46.         turtle.placeDown()
  47.         turtle.turnRight()
  48. end
  49. --turn left
  50. function turnLeft()
  51.     turtle.turnLeft()
  52.         turtle.forward()
  53.         turtle.placeDown()
  54.         turtle.turnLeft()
  55. end
  56.  
  57. --Main Loop check fuel check inventory and begin movement
  58. function mainLoop()  
  59.   if turtle.getFuelLevel() <= 1 then
  60.         refuel()
  61.     elseif turtle.getItemCount() <= 1 then
  62.         findBlock()
  63.     elseif (turtle.getFuelLevel()>0) and (turtle.getItemCount()>0) then
  64.         moveForward()
  65.   end
  66. end
  67.  
  68. repeat mainLoop()
  69.     repeat turnRight()
  70.         until turtle.detect() == false
  71. until turtle.detect() == true
  72.  
  73.  
  74.    
Add Comment
Please, Sign In to add comment