JadedPaster

Bale

Feb 16th, 2025 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.88 KB | None | 0 0
  1. term.clear()
  2.  
  3. -- About
  4.  
  5. -- This program will take input of up to 7 different crops, farm them and then replant the seeds.
  6.  
  7.  
  8. -- Default Variables
  9.  
  10. local dNOC = 2
  11. local dCrops = {wheat, carrot}
  12. local dCSS = 15
  13. local dSES = 4
  14. local dXPlots = 1
  15. local dYPlots = 1
  16. local defaultsLoaded = 0
  17.  
  18. -- Shared Variables
  19. local sSS = 3 -- seed Start Slot
  20.  
  21. -- Local Variables
  22.  
  23. local nOC = 0 -- number Of Crops
  24. local crops = {}
  25. local cSS = 17 -- crop Start Slot
  26. local sES = sSS -- seed End Slot
  27. local xPlots = 1
  28. local yPlots = 1
  29.  
  30.  
  31. -- Functions
  32.  
  33. function pleaseTerminate()
  34.     print("Please terminate process by holding [Ctrl+T].")
  35.     os.pullEvent("terminate")
  36. end
  37.  
  38. function blockName(slot)
  39.     return turtle.getItemDetail(slot).name
  40. end
  41.  
  42. function cropSlots()
  43.     cSS = cSS - nOC
  44. end
  45.  
  46. function checkCS() -- Check crop slots
  47.     -- for i = 1
  48. end
  49.  
  50. function readVars()
  51.     print("")
  52.     print("Variables:")
  53.     print(nOC)
  54.     for i = 1, nOC do
  55.         print(crops[i])
  56.         if i == 1 then
  57.             print(blockName(cSS))
  58.         else
  59.             print(blockName(cSS + i))
  60.         end
  61.     end
  62.     print("")
  63. end
  64.  
  65. function setup()
  66.     print("How many different crops are there? [1-7]")
  67.     write(">: ")
  68.     nOC = tonumber(read())
  69.     if tonumber(nOC) == nil or nOC == 0 or nOC > 7 then
  70.         print("Invalid input, must be an integer.")
  71.         print("Please terminate process by holding [Ctrl+T].")
  72.         os.pullEvent("terminate")
  73.     end
  74.     print("Enter crop names.")
  75.    
  76.     for i = 1, nOC do
  77.         write(i .. "> ")
  78.         crops[i] = string.lower(read())
  79.     end
  80.  
  81.     cropSlots()
  82.    
  83.     if cSS == 16 then
  84.         print("Please add crop to slot 16.")
  85.     else
  86.         print("Please add one crop of each from the start of slot " .. cSS .. " to slot 16")
  87.         print("Ensure that they are in the order they were entered as.")
  88.     end
  89.  
  90.     print("")
  91.    
  92.     if sSS == 3 then
  93.         print("Please add crop to slot 3.")
  94.     else
  95.         print("Please add one seed of each crop from the start of slot 3 to slot " .. sES)
  96.         print("Ensure that they are in the order they were entered as.")
  97.     end
  98.    
  99.     print("")
  100.     print("Continue? [y/n]")
  101.     write("> ")
  102.     if string.lower(read()) == "n" then
  103.         print("I Understand")
  104.         pleaseTerminate()
  105.     else if string.lower(read()) ~= "y" then
  106.         print("Invalid input, y or n")
  107.         pleaseTerminate()
  108.     end
  109.    
  110.     print("")
  111.     print("Setup Complete")
  112.     print("Read off variables? [y]")
  113.     write("> ")
  114.     if string.lower(read()) == "y" then
  115.         readVars()
  116.     else
  117.         if string.lower(read()) == "n" then
  118.             print("I Understand")
  119.         else
  120.             print("Invalid input, y or n")
  121.             pleaseTerminate()
  122.         end
  123.     end
  124.     print("")
  125.     print("Please enter how many 9x9 plots for x and y directions.")
  126.     print("(Based on the Turtle's starting position and rotation, positive numbers only)")
  127.     write("X> ")
  128.     if tonumber(read()) > 0 then
  129.         xPlots = tonumber(read())
  130.     end
  131.     write("Y> ")
  132.     if tonumber(read()) > 0 then
  133.         yPlots = tonumber(read())
  134.     end
  135. end
  136.  
  137. function loadDefaults(bypass)
  138.     if tonumber(dNOC) == nil or dNOC == 0 or dNOC > 7 then
  139.         print("Invalid value for dNOC, must be an integer from 1-7.")
  140.         pleaseTerminate()
  141.     end
  142.  
  143.     if tonumber(dCSS) == nil or dCSS ~= 16 - dNOC then
  144.         print("Invalid value for dCSS, must be an integer that equals 17-dNOC.")
  145.         pleaseTerminate()
  146.     end
  147.    
  148.     if tonumber(dSES) == nil or dSES < sSS or dSES > 9 then
  149.         print("Invalid value for dSES, must be an integer that equals 2+dNOC.")
  150.         pleaseTerminate()
  151.     end
  152.  
  153.     if tonumber(dXPlots) == nil or dXPlots < 1 then
  154.         print("Invalid value for dXPlots, must be an integer greater than 1.")
  155.         pleaseTerminate()
  156.     end
  157.  
  158.     if tonumber(dYPlots) == nil or dYPlots < 1 then
  159.         print("Invalid value for dYPlots, must be an integer greater than 1.")
  160.         pleaseTerminate()
  161.     end
  162.  
  163.     nOC = dNOC
  164.     crops = dCrops
  165.     cSS = dCSS
  166.     sES = dSES
  167.     xPlots = dXPlots
  168.     yPlots = dYPlots
  169.     defaultsLoaded = 1
  170.  
  171.     print("")
  172.     print("Defaults Values Loaded")
  173.  
  174.     if bypass ~= "y" then
  175.         print("Read off default variables? [y]")
  176.         write("> ")
  177.         if string.lower(read()) == "y" then
  178.             readVars()
  179.         else
  180.             print("I Understand")
  181.         end
  182.  
  183.         print("")
  184.         print("Read default X and Y plots?")
  185.         write("> ")
  186.         if string.lower(read()) == "y" then
  187.             print("")
  188.             print("X: " .. dXPlots)
  189.             print("Y: " .. dYPlots)
  190.             print("")
  191.         end
  192.     end
  193.    
  194.     print("Run with default values? [y]")
  195.     write("> ")
  196.     if string.lower(read()) == "y" then
  197.         farmMultiPlots(dXPlots, dYPlots)
  198.     end
  199. end
  200.  
  201. function compareAndFarm()
  202.     for i = 1, nOC do
  203.         turtle.select(cSS - 1 + i)
  204.         if turtle.compareDown() then
  205.             turtle.select(sSS - 1 + i)
  206.             break
  207.         end
  208.     end
  209.  
  210.     turtle.digDown()
  211.     turtle.placeDown()
  212. end
  213.  
  214. function move(times)
  215.     for i = 1, times do
  216.         turtle.forward()
  217.     end
  218. end
  219.  
  220. function farmMove(times)
  221.     for i = 1, times do
  222.         compareAndFarm()       
  223.         move(1)
  224.     end
  225. end
  226.  
  227. function farmPlot()
  228.     turtle.forward()
  229.     for i = 1, 9 do
  230.         farmMove(8)
  231.         if i%2 == 0 then
  232.             turtle.turnLeft()
  233.             turtle.forward()
  234.             turtle.turnLeft()
  235.         else
  236.             turtle.turnRight()
  237.             turtle.forward()
  238.             turtle.turnRight()
  239.         end
  240.     end
  241.     turtle.forward()
  242. end
  243.  
  244. function nextPlot(direction)
  245.     if direction == "R" then
  246.         turtle.turnRight()
  247.         move(14)
  248.         turtle.turnRight()
  249.     else if direction == "L" then
  250.         turtle.turnLeft()
  251.         move(6)
  252.         turtle.turnLeft()
  253.     end
  254. end
  255.  
  256. function farmMultiPlots(x, y)
  257.     if defaultsLoaded == 0 then
  258.         print("")
  259.         print("Please enter how many 9x9 plots for x and y directions.")
  260.         print("(Based on the Turtle's starting position and rotation, positive numbers only)")
  261.         write("X> ")
  262.         if tonumber(read()) > 0 then
  263.             xPlots = tonumber(read())
  264.         else
  265.             print("Invalid input, must be an integer greater than 0.")
  266.             pleaseTerminate()
  267.         end
  268.  
  269.         write("Y> ")
  270.         if tonumber(read()) > 0 then
  271.             yPlots = tonumber(read())
  272.         else
  273.             print("Invalid input, must be an integer greater than 0.")
  274.             pleaseTerminate()
  275.         end
  276.     end
  277.  
  278.     if y == 1 then
  279.         if x == 1 then
  280.             farmPlot()
  281.             -- returnHome()
  282.         else
  283.             for i = 1, x do
  284.                 farmPlot()
  285.             end
  286.         end
  287.     else
  288.         for i = 1, y do
  289.             for j = 1, x do
  290.                 farmPlot()
  291.             end
  292.            
  293.             if i ~= y then
  294.                 if i%2 == 0 then
  295.                     nextPlot(L)
  296.                 else if i%2 ~= 0 then
  297.                     nextPlot(R)
  298.                 end
  299.             end
  300.         end
  301.     end
  302. end
  303.  
  304. function greeting()
  305.     print("")
  306.     print("----------------")
  307.     print("Welcome to Bale!")
  308.     print("----------------")
  309.     print("")
  310.     print("Start! [y]")
  311.     print("Help me! [h] | (Not implemented)")
  312.     print("")
  313.     write("> ")
  314.     if string.lower(read()) == "y" then
  315.         print("Would you like to load defaults? [y/n]")
  316.         write("> ")
  317.         if string.lower(read()) == "y" then
  318.             print("Skip reading default variables? [y/n]")
  319.             write("> ")
  320.             if string.lower(read()) == "y" then
  321.                 loadDefaults("y")
  322.             else
  323.                 if string.lower(read()) == "n" then
  324.                     loadDefaults()
  325.                 else
  326.                     print("Invalid input, y or n")
  327.                     pleaseTerminate()
  328.                 end
  329.             end
  330.         else
  331.             if string.lower(read()) == "n" then
  332.                 setup()
  333.             else
  334.                 print("Invalid input, y or n")
  335.                 pleaseTerminate()
  336.             end
  337.         end
  338.     else
  339.         print("Invalid input.")
  340.         pleaseTerminate()
  341.     end
  342. end
  343.  
  344. greeting()
Add Comment
Please, Sign In to add comment