Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- -- About
- -- This program will take input of up to 7 different crops, farm them and then replant the seeds.
- -- Default Variables
- local dNOC = 2
- local dCrops = {wheat, carrot}
- local dCSS = 15
- local dSES = 4
- local dXPlots = 1
- local dYPlots = 1
- local defaultsLoaded = 0
- -- Shared Variables
- local sSS = 3 -- seed Start Slot
- -- Local Variables
- local nOC = 0 -- number Of Crops
- local crops = {}
- local cSS = 17 -- crop Start Slot
- local sES = sSS -- seed End Slot
- local xPlots = 1
- local yPlots = 1
- -- Functions
- function pleaseTerminate()
- print("Please terminate process by holding [Ctrl+T].")
- os.pullEvent("terminate")
- end
- function blockName(slot)
- return turtle.getItemDetail(slot).name
- end
- function cropSlots()
- cSS = cSS - nOC
- end
- function checkCS() -- Check crop slots
- -- for i = 1
- end
- function readVars()
- print("")
- print("Variables:")
- print(nOC)
- for i = 1, nOC do
- print(crops[i])
- if i == 1 then
- print(blockName(cSS))
- else
- print(blockName(cSS + i))
- end
- end
- print("")
- end
- function setup()
- print("How many different crops are there? [1-7]")
- write(">: ")
- nOC = tonumber(read())
- if tonumber(nOC) == nil or nOC == 0 or nOC > 7 then
- print("Invalid input, must be an integer.")
- print("Please terminate process by holding [Ctrl+T].")
- os.pullEvent("terminate")
- end
- print("Enter crop names.")
- for i = 1, nOC do
- write(i .. "> ")
- crops[i] = string.lower(read())
- end
- cropSlots()
- if cSS == 16 then
- print("Please add crop to slot 16.")
- else
- print("Please add one crop of each from the start of slot " .. cSS .. " to slot 16")
- print("Ensure that they are in the order they were entered as.")
- end
- print("")
- if sSS == 3 then
- print("Please add crop to slot 3.")
- else
- print("Please add one seed of each crop from the start of slot 3 to slot " .. sES)
- print("Ensure that they are in the order they were entered as.")
- end
- print("")
- print("Continue? [y/n]")
- write("> ")
- if string.lower(read()) == "n" then
- print("I Understand")
- pleaseTerminate()
- else if string.lower(read()) ~= "y" then
- print("Invalid input, y or n")
- pleaseTerminate()
- end
- print("")
- print("Setup Complete")
- print("Read off variables? [y]")
- write("> ")
- if string.lower(read()) == "y" then
- readVars()
- else
- if string.lower(read()) == "n" then
- print("I Understand")
- else
- print("Invalid input, y or n")
- pleaseTerminate()
- end
- end
- print("")
- print("Please enter how many 9x9 plots for x and y directions.")
- print("(Based on the Turtle's starting position and rotation, positive numbers only)")
- write("X> ")
- if tonumber(read()) > 0 then
- xPlots = tonumber(read())
- end
- write("Y> ")
- if tonumber(read()) > 0 then
- yPlots = tonumber(read())
- end
- end
- function loadDefaults(bypass)
- if tonumber(dNOC) == nil or dNOC == 0 or dNOC > 7 then
- print("Invalid value for dNOC, must be an integer from 1-7.")
- pleaseTerminate()
- end
- if tonumber(dCSS) == nil or dCSS ~= 16 - dNOC then
- print("Invalid value for dCSS, must be an integer that equals 17-dNOC.")
- pleaseTerminate()
- end
- if tonumber(dSES) == nil or dSES < sSS or dSES > 9 then
- print("Invalid value for dSES, must be an integer that equals 2+dNOC.")
- pleaseTerminate()
- end
- if tonumber(dXPlots) == nil or dXPlots < 1 then
- print("Invalid value for dXPlots, must be an integer greater than 1.")
- pleaseTerminate()
- end
- if tonumber(dYPlots) == nil or dYPlots < 1 then
- print("Invalid value for dYPlots, must be an integer greater than 1.")
- pleaseTerminate()
- end
- nOC = dNOC
- crops = dCrops
- cSS = dCSS
- sES = dSES
- xPlots = dXPlots
- yPlots = dYPlots
- defaultsLoaded = 1
- print("")
- print("Defaults Values Loaded")
- if bypass ~= "y" then
- print("Read off default variables? [y]")
- write("> ")
- if string.lower(read()) == "y" then
- readVars()
- else
- print("I Understand")
- end
- print("")
- print("Read default X and Y plots?")
- write("> ")
- if string.lower(read()) == "y" then
- print("")
- print("X: " .. dXPlots)
- print("Y: " .. dYPlots)
- print("")
- end
- end
- print("Run with default values? [y]")
- write("> ")
- if string.lower(read()) == "y" then
- farmMultiPlots(dXPlots, dYPlots)
- end
- end
- function compareAndFarm()
- for i = 1, nOC do
- turtle.select(cSS - 1 + i)
- if turtle.compareDown() then
- turtle.select(sSS - 1 + i)
- break
- end
- end
- turtle.digDown()
- turtle.placeDown()
- end
- function move(times)
- for i = 1, times do
- turtle.forward()
- end
- end
- function farmMove(times)
- for i = 1, times do
- compareAndFarm()
- move(1)
- end
- end
- function farmPlot()
- turtle.forward()
- for i = 1, 9 do
- farmMove(8)
- if i%2 == 0 then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- else
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- end
- end
- turtle.forward()
- end
- function nextPlot(direction)
- if direction == "R" then
- turtle.turnRight()
- move(14)
- turtle.turnRight()
- else if direction == "L" then
- turtle.turnLeft()
- move(6)
- turtle.turnLeft()
- end
- end
- function farmMultiPlots(x, y)
- if defaultsLoaded == 0 then
- print("")
- print("Please enter how many 9x9 plots for x and y directions.")
- print("(Based on the Turtle's starting position and rotation, positive numbers only)")
- write("X> ")
- if tonumber(read()) > 0 then
- xPlots = tonumber(read())
- else
- print("Invalid input, must be an integer greater than 0.")
- pleaseTerminate()
- end
- write("Y> ")
- if tonumber(read()) > 0 then
- yPlots = tonumber(read())
- else
- print("Invalid input, must be an integer greater than 0.")
- pleaseTerminate()
- end
- end
- if y == 1 then
- if x == 1 then
- farmPlot()
- -- returnHome()
- else
- for i = 1, x do
- farmPlot()
- end
- end
- else
- for i = 1, y do
- for j = 1, x do
- farmPlot()
- end
- if i ~= y then
- if i%2 == 0 then
- nextPlot(L)
- else if i%2 ~= 0 then
- nextPlot(R)
- end
- end
- end
- end
- end
- function greeting()
- print("")
- print("----------------")
- print("Welcome to Bale!")
- print("----------------")
- print("")
- print("Start! [y]")
- print("Help me! [h] | (Not implemented)")
- print("")
- write("> ")
- if string.lower(read()) == "y" then
- print("Would you like to load defaults? [y/n]")
- write("> ")
- if string.lower(read()) == "y" then
- print("Skip reading default variables? [y/n]")
- write("> ")
- if string.lower(read()) == "y" then
- loadDefaults("y")
- else
- if string.lower(read()) == "n" then
- loadDefaults()
- else
- print("Invalid input, y or n")
- pleaseTerminate()
- end
- end
- else
- if string.lower(read()) == "n" then
- setup()
- else
- print("Invalid input, y or n")
- pleaseTerminate()
- end
- end
- else
- print("Invalid input.")
- pleaseTerminate()
- end
- end
- greeting()
Add Comment
Please, Sign In to add comment