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