Guest User

QuarryBeta.lua

a guest
Jul 13th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.81 KB | None | 0 0
  1. monitor = peripheral.find("monitor")
  2. monitor.setCursorPos(1, 1)
  3. monitor.clear()
  4.  
  5.  
  6. -- | Directional
  7. -- | Variables
  8. -- | i.e., these variables deal with the movement of the array
  9.  
  10. mainGearshift = redstone.testBundledInput("back", colors.white) -- White
  11. xGantryProp = redstone.testBundledInput("back", colors.black) -- Black
  12. yGantryProp = redstone.testBundledInput("back", colors.brown) -- Brown
  13.  
  14. -- | Hardware
  15. -- | Variables
  16.  
  17. maxYReached = redstone.testBundledInput("back", colors.yellow) -- Yellow
  18. maxXReached = redstone.testBundledInput("back", colors.purple) -- Purple
  19. maxDepthReached = redstone.testBundledInput("back", colors.red) -- Red
  20. drillArrayReturn = redstone.testBundledInput("back", colors.green) -- Green
  21. drillLeftReturn = redstone.testBundledInput("back", colors.orange) -- Orange
  22. drillBackReturn = redstone.testBundledInput("back", colors.blue) -- Blue
  23. portableInter = redstone.testBundledInput("back", colors.gray) -- Gray
  24. clutch = redstone.testBundledInput("back", colors.magenta) -- Magenta
  25.  
  26. -- | Color
  27. -- | Variables
  28.  
  29. whiteNum = 0x1
  30. orangeNum = 0x2
  31. magentaNum = 0x4
  32. lightBlueNum = 0x8
  33. yellowNum = 0x10
  34. limeNum = 0x20
  35. pinkNum = 0x40
  36. grayNum = 0x80
  37. lightGrayNum = 0x100
  38. cyanNum = 0x200
  39. purpleNum = 0x400
  40. blueNum = 0x800
  41. brownNum = 0x1000
  42. greenNum = 0x2000
  43. redNum = 0x4000
  44. blackNum = 0x8000
  45.  
  46. time = 5 -- Time it takes the array to move by 3m in any direction
  47. --placeholder = 0
  48.  
  49. -- | Bundled Cable
  50. -- | Functions
  51.  
  52. function toggleBundledColor(side, color) -- Works
  53.     -- Toggles the inputted color at selected side
  54.     -- *Warning* This function requires colors with the -Num suffix
  55.     -- credits: https://www.computercraft.info/forums2/index.php?/topic/28112-toggle-bundled-cable-outputs/  User: Lyqyd
  56.     rs.setBundledOutput(side, (colors.test(rs.getBundledOutput(side), color) and colors.subtract(rs.getBundledOutput(side), color) or colors.combine(rs.getBundledOutput(side), color)))
  57. end
  58.  
  59. function setBundledColor(side, color, state) -- Works
  60.     -- Sets the inputted color and the inputted side to the inputted value
  61.     -- *Warning* This function requires colors with the -Num suffix
  62.     -- credits: https://www.computercraft.info/forums2/index.php?/topic/28112-toggle-bundled-cable-outputs/  User: Lyqyd
  63.     if state then
  64.         if not colors.test(rs.getBundledOutput(side), color) then
  65.             rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
  66.         end
  67.     else
  68.         if colors.test(rs.getBundledOutput(side), color) then
  69.             rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), color))
  70.         end
  71.     end
  72. end
  73.  
  74. -- | Drill Array Operation
  75. -- | Variables
  76.  
  77. function moveArrayRight() -- Works
  78.     -- Moves the drill array right.
  79.     -- Main Gearshift: 1, Main Propagation: 1
  80.     setBundledColor("back", whiteNum, true) -- Main
  81.     setBundledColor("back", blackNum, true) -- Main Propagation
  82.     setBundledColor("back", brownNum, false) -- Secondary Propagation
  83. end
  84.  
  85. function moveArrayLeft() -- Works
  86.     -- Moves the drill array left.
  87.     -- Main Propagation: 1
  88.     setBundledColor("back", whiteNum, false) -- Main
  89.     setBundledColor("back", blackNum, true) -- Main Propagation
  90.     setBundledColor("back", brownNum, false) -- Secondary Propagation
  91. end
  92.  
  93. function moveArrayForward() -- Works
  94.     -- Moves the drill array forward.
  95.     -- Main Gearshift: 1
  96.     setBundledColor("back", whiteNum, true) -- Main
  97.     setBundledColor("back", blackNum, false) -- Main Propagation
  98.     setBundledColor("back", brownNum, false) -- Secondary Propagation
  99. end
  100.  
  101. function moveArrayBack() -- Works
  102.     -- Moves the drill array backward.
  103.     -- All values 0
  104.     setBundledColor("back", whiteNum, false) -- Main
  105.     setBundledColor("back", blackNum, false) -- Main Propagation
  106.     setBundledColor("back", brownNum, false) -- Secondary Propagation
  107. end
  108.  
  109. function lowerDrill() -- Works
  110.     -- Lowers the drill array until the max depth is reached.
  111.     -- Main Propagation: 1, Secondary Propagation: 1
  112.     while not MaxDepthReached() do -- Stops once max depth is reached
  113.         setBundledColor("back", whiteNum, false) -- Main
  114.         setBundledColor("back", blackNum, true) -- Main Propagation
  115.         setBundledColor("back", brownNum, true) -- Secondary Propagation    
  116.         sleep() -- Prevents a "Too long without yield" error
  117.     end
  118.     print("Max depth reached.")
  119.    
  120.     while not DrillArrayReturn() do -- Stops once drill array has returned
  121.         raiseDrill()
  122.         sleep()
  123.     end
  124.     print("Drill array returned.")
  125.    
  126. end
  127.  
  128. function raiseDrill() -- Works
  129.     -- Raises the drill array until the drill array has been returned (using the drill return contact).
  130.     -- Main Gearshift: 1, Main Propagation: 1, Secondary Propagation: 1
  131.     print("Inside the raise drill function.")
  132.     setBundledColor("back", whiteNum, true) -- Main
  133.     setBundledColor("back", blackNum, true) -- Main Propagation
  134.     setBundledColor("back", brownNum, true) -- Secondary Propagation
  135. end
  136.  
  137. -- | Helper
  138. -- | Functions
  139. -- | Based on the recommendation of u/CommendableCalamari on Reddit
  140.  
  141. function MaxDepthReached() return redstone.testBundledInput("back", colors.red) end
  142. function DrillArrayReturn() return redstone.testBundledInput("back", colors.green) end
  143. function DrillLeftReturn() return redstone.testBundledInput("back", colors.orange) end
  144. function DrillBackReturn() return redstone.testBundledInput("back", colors.blue) end
  145. function MaxYReached() return redstone.testBundledInput("back", colors.yellow) end
  146. function MaxXReached() return redstone.testBundledInput("back", colors.purple) end
  147.  
  148. -- | Main
  149. -- | Functions
  150.  
  151. function ReturnToOrigin() -- Works
  152.     -- Returns the drill array to the origin.
  153.     while not DrillLeftReturn() do -- While the array isn't at its' max left
  154.         moveArrayLeft()
  155.         sleep()
  156.     end
  157.    
  158.     while not DrillBackReturn() do -- While the array isn' at its' max back
  159.         moveArrayBack()
  160.         sleep()
  161.     end    
  162. end
  163.  
  164. function MoveRightLogic() -- Fix
  165.     -- Moves the drill array right if possible
  166.     while true do
  167.         lowerDrill() -- Issue: Somehow, gets stuck here without raising the drill after moving forward.
  168.         print("Finished lowering the drill.")
  169.         if MaxXReached() then -- Breaks if it has reached the maximum 'X' value
  170.         -- Only does this after it has drilled, so it can drill the section near the max 'X' value
  171.             print("Max 'X' value reached.")
  172.             break
  173.         end
  174.         moveArrayRight()
  175.         sleep(time)
  176.     end
  177.    
  178.     while not DrillLeftReturn() do -- Moves the array left until it reaches the maximum left
  179.         moveArrayLeft()
  180.         sleep()
  181.     end
  182. end
  183.        
  184.        
  185. function Main() -- Untested
  186.     -- The main function
  187.    
  188.     setBundledColor("back", grayNum, true) -- Disables the portable storage interface
  189.     -- setBundledColor("back", magentaNum, true) -- Locks the clutch
  190.     sleep(2.0)
  191.     repeat
  192.         -- setBundledColor("back", magentaNum, false) -- Unlocks the clutch
  193.         print("Beginning of loop.")
  194.         MoveRightLogic() -- Issue when the array is at a 'Y' greater than 3 and is unable to raise drill
  195.         print("Finished move right logic.")
  196.         moveArrayForward()
  197.         print("Moved Array Forward.")
  198.         sleep(time) -- Timing is based on 16 RPM
  199.         print("Gone past system sleep.")
  200.     until(MaxXReached() and MaxYReached()) -- Until the array has reached max 'X' and 'Y'
  201.     -- The only reason I'm doing a repeat-until loop is that once it has actually reached boy 'X' and 'Y' max
  202.     -- It first must drill, then return to origin.
  203.     print("Broken from repeat-while loop.")
  204.  
  205.     ReturnToOrigin()      
  206.     toggleBundledColor("back", magentaNum) -- Locks the clutch
  207.     toggleBundledColor("back", grayNum) -- Enables the portable storage interface      
  208.    
  209. end
  210.  
  211. Main()
  212.  
Advertisement
Add Comment
Please, Sign In to add comment