Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function startfarm(funfarmargs)
- version = "5"
- term.clear()
- term.setCursorPos(1, 1)
- --print(version)
- done = 0
- term.clear()
- term.setCursorPos(1, 1)
- os.loadAPI("AndysPrograms/api/gt")
- if fs.exists("AndysPrograms/Farm/settings") then
- settings.load("AndysPrograms/Farm/settings")
- end
- local maxW, maxH = term.getSize()
- function exit()
- term.clear()
- term.setCursorPos(1, 1)
- print("Starting")
- openset = 0
- end
- function chngset()
- chngsel = 1
- end
- function savesets()
- settings.save("AndysPrograms/Farm/settings")
- end
- gpstab = {}
- local stgpsx, stgpsy, stgpsz = gps.locate(5)
- table.insert(gpstab, stgpsx)
- table.insert(gpstab, stgpsy)
- table.insert(gpstab, stgpsz)
- table.insert(gpstab, "n")
- if fs.exists("AndysPrograms/Farm/settings") == false then
- if fs.exists("AndysPrograms/Farm") == false then
- fs.makeDir("AndysPrograms/Farm")
- end
- srtbk = {"minecraft:pumpkin", "minecraft:reeds"}
- settings.set("Farm Lenth", 1)
- settings.set("Farm Width", 1)
- settings.set("Mode", 2)
- settings.set("Start Location", gpstab)
- settings.set("Chest Location", gpstab)
- settings.set("Sort Block Names", srtbk)
- settings.set("Sort Blocks", 1)
- settings.set("Chest Direction", 0)
- savesets()
- end
- function resetmenu()
- deftab = {}
- setmenu = {}
- setmenu = {
- {text = "Finish editing:", options = "Finish", handler = exit},
- {text = "Farm Lenth", setname = "Farm Lenth", options = settings.get("Farm Lenth"), type = "num", handler = chngset},
- {text = "Farm Width", setname = "Farm Width", options = settings.get("Farm Width"), type = "num", handler = chngset},
- {text = "Mode, 1 = Nrml, 2 = Pump/Mel/SgrCne", setname = "Mode", options = settings.get("Mode"), type = "num", handler = chngset},
- {text = "Start Location", setname = "Start Location", options = settings.get("Start Location"), type = deftab, handler = chngset},
- {text = "Chest Location", setname = "Chest Location", options = settings.get("Chest Location"), type = deftab, handler = chngset},
- {text = "Chest Direction 0=fwd 2=up 1=dn", setname = "Chest Direction", options = settings.get("Chest Direction"), type = "num", handler = chngset},
- {text = "Sort Blocks", setname = "Sort Blocks", options = settings.get("Sort Blocks"), type = "num", handler = chngset},
- {text = "Sort Block Names", setname = "Sort Block Names", options = settings.get("Sort Block Names"), type = deftab, handler = chngset}
- }
- end
- resetmenu()
- function addsettings(num, value)
- settings.set(setmenu[num].setname, value)
- savesets()
- end
- openset = 1
- farmargs = funfarmargs
- if farmargs[1] == "noset" then
- openset = 0
- end
- while openset == 1 do
- if openset == 1 then
- chngsel = 0
- term.clear()
- setsoffset = 1
- selitem = 1
- --if (maxH) < (#setmenu * 2) then
- -- selitem = maxH / 2
- -- elseif (maxH) > (#setmenu) then
- --selitem = 1
- --end
- function printmenu(menu)
- for sets=1,#setmenu do
- setsmul = (sets * 2) - 1
- if (setsmul + setsoffset) <= maxH then
- term.setCursorPos(1, setsmul + setsoffset)
- print(setmenu[sets].text)
- if #setmenu[sets].text / maxW > 1 then
- --setsoffset = setsoffset + #setmenu[sets].text / maxW
- --setsoffset = setsoffset - 0.9
- end
- term.setCursorPos(1, (setsmul + 1) + setsoffset)
- if setmenu[sets].options ~= nil then
- term.clearLine()
- prntset = setmenu[sets].options
- if (type(prntset) == "table") then
- prntset = table.concat(setmenu[sets].options, ", ")
- end
- if selitem == sets then
- if chngsel == 1 then
- input = read()
- if input then
- inptesset = setmenu[sets].type
- if type(inptesset) == "table" then
- settingsinputtable = {}
- input2 = string.gsub(input, ", ", ",")
- --print(input)
- for i in string.gmatch(input2, '([^,]+)') do
- table.insert(settingsinputtable, i)
- end
- --print(input)
- addsettings(selitem, settingsinputtable)
- end
- if type(inptesset) ~= "table" then
- addsettings(selitem, input)
- end
- resetmenu()
- --print(chngsel)
- chngsel = 0
- end
- else
- print("> "..prntset)
- end
- else
- print(" "..prntset)
- end
- end
- end
- end
- end
- function onsel(menu, selected)
- menu[selected].handler()
- end
- function onkeypress(key, menu, selected)
- if key == keys.enter or key == keys.space then
- if chngsel == 0 then
- onsel(menu, selected)
- end
- -- if chngsel == 1 and (key == keys.enter or key == keys.space) then
- -- chngsel = 0
- -- end
- elseif key == keys.up or key == keys.w then
- if selitem > 1 then
- setsoffset = setsoffset + 2.1
- setsoffset = math.floor(setsoffset)
- selitem = selitem - 1
- end
- elseif key == keys.down or key == keys.s then
- if selitem < (#menu) then
- setsoffset = setsoffset - 1.9
- setsoffset = math.floor(setsoffset)
- selitem = selitem + 1
- end
- elseif key == keys.q then
- exit()
- end
- end
- while openset == 1 do
- term.setCursorPos(1, 1)
- term.clear()
- printmenu(setmenu)
- event, key = os.pullEvent("key")
- onkeypress(key, setmenu, selitem)
- end
- end
- end
- farmexit = 0
- while farmexit ~= 1 do
- ---------------------
- ---------------------
- ---------------------
- --CHANGE HERE START--
- ---------------------
- ---------------------
- ---------------------
- --"1" is Normal, "2" is Pumpkin/Melon/Probably Sugar Cane
- Mode = tonumber(settings.get(setmenu[4].setname))
- if Mode > 2 or Mode < 1 then
- Mode = 2
- end
- Farm_Lenth = tonumber(settings.get(setmenu[2].setname))
- Farm_Width = tonumber(settings.get(setmenu[3].setname))
- -- sort for specific crop
- --whether or not to sort, 1 is yes, 0 is no
- sortblock = tonumber(settings.get(setmenu[8].setname))
- if sortblock > 1 or sortblock < 0 then
- sortblock = 1
- end
- --name of the crop
- crop_name = settings.get(setmenu[9].setname)
- --max age of crop should probably be left at 7
- crop_max_age = 7
- --setup location
- setuploc = settings.get(setmenu[5].setname)
- --chest location
- chestloc = settings.get(setmenu[6].setname)
- farmsleeptime = 5
- --chest 2 = "up", 1 = "down", or 0 = "forward"
- chestdirection = tonumber(settings.get(setmenu[7].setname))
- if chestdirection > 2 or chestdirection < 0 then
- chestdirection = 2
- end
- --misc
- --ignore if a crop has no age value should be set at 1 for Pumpkin/Melon and 0 for Normal
- Override_ignore_nil_age = 0
- ignore_nil_age = 1
- override_stages = 0
- turnleftchest = 0
- totalstages = 1
- -------------------
- -------------------
- --CHANGE HERE END--
- -------------------
- -------------------
- function scrlnum(a,b,st,cl)
- if a == b then
- return a, 1
- else
- local clend = cl + st
- local cldiv = cl - clend
- local clenddiv = clend - cl
- scrlnumper = (os.clock() - cl) / clenddiv
- --local scrlnumperold = scrlnumper
- scrlnumper = scrlnumper ^ 2
- --scrlnumper = ((scrlnumper - 1) ^ 2) - 1
- --if scrlnumper < scrlnumperold then
- -- scrlnumper = scrlnumperold
- --end
- --if scrlnumper < 0 then
- -- scrlnumper = -scrlnumper
- --end
- --if scrlnumper > 1.02 and scrlnumper < 0.98 then
- -- scrlnumper = 1
- --end
- return math.floor(((scrlnumper * (b - a)) + a) + 0.1), scrlnumper
- --return ((scrlnumper * (b - a)) + a) + 0.1, scrlnumper
- end
- end
- --unused!!!! Recenter Values
- turn_right_recenter_times = 0
- forward_recenter_times = 0
- if Override_ignore_nil_age == 0 then
- if Mode == 2 then
- ignore_nil_age = 1
- elseif Mode == 1 then
- ignore_nil_age = 0
- end
- end
- st_width = Farm_Width
- lenth = Farm_Lenth
- if override_stages == 1 then
- totalsteps = totalstages
- if Mode == 2 then
- grabstage = 5
- elseif Mode == 1 then
- grabstage = 2
- end
- elseif Mode == 2 then
- if override_stages == 0 then
- grabstage = 5
- totalstages = 1
- totalsteps = 1
- end
- elseif Mode == 1 then
- if override_stages == 0 then
- grabstage = 2
- totalstages = 2
- totalsteps = 2
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("Recentering")
- totalsteps = totalstages
- endsteps = totalsteps + 1
- sub_lenth = lenth - 1
- function chest()
- term.clear()
- term.setCursorPos(1, 1)
- print("Going to Chest")
- gt.goto(chestloc)
- if Mode == 2 then
- chest = 1
- elseif Mode == 1 then
- chest = 2
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("Putting in Chest")
- while chest <= 16 do
- turtle.select(chest)
- if chestdirection == 0 then
- turtle.drop()
- elseif chestdirection == 1 then
- turtle.dropDown()
- elseif chestdirection == 2 then
- turtle.dropUp()
- end
- chest = chest + 1
- end
- if turnleftchest == 1 then
- turtle.turnLeft()
- end
- term.clear()
- term.setCursorPos(1, 1)
- --print("Resetting")
- sleep(farmsleeptime)
- farmexit = 1
- end
- function turn()
- if width >= 2 then
- if right == 1 then
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- dist = sub_lenth
- width = width - 1
- right = 0
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- dist = sub_lenth
- width = width - 1
- right = 1
- end
- elseif width < 2 then
- dist = sub_lenth
- width = width - 1
- if width <= 0 then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- end
- end
- function recenter()
- working_turn_right_recenter_times = turn_right_recenter_times
- working_forward_recenter_times = forward_recenter_times
- gt.goto(setuploc)
- if turn_right_recenter_times ~= 0 then
- while working_turn_right_recenter_times ~= 0 do
- turtle.turnRight()
- working_turn_right_recenter_times = working_turn_right_recenter_times - 1
- end
- end
- right = 1
- turtle.select(1)
- dist = lenth - 1
- if forward_recenter_times ~= 0 then
- while working_forward_recenter_times ~= 0 do
- turtle.forward()
- working_forward_recenter_times = working_forward_recenter_times - 1
- end
- end
- end
- if percentageold == nil then
- percentageold = 0
- end
- if dopnt == nil then
- dopnt = 1
- end
- if tnstm == nil then
- tnstm = 0.01
- end
- if scagtm == nil then
- scagtm = 0.01
- end
- function stage1()
- ttmst = os.clock()
- term.setCursorPos(1, 1)
- term.clearLine()
- if totalstages <= 1 then
- print ("Stage: " .. done .. "/" .. totalsteps.. " Harvest")
- elseif totalstages >= 2 then
- print ("Stage: " .. done .. "/" .. totalsteps.. " Harvest and Plant")
- end
- for i=1,#crop_name do
- success, data = turtle.inspectDown()
- if success then
- if dopnt == 6 then
- if data.state.age ~= nil then
- scnmpnt = 0
- dlprns1 = 0
- percentagefloat = (data.state.age - 0) / (7 - 0) * 100
- percentage = math.floor(percentagefloat+0.5)
- scnmtmst = os.clock()
- scagl = 0
- while dlprns1 < 1 do
- scagtmst = os.clock()
- scnmpnt, dlprns1 = scrlnum(percentageold,percentage,tnstm,scnmtmst)
- if dlprns1 == nil then
- dlprns1 = 0
- end
- term.setCursorPos(1, 2)
- term.clearLine()
- print("Crop Age: " .. scnmpnt .. "%")
- --term.setCursorPos(1, 4)
- --term.clearLine()
- --if dlprns1 ~= nil then
- --print("" .. dlprns1 .. "")
- --end
- --term.setCursorPos(1, 6)
- --term.clearLine()
- --print("" .. percentageold .. "")
- if scagl > 25 then
- sleep()
- scagl = 0
- end
- scagl = scagl + 1
- scagtmen = os.clock()
- scagtm = scagtmen - scagtmst
- end
- percentageold = percentage
- end
- end
- if (data.name == crop_name[i]) or (sortblock == 0) then
- if data.state.age == crop_max_age or ignore_nil_age == 1 then
- --print("Age Check 2: " .. data.state.age)
- turtle.digDown()
- --term.setCursorPos(1, 3)
- --term.clearLine()
- --print("dig")
- end
- end
- turtle.suckDown()
- if Mode == 1 then
- turtle.placeDown()
- end
- end
- end
- ttmen = os.clock()
- tnstm = ttmen - ttmst
- tnstm = tnstm - scagtm
- tnstm = tnstm / 2
- if tnstm < 0 then
- tnstm = 0.02
- end
- end
- function scrlage()
- for i=1,#crop_name do
- success, data = turtle.inspectDown()
- if success then
- if dopnt == 1 then
- if data.state.age ~= nil then
- scnmpnt = 0
- dlprns1 = 0
- percentagefloat = (data.state.age - 0) / (7 - 0) * 100
- percentage = math.floor(percentagefloat+0.5)
- scnmtmst = os.clock()
- while dlprns1 < 1 do
- scnmpnt, dlprns1 = scrlnum(percentageold,percentage,0.5,scnmtmst)
- if dlprns1 == nil then
- dlprns1 = 0
- end
- term.setCursorPos(1, 2)
- term.clearLine()
- print("Crop Age: " .. scnmpnt .. "%")
- --term.setCursorPos(1, 4)
- --term.clearLine()
- --if dlprns1 ~= nil then
- --print("" .. dlprns1 .. "")
- --end
- --term.setCursorPos(1, 6)
- --term.clearLine()
- --print("" .. percentageold .. "")
- sleep()
- end
- percentageold = percentage
- end
- end
- end
- end
- end
- function stage2()
- term.setCursorPos(1, 1)
- term.clearLine()
- print ("Stage: " .. done .. "/" .. totalsteps .. " Cleanup")
- turtle.suckDown()
- --print("grab")
- end
- function stg1tg()
- if dist ~= 0 then
- if done == 1 then
- term.clear()
- while width ~= 0 do
- while dist ~= 0 do
- dopnt = 1
- parallel.waitForAll(stage1,scrlage)
- --stage1()
- dopnt = 1
- turtle.forward()
- --parallel.waitForAll(stage1,scrlage)
- stage1()
- --print(dist)
- dist = dist - 1
- end
- turn()
- end
- end
- end
- end
- if width == 0 or width == nil then
- done = done + 1
- --print ("add")
- --print ("Steps: " .. done)
- if done == endsteps then
- chest()
- done = 0
- farmexit = 1
- end
- width = st_width
- --print("width: " .. width)
- if farmexit ~= 1 then
- recenter()
- end
- elseif width ~= 0 then
- if dist ~= 0 then
- if done == 1 then
- term.clear()
- while width ~= 0 do
- while dist ~= 0 do
- dopnt = 1
- parallel.waitForAll(stage1,scrlage)
- --stage1()
- dopnt = 1
- turtle.forward()
- parallel.waitForAll(stage1,scrlage)
- --stage1()
- --print(dist)
- dist = dist - 1
- end
- turn()
- end
- elseif done == grabstage then
- term.clear()
- while width ~= 0 do
- while dist ~= 0 do
- stage2()
- turtle.forward()
- stage2()
- dist = dist - 1
- end
- turn()
- end
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment