HeatedDZN

MFarm Setup

May 18th, 2024 (edited)
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.73 KB | None | 0 0
  1. -- Function to clear the screen
  2. function clearScreen()
  3.     term.clear()
  4.     term.setCursorPos(1, 1)
  5. end
  6.  
  7. -- Function to display the welcome screen
  8. function welcomeScreen()
  9.     clearScreen()
  10.     print("Welcome to the Automated Wheat Farm")
  11.     print("==================================")
  12.     print("MFarm by Marcus")
  13.     print("This program will help you set up")
  14.     print("and manage an automated wheat farm")
  15.     print("using ComputerCraft turtles.")
  16.     print("")
  17.     print("Press any key to continue...")
  18.     os.pullEvent("key")
  19. end
  20.  
  21. -- Function to get user input for setup
  22. function setupUI()
  23.     clearScreen()
  24.     print("Wheat Farm Setup")
  25.     print("================")
  26.     print("Instructions:")
  27.     print("1. Place the turtle over a chest.")
  28.     print("2. Ensure the chest contains the seeds of your choice in the first slot.")
  29.     print("3. Ensure the chest contains the fuel of your choice in the second slot.")
  30.     print("4. Ensure the chest contains the fully grown crop in the third slot.")
  31.     print("5. Any additional fuel can be placed in slots 4-16.")
  32.     print("")
  33.     print("Press any key to confirm and continue...")
  34.     os.pullEvent("key")
  35. end
  36.  
  37. -- Function to pick items from the chest and identify them
  38. function pickAndIdentifyItems()
  39.     clearScreen()
  40.     print("Picking items from the chest...")
  41.  
  42.     -- Pick all items from the first slot
  43.     turtle.select(1)
  44.     while turtle.suckDown() do end
  45.     local seedItem = turtle.getItemDetail(1)
  46.  
  47.     -- Pick all items from the second slot
  48.     turtle.select(2)
  49.     while turtle.suckDown() do end
  50.     local fuelItem = turtle.getItemDetail(2)
  51.  
  52.     -- Pick all items from the third slot
  53.     turtle.select(3)
  54.     while turtle.suckDown() do end
  55.     local fullyGrownItem = turtle.getItemDetail(3)
  56.  
  57.     if seedItem and fuelItem and fullyGrownItem then
  58.         print("Items identified successfully!")
  59.         print("Seed: " .. seedItem.name)
  60.         print("Fuel: " .. fuelItem.name)
  61.         print("Fully Grown Crop: " .. fullyGrownItem.name)
  62.         return seedItem.name, fuelItem.name, fullyGrownItem.name
  63.     else
  64.         print("Failed to pick items from the chest. Please check the chest setup.")
  65.         return nil, nil, nil
  66.     end
  67. end
  68.  
  69. -- Function to return items to the chest
  70. function returnItems()
  71.     for slot = 1, 16 do
  72.         turtle.select(slot)
  73.         turtle.dropDown()
  74.     end
  75. end
  76.  
  77. -- Main function
  78. function main()
  79.     welcomeScreen()
  80.     setupUI()
  81.     local seedItem, fuelItem, fullyGrownItem = pickAndIdentifyItems()
  82.     if seedItem and fuelItem and fullyGrownItem then
  83.         print("Are the identified items correct? (yes/no)")
  84.         local confirmation = string.lower(read())
  85.  
  86.         if confirmation == "yes" then
  87.             print("Setup Complete! Ready to start farming.")
  88.             local file = fs.open("farmSetup", "w")
  89.             file.writeLine(seedItem)
  90.             file.writeLine(fuelItem)
  91.             file.writeLine(fullyGrownItem)
  92.             print("Enter the size of your farm (e.g., 9 for a 9x9 farm):")
  93.             local farmSize = tonumber(read())
  94.             file.writeLine(farmSize)
  95.             print("Enter the sleep time between farming cycles (in seconds):")
  96.             local sleepTime = tonumber(read())
  97.             file.writeLine(sleepTime)
  98.             file.close()
  99.             print("Setup data saved.")
  100.             print("Fetching MFarm program...")
  101.             shell.run("pastebin get gBeY5EyD MFarm")
  102.             print("Running MFarm program...")
  103.             shell.run("MFarm")
  104.         else
  105.             print("Setup failed. Returning items to the chest.")
  106.             returnItems()
  107.         end
  108.     else
  109.         print("Setup failed. Please try again.")
  110.     end
  111. end
  112.  
  113. -- Start the setup process
  114. main()
  115.  
Add Comment
Please, Sign In to add comment