SHOW:
|
|
- or go back to the newest paste.
| 1 | function startfarm(funfarmargs) | |
| 2 | - | version = "5" |
| 2 | + | while _G.andy_farm_program_running == 1 do |
| 3 | - | term.clear() |
| 3 | + | local setmenu = _G.setmenu |
| 4 | - | term.setCursorPos(1, 1) |
| 4 | + | --print(table.concat(setmenu,", ")) |
| 5 | - | --print(version) |
| 5 | + | --print(tostring(setmenu)) |
| 6 | - | done = 0 |
| 6 | + | version = "5" |
| 7 | --term.clear() | |
| 8 | - | term.clear() |
| 8 | + | --term.setCursorPos(1, 1) |
| 9 | - | term.setCursorPos(1, 1) |
| 9 | + | --print(version) |
| 10 | - | |
| 10 | + | |
| 11 | - | os.loadAPI("AndysPrograms/api/gt")
|
| 11 | + | local farm_prog_progress = "init" |
| 12 | farm_prog_progress = 0 | |
| 13 | farm_prog_progress = farm_prog_progress + 1 | |
| 14 | farmapiloadedguilib = 0 | |
| 15 | --term.clear() | |
| 16 | - | if fs.exists("AndysPrograms/Farm/settings") then
|
| 16 | + | --term.setCursorPos(1, 1) |
| 17 | - | settings.load("AndysPrograms/Farm/settings")
|
| 17 | + | |
| 18 | - | end |
| 18 | + | os.loadAPI("AndysPrograms/api/gt")
|
| 19 | - | local maxW, maxH = term.getSize() |
| 19 | + | while farmapiloadedguilib ~= 1 do |
| 20 | if os.loadAPI("AndysPrograms/api/gui/gui") then
| |
| 21 | --print("loaded gui farmapi lib")
| |
| 22 | farmapiloadedguilib = 1 | |
| 23 | - | function exit() |
| 23 | + | else |
| 24 | - | term.clear() |
| 24 | + | print(" NOTloaded gui lib")
|
| 25 | - | term.setCursorPos(1, 1) |
| 25 | + | |
| 26 | - | print("Starting")
|
| 26 | + | |
| 27 | - | openset = 0 |
| 27 | + | |
| 28 | - | end |
| 28 | + | local setmenu = gui.get_setmenu() |
| 29 | - | function chngset() |
| 29 | + | --andy_farm_program_running = 0 |
| 30 | - | chngsel = 1 |
| 30 | + | |
| 31 | - | end |
| 31 | + | if fs.exists("AndysPrograms/Farm/settings") then
|
| 32 | settings.load("AndysPrograms/Farm/settings")
| |
| 33 | - | function savesets() |
| 33 | + | |
| 34 | - | settings.save("AndysPrograms/Farm/settings")
|
| 34 | + | local maxW, maxH = term.getSize() |
| 35 | - | end |
| 35 | + | |
| 36 | - | gpstab = {}
|
| 36 | + | farmexit = 0 |
| 37 | - | local stgpsx, stgpsy, stgpsz = gps.locate(5) |
| 37 | + | while farmexit ~= 1 do |
| 38 | - | table.insert(gpstab, stgpsx) |
| 38 | + | |
| 39 | - | table.insert(gpstab, stgpsy) |
| 39 | + | local setmenu = _G.setmenu |
| 40 | - | table.insert(gpstab, stgpsz) |
| 40 | + | |
| 41 | - | table.insert(gpstab, "n") |
| 41 | + | |
| 42 | - | if fs.exists("AndysPrograms/Farm/settings") == false then
|
| 42 | + | |
| 43 | - | if fs.exists("AndysPrograms/Farm") == false then
|
| 43 | + | |
| 44 | - | fs.makeDir("AndysPrograms/Farm")
|
| 44 | + | -- setmenu = {
|
| 45 | -- {options = "Finish editing", handler = mainmenu_farm},
| |
| 46 | -- {text = "Farm Lenth", setname = "Farm Lenth", options = settings.get("Farm Lenth"), type = "num", handler = chngset},
| |
| 47 | -- {text = "Farm Width", setname = "Farm Width", options = settings.get("Farm Width"), type = "num", handler = chngset},
| |
| 48 | -- {text = "Mode, 1 = Nrml, 2 = Pump/Mel/SgrCne", setname = "Mode", options = settings.get("Mode"), type = "num", handler = chngset},
| |
| 49 | -- {text = "Start Location", setname = "Start Location", options = settings.get("Start Location"), type = deftab, handler = chngset},
| |
| 50 | - | srtbk = {"minecraft:pumpkin", "minecraft:reeds"}
|
| 50 | + | -- {text = "Chest Location", setname = "Chest Location", options = settings.get("Chest Location"), type = deftab, handler = chngset},
|
| 51 | - | settings.set("Farm Lenth", 1)
|
| 51 | + | -- {text = "Chest Direction 0=fwd 2=up 1=dn", setname = "Chest Direction", options = settings.get("Chest Direction"), type = "num", handler = chngset},
|
| 52 | - | settings.set("Farm Width", 1)
|
| 52 | + | -- {text = "Sort Blocks", setname = "Sort Blocks", options = settings.get("Sort Blocks"), type = "num", handler = chngset},
|
| 53 | - | settings.set("Mode", 2)
|
| 53 | + | -- {text = "Sort Block Names", setname = "Sort Block Names", options = settings.get("Sort Block Names"), type = deftab, handler = chngset}
|
| 54 | - | settings.set("Start Location", gpstab)
|
| 54 | + | -- } |
| 55 | - | settings.set("Chest Location", gpstab)
|
| 55 | + | --------------------- |
| 56 | - | settings.set("Sort Block Names", srtbk)
|
| 56 | + | --------------------- |
| 57 | - | settings.set("Sort Blocks", 1)
|
| 57 | + | --------------------- |
| 58 | - | settings.set("Chest Direction", 0)
|
| 58 | + | --CHANGE HERE START-- |
| 59 | - | savesets() |
| 59 | + | --------------------- |
| 60 | - | |
| 60 | + | --------------------- |
| 61 | - | |
| 61 | + | --------------------- |
| 62 | - | |
| 62 | + | |
| 63 | - | end |
| 63 | + | |
| 64 | - | function resetmenu() |
| 64 | + | |
| 65 | - | deftab = {}
|
| 65 | + | |
| 66 | - | setmenu = {}
|
| 66 | + | |
| 67 | - | setmenu = {
|
| 67 | + | |
| 68 | - | {text = "Finish editing:", options = "Finish", handler = exit},
|
| 68 | + | |
| 69 | - | {text = "Farm Lenth", setname = "Farm Lenth", options = settings.get("Farm Lenth"), type = "num", handler = chngset},
|
| 69 | + | --"1" is Normal, "2" is Pumpkin/Melon/Probably Sugar Cane |
| 70 | - | {text = "Farm Width", setname = "Farm Width", options = settings.get("Farm Width"), type = "num", handler = chngset},
|
| 70 | + | farm_prog_progress = farm_prog_progress + 1 |
| 71 | - | {text = "Mode, 1 = Nrml, 2 = Pump/Mel/SgrCne", setname = "Mode", options = settings.get("Mode"), type = "num", handler = chngset},
|
| 71 | + | Mode = tonumber(settings.get(setmenu[4].setname)) |
| 72 | - | {text = "Start Location", setname = "Start Location", options = settings.get("Start Location"), type = deftab, handler = chngset},
|
| 72 | + | |
| 73 | - | {text = "Chest Location", setname = "Chest Location", options = settings.get("Chest Location"), type = deftab, handler = chngset},
|
| 73 | + | if Mode > 2 or Mode < 1 then |
| 74 | - | {text = "Chest Direction 0=fwd 2=up 1=dn", setname = "Chest Direction", options = settings.get("Chest Direction"), type = "num", handler = chngset},
|
| 74 | + | Mode = 2 |
| 75 | - | {text = "Sort Blocks", setname = "Sort Blocks", options = settings.get("Sort Blocks"), type = "num", handler = chngset},
|
| 75 | + | |
| 76 | - | {text = "Sort Block Names", setname = "Sort Block Names", options = settings.get("Sort Block Names"), type = deftab, handler = chngset}
|
| 76 | + | |
| 77 | - | } |
| 77 | + | |
| 78 | Farm_Lenth = tonumber(settings.get(setmenu[2].setname)) | |
| 79 | - | end |
| 79 | + | Farm_Width = tonumber(settings.get(setmenu[3].setname)) |
| 80 | - | resetmenu() |
| 80 | + | |
| 81 | ||
| 82 | - | function addsettings(num, value) |
| 82 | + | |
| 83 | - | settings.set(setmenu[num].setname, value) |
| 83 | + | |
| 84 | - | savesets() |
| 84 | + | -- sort for specific crop |
| 85 | - | end |
| 85 | + | |
| 86 | --whether or not to sort, 1 is yes, 0 is no | |
| 87 | - | openset = 1 |
| 87 | + | sortblock = tonumber(settings.get(setmenu[8].setname)) |
| 88 | if sortblock > 1 or sortblock < 0 then | |
| 89 | - | farmargs = funfarmargs |
| 89 | + | sortblock = 1 |
| 90 | - | if farmargs[1] == "noset" then |
| 90 | + | |
| 91 | - | openset = 0 |
| 91 | + | |
| 92 | - | end |
| 92 | + | --name of the crop |
| 93 | crop_name = settings.get(setmenu[9].setname) | |
| 94 | - | while openset == 1 do |
| 94 | + | |
| 95 | --max age of crop should probably be left at 7 | |
| 96 | crop_max_age = 7 | |
| 97 | ||
| 98 | ||
| 99 | - | if openset == 1 then |
| 99 | + | |
| 100 | - | chngsel = 0 |
| 100 | + | --setup location |
| 101 | - | term.clear() |
| 101 | + | setuploc = settings.get(setmenu[5].setname) |
| 102 | - | setsoffset = 1 |
| 102 | + | |
| 103 | - | selitem = 1 |
| 103 | + | |
| 104 | - | --if (maxH) < (#setmenu * 2) then |
| 104 | + | |
| 105 | - | -- selitem = maxH / 2 |
| 105 | + | --chest location |
| 106 | - | -- elseif (maxH) > (#setmenu) then |
| 106 | + | chestloc = settings.get(setmenu[6].setname) |
| 107 | - | --selitem = 1 |
| 107 | + | |
| 108 | - | --end |
| 108 | + | farmsleeptime = 0 |
| 109 | - | function printmenu(menu) |
| 109 | + | |
| 110 | - | for sets=1,#setmenu do |
| 110 | + | --chest 2 = "up", 1 = "down", or 0 = "forward" |
| 111 | chestdirection = tonumber(settings.get(setmenu[7].setname)) | |
| 112 | - | setsmul = (sets * 2) - 1 |
| 112 | + | |
| 113 | - | if (setsmul + setsoffset) <= maxH then |
| 113 | + | if chestdirection > 2 or chestdirection < 0 then |
| 114 | - | term.setCursorPos(1, setsmul + setsoffset) |
| 114 | + | chestdirection = 2 |
| 115 | - | print(setmenu[sets].text) |
| 115 | + | |
| 116 | - | if #setmenu[sets].text / maxW > 1 then |
| 116 | + | --misc |
| 117 | - | --setsoffset = setsoffset + #setmenu[sets].text / maxW |
| 117 | + | |
| 118 | - | --setsoffset = setsoffset - 0.9 |
| 118 | + | --ignore if a crop has no age value should be set at 1 for Pumpkin/Melon and 0 for Normal |
| 119 | Override_ignore_nil_age = 0 | |
| 120 | - | term.setCursorPos(1, (setsmul + 1) + setsoffset) |
| 120 | + | ignore_nil_age = 1 |
| 121 | - | if setmenu[sets].options ~= nil then |
| 121 | + | |
| 122 | - | term.clearLine() |
| 122 | + | override_stages = 0 |
| 123 | - | prntset = setmenu[sets].options |
| 123 | + | turnleftchest = 0 |
| 124 | - | if (type(prntset) == "table") then |
| 124 | + | totalstages = 1 |
| 125 | - | prntset = table.concat(setmenu[sets].options, ", ") |
| 125 | + | ------------------- |
| 126 | ------------------- | |
| 127 | - | if selitem == sets then |
| 127 | + | --CHANGE HERE END-- |
| 128 | - | if chngsel == 1 then |
| 128 | + | ------------------- |
| 129 | - | input = read() |
| 129 | + | ------------------- |
| 130 | - | if input then |
| 130 | + | |
| 131 | - | inptesset = setmenu[sets].type |
| 131 | + | |
| 132 | - | if type(inptesset) == "table" then |
| 132 | + | |
| 133 | - | settingsinputtable = {}
|
| 133 | + | |
| 134 | - | input2 = string.gsub(input, ", ", ",") |
| 134 | + | |
| 135 | - | --print(input) |
| 135 | + | |
| 136 | - | for i in string.gmatch(input2, '([^,]+)') do |
| 136 | + | |
| 137 | - | table.insert(settingsinputtable, i) |
| 137 | + | |
| 138 | - | end |
| 138 | + | |
| 139 | - | --print(input) |
| 139 | + | |
| 140 | - | addsettings(selitem, settingsinputtable) |
| 140 | + | |
| 141 | ||
| 142 | - | if type(inptesset) ~= "table" then |
| 142 | + | |
| 143 | - | addsettings(selitem, input) |
| 143 | + | |
| 144 | ||
| 145 | - | resetmenu() |
| 145 | + | |
| 146 | - | --print(chngsel) |
| 146 | + | farm_prog_progress = farm_prog_progress + 1 |
| 147 | - | chngsel = 0 |
| 147 | + | |
| 148 | ||
| 149 | ||
| 150 | - | else |
| 150 | + | function scrlnum(a,b,st,cl) |
| 151 | - | print("> "..prntset)
|
| 151 | + | if a == b then |
| 152 | return a, 1 | |
| 153 | else | |
| 154 | - | print(" "..prntset)
|
| 154 | + | local clend = cl + st |
| 155 | local cldiv = cl - clend | |
| 156 | local clenddiv = clend - cl | |
| 157 | scrlnumper = (os.clock() - cl) / clenddiv | |
| 158 | --local scrlnumperold = scrlnumper | |
| 159 | - | end |
| 159 | + | scrlnumper = scrlnumper ^ 2 |
| 160 | - | function onsel(menu, selected) |
| 160 | + | --scrlnumper = ((scrlnumper - 1) ^ 2) - 1 |
| 161 | - | menu[selected].handler() |
| 161 | + | --if scrlnumper < scrlnumperold then |
| 162 | -- scrlnumper = scrlnumperold | |
| 163 | --end | |
| 164 | - | function onkeypress(key, menu, selected) |
| 164 | + | --if scrlnumper < 0 then |
| 165 | - | if key == keys.enter or key == keys.space then |
| 165 | + | -- scrlnumper = -scrlnumper |
| 166 | - | if chngsel == 0 then |
| 166 | + | --end |
| 167 | - | onsel(menu, selected) |
| 167 | + | --if scrlnumper > 1.02 and scrlnumper < 0.98 then |
| 168 | -- scrlnumper = 1 | |
| 169 | - | -- if chngsel == 1 and (key == keys.enter or key == keys.space) then |
| 169 | + | --end |
| 170 | - | -- chngsel = 0 |
| 170 | + | |
| 171 | - | -- end |
| 171 | + | return math.floor(((scrlnumper * (b - a)) + a) + 0.1), scrlnumper |
| 172 | - | elseif key == keys.up or key == keys.w then |
| 172 | + | --return ((scrlnumper * (b - a)) + a) + 0.1, scrlnumper |
| 173 | - | if selitem > 1 then |
| 173 | + | |
| 174 | - | setsoffset = setsoffset + 2.1 |
| 174 | + | |
| 175 | - | setsoffset = math.floor(setsoffset) |
| 175 | + | |
| 176 | - | selitem = selitem - 1 |
| 176 | + | |
| 177 | ||
| 178 | - | elseif key == keys.down or key == keys.s then |
| 178 | + | |
| 179 | - | if selitem < (#menu) then |
| 179 | + | |
| 180 | - | setsoffset = setsoffset - 1.9 |
| 180 | + | --unused!!!! Recenter Values |
| 181 | - | setsoffset = math.floor(setsoffset) |
| 181 | + | turn_right_recenter_times = 0 |
| 182 | - | selitem = selitem + 1 |
| 182 | + | forward_recenter_times = 0 |
| 183 | ||
| 184 | - | elseif key == keys.q then |
| 184 | + | if Override_ignore_nil_age == 0 then |
| 185 | - | exit() |
| 185 | + | if Mode == 2 then |
| 186 | ignore_nil_age = 1 | |
| 187 | elseif Mode == 1 then | |
| 188 | ignore_nil_age = 0 | |
| 189 | - | while openset == 1 do |
| 189 | + | |
| 190 | - | term.setCursorPos(1, 1) |
| 190 | + | |
| 191 | - | term.clear() |
| 191 | + | |
| 192 | - | printmenu(setmenu) |
| 192 | + | st_width = Farm_Width |
| 193 | - | event, key = os.pullEvent("key")
|
| 193 | + | lenth = Farm_Lenth |
| 194 | - | onkeypress(key, setmenu, selitem) |
| 194 | + | if override_stages == 1 then |
| 195 | - | end |
| 195 | + | totalsteps = totalstages |
| 196 | if Mode == 2 then | |
| 197 | grabstage = 5 | |
| 198 | elseif Mode == 1 then | |
| 199 | grabstage = 2 | |
| 200 | end | |
| 201 | elseif Mode == 2 then | |
| 202 | if override_stages == 0 then | |
| 203 | grabstage = 5 | |
| 204 | totalstages = 1 | |
| 205 | - | end |
| 205 | + | totalsteps = 1 |
| 206 | end | |
| 207 | elseif Mode == 1 then | |
| 208 | if override_stages == 0 then | |
| 209 | - | end |
| 209 | + | grabstage = 2 |
| 210 | - | farmexit = 0 |
| 210 | + | totalstages = 2 |
| 211 | - | while farmexit ~= 1 do |
| 211 | + | totalsteps = 2 |
| 212 | end | |
| 213 | end | |
| 214 | ||
| 215 | --term.clear() | |
| 216 | - | --------------------- |
| 216 | + | --term.setCursorPos(1, 1) |
| 217 | - | --------------------- |
| 217 | + | --print("Recentering")
|
| 218 | - | --------------------- |
| 218 | + | totalsteps = totalstages |
| 219 | - | --CHANGE HERE START-- |
| 219 | + | endsteps = totalsteps + 1 |
| 220 | - | --------------------- |
| 220 | + | sub_lenth = lenth - 1 |
| 221 | - | --------------------- |
| 221 | + | function chest() |
| 222 | - | --------------------- |
| 222 | + | --term.clear() |
| 223 | --term.setCursorPos(1, 1) | |
| 224 | --print("Going to Chest")
| |
| 225 | gt.goto(chestloc) | |
| 226 | if Mode == 2 then | |
| 227 | chest = 1 | |
| 228 | elseif Mode == 1 then | |
| 229 | chest = 2 | |
| 230 | - | --"1" is Normal, "2" is Pumpkin/Melon/Probably Sugar Cane |
| 230 | + | |
| 231 | - | Mode = tonumber(settings.get(setmenu[4].setname)) |
| 231 | + | --term.clear() |
| 232 | - | |
| 232 | + | --term.setCursorPos(1, 1) |
| 233 | - | if Mode > 2 or Mode < 1 then |
| 233 | + | --print("Putting in Chest")
|
| 234 | - | Mode = 2 |
| 234 | + | |
| 235 | - | end |
| 235 | + | |
| 236 | while chest <= 16 do | |
| 237 | turtle.select(chest) | |
| 238 | - | Farm_Lenth = tonumber(settings.get(setmenu[2].setname)) |
| 238 | + | if chestdirection == 0 then |
| 239 | - | Farm_Width = tonumber(settings.get(setmenu[3].setname)) |
| 239 | + | turtle.drop() |
| 240 | elseif chestdirection == 1 then | |
| 241 | turtle.dropDown() | |
| 242 | elseif chestdirection == 2 then | |
| 243 | turtle.dropUp() | |
| 244 | - | -- sort for specific crop |
| 244 | + | end |
| 245 | chest = chest + 1 | |
| 246 | - | --whether or not to sort, 1 is yes, 0 is no |
| 246 | + | |
| 247 | - | sortblock = tonumber(settings.get(setmenu[8].setname)) |
| 247 | + | if turnleftchest == 1 then |
| 248 | - | if sortblock > 1 or sortblock < 0 then |
| 248 | + | turtle.turnLeft() |
| 249 | - | sortblock = 1 |
| 249 | + | |
| 250 | - | end |
| 250 | + | --term.clear() |
| 251 | --term.setCursorPos(1, 1) | |
| 252 | - | --name of the crop |
| 252 | + | --print("Resetting")
|
| 253 | - | crop_name = settings.get(setmenu[9].setname) |
| 253 | + | -- sleep(farmsleeptime) |
| 254 | farmexit = 1 | |
| 255 | - | --max age of crop should probably be left at 7 |
| 255 | + | |
| 256 | - | crop_max_age = 7 |
| 256 | + | |
| 257 | ||
| 258 | function turn() | |
| 259 | if width >= 2 then | |
| 260 | - | --setup location |
| 260 | + | if right == 1 then |
| 261 | - | setuploc = settings.get(setmenu[5].setname) |
| 261 | + | turtle.turnRight() |
| 262 | turtle.forward() | |
| 263 | turtle.turnRight() | |
| 264 | dist = sub_lenth | |
| 265 | - | --chest location |
| 265 | + | width = width - 1 |
| 266 | - | chestloc = settings.get(setmenu[6].setname) |
| 266 | + | right = 0 |
| 267 | else | |
| 268 | - | farmsleeptime = 5 |
| 268 | + | turtle.turnLeft() |
| 269 | - | |
| 269 | + | |
| 270 | - | --chest 2 = "up", 1 = "down", or 0 = "forward" |
| 270 | + | turtle.turnLeft() |
| 271 | - | chestdirection = tonumber(settings.get(setmenu[7].setname)) |
| 271 | + | dist = sub_lenth |
| 272 | - | |
| 272 | + | width = width - 1 |
| 273 | - | if chestdirection > 2 or chestdirection < 0 then |
| 273 | + | right = 1 |
| 274 | - | chestdirection = 2 |
| 274 | + | |
| 275 | - | end |
| 275 | + | elseif width < 2 then |
| 276 | - | --misc |
| 276 | + | dist = sub_lenth |
| 277 | width = width - 1 | |
| 278 | - | --ignore if a crop has no age value should be set at 1 for Pumpkin/Melon and 0 for Normal |
| 278 | + | if width <= 0 then |
| 279 | - | Override_ignore_nil_age = 0 |
| 279 | + | turtle.turnLeft() |
| 280 | - | ignore_nil_age = 1 |
| 280 | + | turtle.turnLeft() |
| 281 | end | |
| 282 | - | override_stages = 0 |
| 282 | + | |
| 283 | - | turnleftchest = 0 |
| 283 | + | |
| 284 | - | totalstages = 1 |
| 284 | + | |
| 285 | - | ------------------- |
| 285 | + | |
| 286 | - | ------------------- |
| 286 | + | function recenter() |
| 287 | - | --CHANGE HERE END-- |
| 287 | + | working_turn_right_recenter_times = turn_right_recenter_times |
| 288 | - | ------------------- |
| 288 | + | |
| 289 | - | ------------------- |
| 289 | + | working_forward_recenter_times = forward_recenter_times |
| 290 | gt.goto(setuploc) | |
| 291 | if turn_right_recenter_times ~= 0 then | |
| 292 | while working_turn_right_recenter_times ~= 0 do | |
| 293 | turtle.turnRight() | |
| 294 | working_turn_right_recenter_times = working_turn_right_recenter_times - 1 | |
| 295 | end | |
| 296 | end | |
| 297 | ||
| 298 | right = 1 | |
| 299 | turtle.select(1) | |
| 300 | dist = lenth - 1 | |
| 301 | if forward_recenter_times ~= 0 then | |
| 302 | while working_forward_recenter_times ~= 0 do | |
| 303 | turtle.forward() | |
| 304 | working_forward_recenter_times = working_forward_recenter_times - 1 | |
| 305 | end | |
| 306 | end | |
| 307 | end | |
| 308 | ||
| 309 | if percentageold == nil then | |
| 310 | percentageold = 0 | |
| 311 | end | |
| 312 | if dopnt == nil then | |
| 313 | dopnt = 1 | |
| 314 | end | |
| 315 | if tnstm == nil then | |
| 316 | - | --unused!!!! Recenter Values |
| 316 | + | tnstm = 0.01 |
| 317 | - | turn_right_recenter_times = 0 |
| 317 | + | |
| 318 | - | forward_recenter_times = 0 |
| 318 | + | if scagtm == nil then |
| 319 | scagtm = 0.01 | |
| 320 | - | if Override_ignore_nil_age == 0 then |
| 320 | + | |
| 321 | - | if Mode == 2 then |
| 321 | + | function stage1() |
| 322 | - | ignore_nil_age = 1 |
| 322 | + | ttmst = os.clock() |
| 323 | - | elseif Mode == 1 then |
| 323 | + | --term.setCursorPos(1, 1) |
| 324 | - | ignore_nil_age = 0 |
| 324 | + | --term.clearLine() |
| 325 | - | end |
| 325 | + | if totalstages <= 1 then |
| 326 | - | end |
| 326 | + | --print ("Stage: " .. done .. "/" .. totalsteps.. " Harvest")
|
| 327 | elseif totalstages >= 2 then | |
| 328 | - | st_width = Farm_Width |
| 328 | + | --print ("Stage: " .. done .. "/" .. totalsteps.. " Harvest and Plant")
|
| 329 | - | lenth = Farm_Lenth |
| 329 | + | |
| 330 | - | if override_stages == 1 then |
| 330 | + | for i=1,#crop_name do |
| 331 | - | totalsteps = totalstages |
| 331 | + | success, data = turtle.inspectDown() |
| 332 | - | if Mode == 2 then |
| 332 | + | if success then |
| 333 | - | grabstage = 5 |
| 333 | + | if dopnt == 6 then |
| 334 | - | elseif Mode == 1 then |
| 334 | + | if data.state.age ~= nil then |
| 335 | - | grabstage = 2 |
| 335 | + | scnmpnt = 0 |
| 336 | dlprns1 = 0 | |
| 337 | - | elseif Mode == 2 then |
| 337 | + | percentagefloat = (data.state.age - 0) / (7 - 0) * 100 |
| 338 | - | if override_stages == 0 then |
| 338 | + | percentage = math.floor(percentagefloat+0.5) |
| 339 | - | grabstage = 5 |
| 339 | + | scnmtmst = os.clock() |
| 340 | - | totalstages = 1 |
| 340 | + | |
| 341 | - | totalsteps = 1 |
| 341 | + | scagl = 0 |
| 342 | - | end |
| 342 | + | while dlprns1 < 1 do |
| 343 | - | elseif Mode == 1 then |
| 343 | + | scagtmst = os.clock() |
| 344 | - | if override_stages == 0 then |
| 344 | + | scnmpnt, dlprns1 = scrlnum(percentageold,percentage,tnstm,scnmtmst) |
| 345 | - | grabstage = 2 |
| 345 | + | if dlprns1 == nil then |
| 346 | - | totalstages = 2 |
| 346 | + | dlprns1 = 0 |
| 347 | - | totalsteps = 2 |
| 347 | + | |
| 348 | -- term.setCursorPos(1, 2) | |
| 349 | - | end |
| 349 | + | -- term.clearLine() |
| 350 | --print("Crop Age: " .. scnmpnt .. "%")
| |
| 351 | - | term.clear() |
| 351 | + | --term.setCursorPos(1, 4) |
| 352 | - | term.setCursorPos(1, 1) |
| 352 | + | --term.clearLine() |
| 353 | - | print("Recentering")
|
| 353 | + | --if dlprns1 ~= nil then |
| 354 | - | totalsteps = totalstages |
| 354 | + | --print("" .. dlprns1 .. "")
|
| 355 | - | endsteps = totalsteps + 1 |
| 355 | + | --end |
| 356 | - | sub_lenth = lenth - 1 |
| 356 | + | --term.setCursorPos(1, 6) |
| 357 | - | function chest() |
| 357 | + | --term.clearLine() |
| 358 | - | term.clear() |
| 358 | + | --print("" .. percentageold .. "")
|
| 359 | - | term.setCursorPos(1, 1) |
| 359 | + | if scagl > 25 then |
| 360 | - | print("Going to Chest")
|
| 360 | + | sleep() |
| 361 | - | gt.goto(chestloc) |
| 361 | + | scagl = 0 |
| 362 | - | if Mode == 2 then |
| 362 | + | |
| 363 | - | chest = 1 |
| 363 | + | scagl = scagl + 1 |
| 364 | - | elseif Mode == 1 then |
| 364 | + | scagtmen = os.clock() |
| 365 | - | chest = 2 |
| 365 | + | scagtm = scagtmen - scagtmst |
| 366 | end | |
| 367 | - | term.clear() |
| 367 | + | percentageold = percentage |
| 368 | - | term.setCursorPos(1, 1) |
| 368 | + | |
| 369 | - | print("Putting in Chest")
|
| 369 | + | |
| 370 | - | |
| 370 | + | |
| 371 | - | |
| 371 | + | |
| 372 | - | while chest <= 16 do |
| 372 | + | if (data.name == crop_name[i]) or (sortblock == 0) then |
| 373 | - | turtle.select(chest) |
| 373 | + | if data.state.age == crop_max_age or ignore_nil_age == 1 then |
| 374 | - | if chestdirection == 0 then |
| 374 | + | --print("Age Check 2: " .. data.state.age)
|
| 375 | - | turtle.drop() |
| 375 | + | turtle.digDown() |
| 376 | - | elseif chestdirection == 1 then |
| 376 | + | --term.setCursorPos(1, 3) |
| 377 | - | turtle.dropDown() |
| 377 | + | --term.clearLine() |
| 378 | - | elseif chestdirection == 2 then |
| 378 | + | --print("dig")
|
| 379 | - | turtle.dropUp() |
| 379 | + | |
| 380 | - | end |
| 380 | + | end |
| 381 | - | chest = chest + 1 |
| 381 | + | end |
| 382 | turtle.suckDown() | |
| 383 | - | if turnleftchest == 1 then |
| 383 | + | if Mode == 1 then |
| 384 | - | turtle.turnLeft() |
| 384 | + | turtle.placeDown() |
| 385 | end | |
| 386 | - | term.clear() |
| 386 | + | |
| 387 | - | term.setCursorPos(1, 1) |
| 387 | + | |
| 388 | - | --print("Resetting")
|
| 388 | + | ttmen = os.clock() |
| 389 | - | sleep(farmsleeptime) |
| 389 | + | tnstm = ttmen - ttmst |
| 390 | - | farmexit = 1 |
| 390 | + | tnstm = tnstm - scagtm |
| 391 | - | end |
| 391 | + | tnstm = tnstm / 2 |
| 392 | if tnstm < 0 then | |
| 393 | tnstm = 0.02 | |
| 394 | - | function turn() |
| 394 | + | |
| 395 | - | if width >= 2 then |
| 395 | + | |
| 396 | - | if right == 1 then |
| 396 | + | |
| 397 | - | turtle.turnRight() |
| 397 | + | function scrlage() |
| 398 | - | turtle.forward() |
| 398 | + | for i=1,#crop_name do |
| 399 | - | turtle.turnRight() |
| 399 | + | success, data = turtle.inspectDown() |
| 400 | - | dist = sub_lenth |
| 400 | + | if success then |
| 401 | - | width = width - 1 |
| 401 | + | if dopnt == 1 then |
| 402 | - | right = 0 |
| 402 | + | if data.state.age ~= nil then |
| 403 | scnmpnt = 0 | |
| 404 | - | turtle.turnLeft() |
| 404 | + | dlprns1 = 0 |
| 405 | - | turtle.forward() |
| 405 | + | percentagefloat = (data.state.age - 0) / (7 - 0) * 100 |
| 406 | - | turtle.turnLeft() |
| 406 | + | percentage = math.floor(percentagefloat+0.5) |
| 407 | - | dist = sub_lenth |
| 407 | + | scnmtmst = os.clock() |
| 408 | - | width = width - 1 |
| 408 | + | |
| 409 | ||
| 410 | while dlprns1 < 1 do | |
| 411 | - | elseif width < 2 then |
| 411 | + | scnmpnt, dlprns1 = scrlnum(percentageold,percentage,0.5,scnmtmst) |
| 412 | - | dist = sub_lenth |
| 412 | + | if dlprns1 == nil then |
| 413 | - | width = width - 1 |
| 413 | + | dlprns1 = 0 |
| 414 | - | if width <= 0 then |
| 414 | + | |
| 415 | - | turtle.turnLeft() |
| 415 | + | -- term.setCursorPos(1, 2) |
| 416 | - | turtle.turnLeft() |
| 416 | + | -- term.clearLine() |
| 417 | --print("Crop Age: " .. scnmpnt .. "%")
| |
| 418 | --term.setCursorPos(1, 4) | |
| 419 | - | end |
| 419 | + | --term.clearLine() |
| 420 | --if dlprns1 ~= nil then | |
| 421 | --print("" .. dlprns1 .. "")
| |
| 422 | - | function recenter() |
| 422 | + | --end |
| 423 | - | working_turn_right_recenter_times = turn_right_recenter_times |
| 423 | + | --term.setCursorPos(1, 6) |
| 424 | --term.clearLine() | |
| 425 | - | working_forward_recenter_times = forward_recenter_times |
| 425 | + | --print("" .. percentageold .. "")
|
| 426 | - | gt.goto(setuploc) |
| 426 | + | sleep() |
| 427 | - | if turn_right_recenter_times ~= 0 then |
| 427 | + | |
| 428 | - | while working_turn_right_recenter_times ~= 0 do |
| 428 | + | percentageold = percentage |
| 429 | - | turtle.turnRight() |
| 429 | + | |
| 430 | - | working_turn_right_recenter_times = working_turn_right_recenter_times - 1 |
| 430 | + | |
| 431 | end | |
| 432 | end | |
| 433 | end | |
| 434 | - | right = 1 |
| 434 | + | |
| 435 | - | turtle.select(1) |
| 435 | + | |
| 436 | - | dist = lenth - 1 |
| 436 | + | |
| 437 | - | if forward_recenter_times ~= 0 then |
| 437 | + | |
| 438 | - | while working_forward_recenter_times ~= 0 do |
| 438 | + | |
| 439 | - | turtle.forward() |
| 439 | + | |
| 440 | - | working_forward_recenter_times = working_forward_recenter_times - 1 |
| 440 | + | function stage2() |
| 441 | -- term.setCursorPos(1, 1) | |
| 442 | -- term.clearLine() | |
| 443 | - | end |
| 443 | + | --print ("Stage: " .. done .. "/" .. totalsteps .. " Cleanup")
|
| 444 | turtle.suckDown() | |
| 445 | --print("grab")
| |
| 446 | end | |
| 447 | ||
| 448 | - | function stage1() |
| 448 | + | function stg1tg() |
| 449 | - | term.setCursorPos(1, 1) |
| 449 | + | if dist ~= 0 then |
| 450 | - | term.clearLine() |
| 450 | + | if done == 1 then |
| 451 | - | if totalstages <= 1 then |
| 451 | + | -- term.clear() |
| 452 | - | print ("Stage: " .. done .. "/" .. totalsteps.. " Harvest")
|
| 452 | + | while width ~= 0 do |
| 453 | - | elseif totalstages >= 2 then |
| 453 | + | while dist ~= 0 do |
| 454 | - | print ("Stage: " .. done .. "/" .. totalsteps.. " Harvest and Plant")
|
| 454 | + | dopnt = 1 |
| 455 | parallel.waitForAll(stage1,scrlage) | |
| 456 | - | for i=1,#crop_name do |
| 456 | + | --stage1() |
| 457 | - | success, data = turtle.inspectDown() |
| 457 | + | dopnt = 1 |
| 458 | - | if success then |
| 458 | + | turtle.forward() |
| 459 | - | if data.state.age ~= nil then |
| 459 | + | --parallel.waitForAll(stage1,scrlage) |
| 460 | - | term.setCursorPos(1, 2) |
| 460 | + | stage1() |
| 461 | - | term.clearLine() |
| 461 | + | --print(dist) |
| 462 | - | percentagefloat = (data.state.age - 0) / (7 - 0) * 100 |
| 462 | + | dist = dist - 1 |
| 463 | - | percentage = math.floor(percentagefloat+0.5) |
| 463 | + | |
| 464 | turn() | |
| 465 | - | print("Crop Age: " .. percentage .. "%")
|
| 465 | + | |
| 466 | end | |
| 467 | end | |
| 468 | - | if (data.name == crop_name[i]) or (sortblock == 0) then |
| 468 | + | |
| 469 | - | if data.state.age == crop_max_age or ignore_nil_age == 1 then |
| 469 | + | |
| 470 | - | --print("Age Check 2: " .. data.state.age)
|
| 470 | + | |
| 471 | - | turtle.digDown() |
| 471 | + | if width == 0 or width == nil then |
| 472 | - | --term.setCursorPos(1, 3) |
| 472 | + | done = done + 1 |
| 473 | - | --term.clearLine() |
| 473 | + | --print ("add")
|
| 474 | - | --print("dig")
|
| 474 | + | --print ("Steps: " .. done)
|
| 475 | if done == endsteps then | |
| 476 | - | end |
| 476 | + | chest() |
| 477 | - | end |
| 477 | + | done = 0 |
| 478 | farmexit = 1 | |
| 479 | - | if Mode == 1 then |
| 479 | + | |
| 480 | - | turtle.placeDown() |
| 480 | + | width = st_width |
| 481 | --print("width: " .. width)
| |
| 482 | if farmexit ~= 1 then | |
| 483 | recenter() | |
| 484 | - | end |
| 484 | + | |
| 485 | ||
| 486 | elseif width ~= 0 then | |
| 487 | ||
| 488 | - | function stage2() |
| 488 | + | if dist ~= 0 then |
| 489 | - | term.setCursorPos(1, 1) |
| 489 | + | if done == 1 then |
| 490 | - | term.clearLine() |
| 490 | + | -- term.clear() |
| 491 | - | print ("Stage: " .. done .. "/" .. totalsteps .. " Cleanup")
|
| 491 | + | while width ~= 0 do |
| 492 | - | turtle.suckDown() |
| 492 | + | while dist ~= 0 do |
| 493 | - | --print("grab")
|
| 493 | + | dopnt = 1 |
| 494 | - | end |
| 494 | + | parallel.waitForAll(stage1,scrlage) |
| 495 | --stage1() | |
| 496 | dopnt = 1 | |
| 497 | turtle.forward() | |
| 498 | - | if width == 0 or width == nil then |
| 498 | + | parallel.waitForAll(stage1,scrlage) |
| 499 | - | done = done + 1 |
| 499 | + | --stage1() |
| 500 | - | --print ("add")
|
| 500 | + | --print(dist) |
| 501 | - | --print ("Steps: " .. done)
|
| 501 | + | dist = dist - 1 |
| 502 | - | if done == endsteps then |
| 502 | + | |
| 503 | - | chest() |
| 503 | + | turn() |
| 504 | end | |
| 505 | - | farmexit = 1 |
| 505 | + | |
| 506 | elseif done == grabstage then | |
| 507 | - | width = st_width |
| 507 | + | -- term.clear() |
| 508 | - | --print("width: " .. width)
|
| 508 | + | while width ~= 0 do |
| 509 | - | if farmexit ~= 1 then |
| 509 | + | while dist ~= 0 do |
| 510 | - | recenter() |
| 510 | + | stage2() |
| 511 | turtle.forward() | |
| 512 | stage2() | |
| 513 | - | elseif width ~= 0 then |
| 513 | + | dist = dist - 1 |
| 514 | end | |
| 515 | - | if dist ~= 0 then |
| 515 | + | turn() |
| 516 | - | if done == 1 then |
| 516 | + | |
| 517 | - | term.clear() |
| 517 | + | |
| 518 | - | while width ~= 0 do |
| 518 | + | |
| 519 | - | while dist ~= 0 do |
| 519 | + | |
| 520 | - | stage1() |
| 520 | + | |
| 521 | end | |
| 522 | - | stage1() |
| 522 | + | |
| 523 | - | --print(dist) |
| 523 | + |