function startfarm(funfarmargs) version = "5" term.clear() term.setCursorPos(1, 1) --print(version) done = 0 --for l=1,10 do --if fs.exists("farmapi/gt") == false then do --print("downloading goto api") --shell.run("mkdir","farmapi") --shell.run("cd","farmapi") --shell.run("pastebin","get","a3GBewNp","gt") --shell.run("cd","..") --if fs.exists("farmapi/gt") == true then --print("download complete") --elseif fs.exists("farmapi/gt") == false then --print("download failed") --end --end --else do 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) --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-- ------------------- ------------------- --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(1) farmexit = 1 end --chest() 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 function stage1() term.setCursorPos(1, 1) term.clearLine() print ("Stage: " .. done .. "/" .. totalsteps.. " Harvest and Plant") for i=1,#crop_name do success, data = turtle.inspectDown() if success then if data.state.age ~= nil then term.setCursorPos(1, 2) term.clearLine() percentagefloat = (data.state.age - 0) / (7 - 0) * 100 percentage = math.floor(percentagefloat+0.5) print("Crop Age: " .. percentage .. "%") end -- if ignore_nil_age == 1 then -- if data.state.age == nil then -- data.state.age = crop_max_age -- 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() turtle.suckDown() --term.setCursorPos(1, 3) --term.clearLine() --print("dig") end end if Mode == 1 then turtle.placeDown() end end end end function stage2() term.setCursorPos(1, 1) term.clearLine() print ("Stage: " .. done .. "/" .. totalsteps .. " Cleanup") turtle.suckDown() --print("grab") 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 stage1() turtle.forward() 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 --unused planting phase not needed because it can be done after digging elseif done == 9 then while width ~= 0 do while dist ~= 0 do turtle.placeDown() turtle.forward() print("plant") print ("Steps: " .. done) dist = dist - 1 end turn() end --end- unused planting phase end end end end end end