Advertisement
ImmoralKoala

CC_Create_CocoaBeanFarm

Jan 28th, 2022 (edited)
605
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. xPos = 0
  2. yPos = 0
  3.  
  4. xSize = 0
  5. ySize = 0
  6.  
  7. speed = 0
  8.  
  9. function resetOutputs()
  10.     redstone.setOutput("left", false) -- Direction
  11.     redstone.setOutput("right", false) -- Inversion
  12.     redstone.setOutput("back", false) -- Brake
  13. end
  14.  
  15. function invertMovement(invert)
  16.     if not invert then
  17.         redstone.setOutput("right", false)
  18.     else
  19.         redstone.setOutput("right", true)
  20.     end
  21. end
  22.  
  23. function goToPosition(xTarget, yTarget)
  24.     local xDistance = xTarget - xPos
  25.     local yDistance = yTarget - yPos
  26.     local time = 0
  27.  
  28.     resetOutputs()
  29.  
  30.     print("Moving to Position...")
  31.  
  32.     print("Distances XY: " .. xDistance .. " " .. yDistance)
  33.  
  34.     if xDistance ~= 0 then
  35.         if xDistance < 0 then
  36.             invertMovement(true) -- Invert Movement
  37.         else
  38.             invertMovement(false)
  39.         end
  40.  
  41.         redstone.setOutput("back", true) -- Start Movement
  42.         time = math.abs(xDistance / speed)
  43.         os.sleep(time)
  44.         redstone.setOutput("back", false)
  45.         xPos = xTarget
  46.     end
  47.  
  48.     if yDistance ~= 0 then
  49.         if yDistance < 0 then
  50.             invertMovement(true) -- Invert Movement
  51.         else
  52.             invertMovement(false)
  53.         end
  54.  
  55.         redstone.setOutput("left", true)
  56.         redstone.setOutput("back", true)
  57.         time = math.abs(yDistance / speed)
  58.         os.sleep(time)
  59.         redstone.setOutput("back", false)
  60.         yPos = yTarget
  61.     end
  62.  
  63.     resetOutputs()
  64. end
  65.  
  66. function farm()
  67.     for x = 0, (xSize - 1), 1 do
  68.         os.sleep(1.5)
  69.         goToPosition(x, ySize)
  70.         goToPosition(x, 0)
  71.     end
  72. end
  73.  
  74. function calibrate()
  75.     resetOutputs()
  76.  
  77.     redstone.setOutput("back", true)
  78.  
  79.     while true do
  80.         os.sleep(1 / speed)
  81.  
  82.         if(redstone.getInput("top")) then
  83.             redstone.setOutput("back", false)
  84.             break
  85.         end
  86.  
  87.         xSize = xSize + 1
  88.         xPos = xPos + 1
  89.     end
  90.  
  91.     redstone.setOutput("left", true)
  92.     redstone.setOutput("back", true)
  93.  
  94.     while true do
  95.         os.sleep(1 / speed)
  96.         if(redstone.getInput("top")) then
  97.             redstone.setOutput("back", false)
  98.             break
  99.         end
  100.  
  101.         ySize = ySize + 1
  102.         yPos = yPos + 1
  103.     end
  104.  
  105.     goToPosition(0, 0)
  106.  
  107.     resetOutputs()
  108. end
  109.  
  110. function init()
  111.     term.clear()
  112.     io.write("Input RPM: ")
  113.     rpm = tonumber(read()) -- Save current RPM, used for calculating travel time.
  114.     speed = 0.0385 * rpm
  115.  
  116. end
  117.  
  118. init()
  119. calibrate()
  120.  
  121. while true do
  122.     term.clear()
  123.     print("Current Position XY: " .. xPos .. " " .. yPos)
  124.     farm()
  125.     goToPosition(0, 0)
  126.     os.sleep(1)
  127.     resetOutputs()
  128. end
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement