SHOW:
|
|
- or go back to the newest paste.
| 1 | --INPUT = reference, slots, blocks, data | |
| 2 | --OUTPUT = ObjectivesList | |
| 3 | ||
| 4 | --[[function saveVarsToConsole(name) | |
| 5 | local h = fs.open(name,'w') | |
| 6 | local env = getfenv() | |
| 7 | for i,v in pairs(env) do | |
| 8 | if i then | |
| 9 | h.write(i) | |
| 10 | if v then | |
| 11 | --h.write("("..tostring(type(v))..")")
| |
| 12 | h.write(': ')
| |
| 13 | h.writeLine(v) | |
| 14 | end | |
| 15 | end | |
| 16 | end | |
| 17 | h.close() | |
| 18 | end]] | |
| 19 | ||
| 20 | --update | |
| 21 | local h = fs.open("update","w")
| |
| 22 | h.write([[ | |
| 23 | fs.delete("schemAPI")
| |
| 24 | shell.run("pastebin get 13QunP89 schemAPI")
| |
| 25 | ]]) | |
| 26 | h.close() | |
| 27 | ||
| 28 | --restart | |
| 29 | local k = fs.open("restart","w")
| |
| 30 | k.write([[ | |
| 31 | for i,v in pairs(fs.list("")) do
| |
| 32 | if v~="rom" and v~="chicken" then | |
| 33 | fs.delete(v) | |
| 34 | end | |
| 35 | end | |
| 36 | ]]) | |
| 37 | k.close() | |
| 38 | ||
| 39 | function openRednet() | |
| 40 | for _,v in ipairs(peripheral.getNames()) do | |
| 41 | if peripheral.getType(v)=="modem" then | |
| 42 | rednet.open(v) | |
| 43 | end | |
| 44 | end | |
| 45 | end | |
| 46 | ||
| 47 | function checkIfRefill() | |
| 48 | local _,inFront = turtle.inspect() | |
| 49 | local _,below = turtle.inspectDown() | |
| 50 | local mem = turtle.getSelectedSlot() | |
| 51 | turtle.select(16) | |
| 52 | local check = turtle.getItemDetail() | |
| 53 | if check and check.name ~= "EnderStorage:enderChest" then | |
| 54 | if not turtle.dropDown() then | |
| 55 | if not turtle.drop() then | |
| 56 | turtle.dropUp() | |
| 57 | end | |
| 58 | end | |
| 59 | end | |
| 60 | if inFront or below then | |
| 61 | if inFront.name == "EnderStorage:enderChest" then | |
| 62 | turtle.select(enderchest1) | |
| 63 | turtle.dig() | |
| 64 | end | |
| 65 | if below.name == "EnderStorage:enderChest" then | |
| 66 | turtle.select(enderchest2) | |
| 67 | turtle.digDown() | |
| 68 | end | |
| 69 | end | |
| 70 | turtle.select(mem) | |
| 71 | end | |
| 72 | ||
| 73 | function calibrateDir() | |
| 74 | --if gpsi then | |
| 75 | local dir | |
| 76 | local h,k,l = gps.locate() | |
| 77 | h = math.floor(h) | |
| 78 | k = math.floor(k) | |
| 79 | l = math.floor(l) | |
| 80 | while not turtle.forward() do | |
| 81 | turtle.dig() | |
| 82 | end | |
| 83 | local h2,k2,l2 = gps.locate() | |
| 84 | turtle.back() | |
| 85 | if h2>h then | |
| 86 | dir = "east" | |
| 87 | elseif h2<h then | |
| 88 | dir = "west" | |
| 89 | elseif l2>l then | |
| 90 | dir = "south" | |
| 91 | elseif l2<l then | |
| 92 | dir = "north" | |
| 93 | end | |
| 94 | return dir | |
| 95 | --end | |
| 96 | end | |
| 97 | ||
| 98 | function recalibratePos() | |
| 99 | local h,k,l = gps.locate() | |
| 100 | local xtemp,ytemp,ztemp = h - Hoff, k - Koff, l - Loff | |
| 101 | ||
| 102 | if origDir == "south" then | |
| 103 | widthPos = 0 + xtemp | |
| 104 | heightPos = ytemp | |
| 105 | lengthPos = 0 + ztemp | |
| 106 | elseif origDir == "north" then | |
| 107 | widthPos = 0 - xtemp | |
| 108 | heightPos = ytemp | |
| 109 | lengthPos = 0 - ztemp | |
| 110 | elseif origDir == "east" then | |
| 111 | widthPos = 0 - ztemp | |
| 112 | heightPos = ytemp | |
| 113 | lengthPos = 0 + xtemp | |
| 114 | elseif origDir == "west" then | |
| 115 | widthPos = 0 + ztemp | |
| 116 | heightPos = ytemp | |
| 117 | lengthPos = 0 - xtemp | |
| 118 | end | |
| 119 | ||
| 120 | end | |
| 121 | ||
| 122 | function recalibrateFace() | |
| 123 | if origDir ~= "south" then | |
| 124 | if origDir == "north" then | |
| 125 | update("right")
| |
| 126 | update("right")
| |
| 127 | elseif origDir == "east" then | |
| 128 | update("right")
| |
| 129 | elseif origDir == "west" then | |
| 130 | update("left")
| |
| 131 | end | |
| 132 | end | |
| 133 | end | |
| 134 | ||
| 135 | function resynchronize() | |
| 136 | if gpsi then | |
| 137 | recalibratePos() | |
| 138 | face = calibrateDir() | |
| 139 | recalibrateFace() | |
| 140 | recordPos(heightPos,widthPos,lengthPos,face) | |
| 141 | end | |
| 142 | end | |
| 143 | ||
| 144 | function saveVarsToFile() | |
| 145 | local h = fs.open("currentVars",'w')
| |
| 146 | local env = getfenv() | |
| 147 | for i,v in pairs(env) do | |
| 148 | if type(v) == "string" then | |
| 149 | h.write(tostring(i)) | |
| 150 | h.write(" = ")
| |
| 151 | h.write([["]]..tostring(v)..[["]]) | |
| 152 | elseif type(v) == "table" then | |
| 153 | h.write(i) | |
| 154 | h.write(" = ")
| |
| 155 | h.write(textutils.serialize(v)) | |
| 156 | end | |
| 157 | end | |
| 158 | h.close() | |
| 159 | end | |
| 160 | ||
| 161 | function loadVars() | |
| 162 | local h = fs.open("currentVars",'r')
| |
| 163 | end | |
| 164 | ||
| 165 | function recordPos(heightPos,widthPos,lengthPos,face) | |
| 166 | local h = fs.open("position","w")
| |
| 167 | h.writeLine("heightPos = "..tostring(heightPos))
| |
| 168 | h.writeLine("widthPos = "..tostring(widthPos))
| |
| 169 | h.writeLine("lengthPos = "..tostring(lengthPos))
| |
| 170 | h.writeLine("face = ".."\""..tostring(face).."\"")
| |
| 171 | h.close() | |
| 172 | end | |
| 173 | ||
| 174 | function recordObj(x,y,z) | |
| 175 | local h = fs.open("objective",'w')
| |
| 176 | h.writeLine("x = "..tostring(x))
| |
| 177 | h.writeLine("y = "..tostring(y))
| |
| 178 | h.writeLine("z = "..tostring(z))
| |
| 179 | h.close() | |
| 180 | end | |
| 181 | ||
| 182 | function recordObjNum(num) | |
| 183 | local h = fs.open("objective2",'w')
| |
| 184 | h.writeLine("num = "..tostring(num))
| |
| 185 | h.close() | |
| 186 | end | |
| 187 | ||
| 188 | block_id = {}
| |
| 189 | block_id[0] = "Air" | |
| 190 | block_id[1] = "Stone" | |
| 191 | block_id[2] = "Grass" | |
| 192 | block_id[3] = "Dirt" | |
| 193 | block_id[4] = "Cobblestone" | |
| 194 | block_id[5] = "Wooden Plank" | |
| 195 | block_id[6] = "Sapling" | |
| 196 | block_id[7] = "Bedrock" | |
| 197 | block_id[8] = "Water" | |
| 198 | block_id[9] = "Stationary water" | |
| 199 | block_id[10] = "Lava" | |
| 200 | block_id[11] = "Stationary lava" | |
| 201 | block_id[12] = "Sand" | |
| 202 | block_id[13] = "Gravel" | |
| 203 | block_id[14] = "Gold Ore" | |
| 204 | block_id[15] = "Iron (Ore)" | |
| 205 | block_id[16] = "Coal Ore" | |
| 206 | block_id[17] = "Log" | |
| 207 | block_id[18] = "Leaves" | |
| 208 | block_id[19] = "Sponge" | |
| 209 | block_id[20] = "Glass" | |
| 210 | block_id[21] = "Lapis Lazuli (Ore)" | |
| 211 | block_id[22] = "Lapis Lazuli (Block)" | |
| 212 | block_id[23] = "Dispenser" | |
| 213 | block_id[24] = "Sandstone" | |
| 214 | block_id[25] = "Note Block Tile entity" | |
| 215 | block_id[26] = "Bed" | |
| 216 | block_id[27] = "Powered Rail " | |
| 217 | block_id[28] = "Detector Rail " | |
| 218 | block_id[29] = "Sticky Piston" | |
| 219 | block_id[30] = "Cobweb" | |
| 220 | block_id[31] = "Tall Grass" | |
| 221 | block_id[32] = "Dead Bush" | |
| 222 | block_id[33] = "Piston" | |
| 223 | block_id[34] = "Piston Extension" | |
| 224 | block_id[35] = "Wool" | |
| 225 | block_id[36] = "Block moved by Piston" | |
| 226 | block_id[37] = "Dandelionandelion" | |
| 227 | block_id[38] = "Rose" | |
| 228 | block_id[39] = "Brown Mushroom" | |
| 229 | block_id[40] = "Red Mushroom" | |
| 230 | block_id[41] = "Block of Gold" | |
| 231 | block_id[42] = "Block of Iron" | |
| 232 | block_id[43] = "Double Slabs" | |
| 233 | block_id[44] = "Slabs" | |
| 234 | block_id[45] = "Brick Block" | |
| 235 | block_id[46] = "TNT" | |
| 236 | block_id[47] = "Bookshelf" | |
| 237 | block_id[48] = "Moss Stone" | |
| 238 | block_id[49] = "Obsidian" | |
| 239 | block_id[50] = "Torch" | |
| 240 | block_id[51] = "Fire" | |
| 241 | block_id[52] = "Monster Spawner" | |
| 242 | block_id[53] = "Wooden Stairs" | |
| 243 | block_id[54] = "Chest" | |
| 244 | block_id[55] = "Redstone (Wire)" | |
| 245 | block_id[56] = "Diamond (Ore)" | |
| 246 | block_id[57] = "Block of Diamond" | |
| 247 | block_id[58] = "Crafting Table" | |
| 248 | block_id[59] = "Seeds" | |
| 249 | block_id[60] = "Farland" | |
| 250 | block_id[61] = "Furnace" | |
| 251 | block_id[62] = "Burning Furnace" | |
| 252 | block_id[63] = "Sign Post" | |
| 253 | block_id[64] = "Wooden Door" | |
| 254 | block_id[65] = "Ladders" | |
| 255 | block_id[66] = "Rails" | |
| 256 | block_id[67] = "Cobblestone Stairs" | |
| 257 | block_id[68] = "Wall Sign" | |
| 258 | block_id[69] = "Lever" | |
| 259 | block_id[70] = "Stone Pressure Plate" | |
| 260 | block_id[71] = "Iron Door" | |
| 261 | block_id[72] = "Wooden Pressure Plates" | |
| 262 | block_id[73] = "Redstone Ore" | |
| 263 | block_id[74] = "Glowing Redstone Ore" | |
| 264 | block_id[75] = "Redstone Torch" | |
| 265 | block_id[76] = "Redstone Torch" | |
| 266 | block_id[77] = "Stone Button " | |
| 267 | block_id[78] = "Snow" | |
| 268 | block_id[79] = "Ice" | |
| 269 | block_id[80] = "Snow Block" | |
| 270 | block_id[81] = "Cactus" | |
| 271 | block_id[82] = "Clay (Block)" | |
| 272 | block_id[83] = "Sugar Cane" | |
| 273 | block_id[84] = "Jukebox" | |
| 274 | block_id[85] = "Fence" | |
| 275 | block_id[86] = "Pumpkin" | |
| 276 | block_id[87] = "Netherrack" | |
| 277 | block_id[88] = "Soul Sand" | |
| 278 | block_id[89] = "Glowstone" | |
| 279 | block_id[90] = "Portal" | |
| 280 | block_id[91] = "Jack-O-Lantern" | |
| 281 | block_id[92] = "Cake Block" | |
| 282 | block_id[93] = "Redstone Repeater" | |
| 283 | block_id[94] = "Redstone Repeater" | |
| 284 | block_id[95] = "Locked Chest" | |
| 285 | block_id[96] = "Trapdoors" | |
| 286 | block_id[97] = "Hidden Silverfish" | |
| 287 | block_id[98] = "Stone Brick" | |
| 288 | block_id[99] = "Huge brown and red mushroom" | |
| 289 | block_id[100] = "Huge brown and red mushroom" | |
| 290 | block_id[101] = "Iron Bars" | |
| 291 | block_id[102] = "Glass Pane" | |
| 292 | block_id[103] = "Melon" | |
| 293 | block_id[104] = "Pumpkin Stem" | |
| 294 | block_id[105] = "Melon Stem" | |
| 295 | block_id[106] = "Vines" | |
| 296 | block_id[107] = "Fence Gate" | |
| 297 | block_id[108] = "Brick Stairs" | |
| 298 | block_id[109] = "Stone Brick Stairs" | |
| 299 | block_id[110] = "Mycelium" | |
| 300 | block_id[111] = "Lily Pad" | |
| 301 | block_id[112] = "Nether Brick" | |
| 302 | block_id[113] = "Nether Brick Fence" | |
| 303 | block_id[114] = "Nether Brick Stairs" | |
| 304 | block_id[115] = "Nether Wart" | |
| 305 | block_id[116] = "Enchantment Table" | |
| 306 | block_id[117] = "Brewing Stand" | |
| 307 | block_id[118] = "Cauldron" | |
| 308 | block_id[119] = "End Portal" | |
| 309 | block_id[120] = "End Portal Frame" | |
| 310 | block_id[121] = "End Stone " | |
| 311 | block_id[256] = "Iron Ingotron Shovel" | |
| 312 | block_id[257] = "Iron Pickaxe" | |
| 313 | block_id[258] = "Iron Axe" | |
| 314 | block_id[259] = "Flint and Steel" | |
| 315 | block_id[260] = "Red Apple" | |
| 316 | block_id[261] = "Bow" | |
| 317 | block_id[262] = "Arrow" | |
| 318 | block_id[263] = "Coal" | |
| 319 | ||
| 320 | woolColors = {}
| |
| 321 | woolColors[0] = "White" | |
| 322 | woolColors[1] = "Orange" | |
| 323 | woolColors[2] = "Magenta" | |
| 324 | woolColors[3] = "Light Blue" | |
| 325 | woolColors[4] = "Yellow" | |
| 326 | woolColors[5] = "Lime" | |
| 327 | woolColors[6] = "Pink" | |
| 328 | woolColors[7] = "Gray" | |
| 329 | woolColors[8] = "Light Gray" | |
| 330 | woolColors[9] = "Cyan" | |
| 331 | woolColors[10] = "Purple" | |
| 332 | woolColors[11] = "Blue" | |
| 333 | woolColors[12] = "Brown" | |
| 334 | woolColors[13] = "Green" | |
| 335 | woolColors[14] = "Red" | |
| 336 | woolColors[15] = "Black" | |
| 337 | ||
| 338 | --[[Navigation Functions]]-- | |
| 339 | ||
| 340 | function goto(heightGoal,widthGoal,lengthGoal) | |
| 341 | shell.run("position")
| |
| 342 | if turtle.getFuelLevel() < 200 then | |
| 343 | refill() | |
| 344 | end | |
| 345 | if heightGoal > heightPos then | |
| 346 | while heightGoal > heightPos do | |
| 347 | up() | |
| 348 | end | |
| 349 | elseif heightGoal < heightPos then | |
| 350 | while heightGoal < heightPos do | |
| 351 | down() | |
| 352 | end | |
| 353 | end | |
| 354 | if widthGoal > widthPos then | |
| 355 | turn("east")
| |
| 356 | while widthGoal > widthPos do | |
| 357 | forward() | |
| 358 | end | |
| 359 | elseif widthGoal < widthPos then | |
| 360 | turn("west")
| |
| 361 | while widthGoal < widthPos do | |
| 362 | forward() | |
| 363 | end | |
| 364 | end | |
| 365 | if lengthGoal > lengthPos then | |
| 366 | turn("south")
| |
| 367 | while lengthGoal > lengthPos do | |
| 368 | forward() | |
| 369 | end | |
| 370 | elseif lengthGoal < lengthPos then | |
| 371 | turn("north")
| |
| 372 | while lengthGoal < lengthPos do | |
| 373 | forward() | |
| 374 | end | |
| 375 | end | |
| 376 | end | |
| 377 | ||
| 378 | function update(dir) | |
| 379 | if dir == "forward" then | |
| 380 | if face == "north" then | |
| 381 | lengthPos = lengthPos - 1 | |
| 382 | elseif face == "south" then | |
| 383 | lengthPos = lengthPos + 1 | |
| 384 | elseif face == "west" then | |
| 385 | widthPos = widthPos - 1 | |
| 386 | elseif face == "east" then | |
| 387 | widthPos = widthPos + 1 | |
| 388 | end | |
| 389 | elseif dir == "backward" then | |
| 390 | if face == "north" then | |
| 391 | lengthPos = lengthPos + 1 | |
| 392 | elseif face == "south" then | |
| 393 | lengthPos = lengthPos - 1 | |
| 394 | elseif face == "west" then | |
| 395 | widthPos = widthPos + 1 | |
| 396 | elseif face == "east" then | |
| 397 | widthPos = widthPos - 1 | |
| 398 | end | |
| 399 | elseif dir == "up" then | |
| 400 | heightPos = heightPos + 1 | |
| 401 | elseif dir == "down" then | |
| 402 | heightPos = heightPos - 1 | |
| 403 | elseif dir == "right" then | |
| 404 | if face == "north" then | |
| 405 | face = "east" | |
| 406 | elseif face == "east" then | |
| 407 | face = "south" | |
| 408 | elseif face == "south" then | |
| 409 | face = "west" | |
| 410 | elseif face == "west" then | |
| 411 | face = "north" | |
| 412 | end | |
| 413 | elseif dir == "left" then | |
| 414 | if face == "north" then | |
| 415 | face = "west" | |
| 416 | elseif face == "west" then | |
| 417 | face = "south" | |
| 418 | elseif face == "south" then | |
| 419 | face = "east" | |
| 420 | elseif face == "east" then | |
| 421 | face = "north" | |
| 422 | end | |
| 423 | end | |
| 424 | recordPos(heightPos,widthPos,lengthPos,face) | |
| 425 | end | |
| 426 | ||
| 427 | --[[Refill Functions]]-- | |
| 428 | ||
| 429 | function scanInv() | |
| 430 | local invList = {}
| |
| 431 | for i = 1,16 do | |
| 432 | turtle.select(i) | |
| 433 | local item = turtle.getItemDetail() | |
| 434 | if item then | |
| 435 | invList[i] = {}
| |
| 436 | invList[i][item.name] = item.damage | |
| 437 | end | |
| 438 | end | |
| 439 | return invList | |
| 440 | end | |
| 441 | ||
| 442 | function ParseInv() | |
| 443 | turtle.select(16) | |
| 444 | turtle.dropUp() | |
| 445 | while turtle.suck() do | |
| 446 | local item = turtle.getItemDetail() | |
| 447 | for i =1,16 do | |
| 448 | if item then | |
| 449 | if invList[i][item.name] then | |
| 450 | if invList[i][item.name] == item.damage then | |
| 451 | turtle.transferTo(i) | |
| 452 | break | |
| 453 | end | |
| 454 | end | |
| 455 | if item.name == "minecraft:lava_bucket" or item.name == "minecraft:coal" then | |
| 456 | turtle.refuel(64) | |
| 457 | end | |
| 458 | end | |
| 459 | end | |
| 460 | turtle.dropUp() | |
| 461 | end | |
| 462 | end | |
| 463 | ||
| 464 | function refill() | |
| 465 | local mem = turtle.getSelectedSlot() | |
| 466 | chester("set")
| |
| 467 | ParseInv() | |
| 468 | chester("gather")
| |
| 469 | turtle.select(mem) | |
| 470 | end | |
| 471 | ||
| 472 | function chester(action) | |
| 473 | --action = 'set' or 'gather' | |
| 474 | if action == "set" then | |
| 475 | turtle.select(tonumber(enderchest1)) | |
| 476 | turtle.place() | |
| 477 | turtle.select(tonumber(enderchest2)) | |
| 478 | turtle.placeUp() | |
| 479 | elseif action == "gather" then | |
| 480 | if tonumber(chestOrder) == 1 then | |
| 481 | turtle.digUp() | |
| 482 | transferTo(enderchest1) | |
| 483 | turtle.dig() | |
| 484 | transferTo(enderchest1) | |
| 485 | chestOrder = 2 | |
| 486 | elseif tonumber(chestOrder) == 2 then | |
| 487 | turtle.dig() | |
| 488 | transferTo(enderchest1) | |
| 489 | turtle.digUp() | |
| 490 | transferTo(enderchest1) | |
| 491 | chestOrder = 1 | |
| 492 | end | |
| 493 | end | |
| 494 | end | |
| 495 | ||
| 496 | function transferTo(enderchestSlot) | |
| 497 | for i=16,1,-1 do | |
| 498 | turtle.select(i) | |
| 499 | local item = turtle.getItemDetail() | |
| 500 | if item then | |
| 501 | if item.name == "EnderStorage:enderChest" then | |
| 502 | turtle.transferTo(enderchestSlot) | |
| 503 | break | |
| 504 | end | |
| 505 | end | |
| 506 | end | |
| 507 | end | |
| 508 | ||
| 509 | function getBlockName(id, blockData) | |
| 510 | blockData = blockData or nil | |
| 511 | if(block_id[id] == nil) then | |
| 512 | return "ID: "..tostring(id)..", Data: "..tostring(blockData) | |
| 513 | else | |
| 514 | if(blockData) then | |
| 515 | if(id == 35) then | |
| 516 | str = woolColors[blockData] .. " " .. block_id[id] | |
| 517 | return str | |
| 518 | end | |
| 519 | end | |
| 520 | return block_id[id] .. " " .. id .. ", " .. blockData | |
| 521 | end | |
| 522 | end | |
| 523 | ||
| 524 | function getBlockId(x,y,z) | |
| 525 | return blocks[y + z*width + x*length*width + 1] | |
| 526 | end | |
| 527 | ||
| 528 | function getData(x,y,z) | |
| 529 | return data[y + z*width + x*length*width + 1] | |
| 530 | end | |
| 531 | ||
| 532 | function readbytes(handle, n) | |
| 533 | for i=1,n do | |
| 534 | handle.read() | |
| 535 | end | |
| 536 | end | |
| 537 | ||
| 538 | function readname(handle) | |
| 539 | n1 = handle.read() | |
| 540 | n2 = handle.read() | |
| 541 | ||
| 542 | if(n1 == nil or n2 == nil) then | |
| 543 | return "" | |
| 544 | end | |
| 545 | ||
| 546 | n = n1*256 + n2 | |
| 547 | ||
| 548 | str = "" | |
| 549 | for i=1,n do | |
| 550 | c = handle.read() | |
| 551 | if c == nil then | |
| 552 | return | |
| 553 | end | |
| 554 | str = str .. string.char(c) | |
| 555 | end | |
| 556 | return str | |
| 557 | end | |
| 558 | ||
| 559 | function parse(a, handle, containsName) | |
| 560 | containsName = containsName or true | |
| 561 | if a==0 then | |
| 562 | return | |
| 563 | end | |
| 564 | if containsName then | |
| 565 | name = readname(handle) | |
| 566 | end | |
| 567 | ||
| 568 | if a==1 then | |
| 569 | readbytes(handle,1) | |
| 570 | elseif a==2 then | |
| 571 | i1 = handle.read() | |
| 572 | i2 = handle.read() | |
| 573 | i = i1*256 + i2 | |
| 574 | if(name=="Height") then | |
| 575 | height = i | |
| 576 | elseif (name=="Length") then | |
| 577 | length = i | |
| 578 | elseif (name=="Width") then | |
| 579 | width = i | |
| 580 | end | |
| 581 | elseif a==3 then | |
| 582 | readbytes(handle,4) | |
| 583 | elseif a==4 then | |
| 584 | readbytes(handle,8) | |
| 585 | elseif a==5 then | |
| 586 | readbytes(handle,4) | |
| 587 | elseif a==6 then | |
| 588 | readbytes(handle,8) | |
| 589 | elseif a==7 then | |
| 590 | i1 = handle.read() | |
| 591 | i2 = handle.read() | |
| 592 | i3 = handle.read() | |
| 593 | i4 = handle.read() | |
| 594 | i = i1*256*256*256 + i2*256*256 + i3*256 + i4 | |
| 595 | if name == "Blocks" then | |
| 596 | for i=1,i do | |
| 597 | table.insert(blocks, handle.read()) | |
| 598 | end | |
| 599 | elseif name == "Data" then | |
| 600 | for i=1,i do | |
| 601 | table.insert(data, handle.read()) | |
| 602 | end | |
| 603 | else | |
| 604 | readbytes(handle,i) | |
| 605 | end | |
| 606 | elseif a==8 then | |
| 607 | i1 = handle.read() | |
| 608 | i2 = handle.read() | |
| 609 | i = i1*256 + i2 | |
| 610 | readbytes(handle,i) | |
| 611 | elseif a==9 then | |
| 612 | --readbytes(handle,5) | |
| 613 | type = handle.read() | |
| 614 | i1 = handle.read() | |
| 615 | i2 = handle.read() | |
| 616 | i3 = handle.read() | |
| 617 | i4 = handle.read() | |
| 618 | i = i1*256*256*256 + i2*256*256 + i3*256 + i4 | |
| 619 | for j=1,i do | |
| 620 | parse(handle.read(), handle, false) | |
| 621 | end | |
| 622 | end | |
| 623 | end | |
| 624 | ||
| 625 | --[[Movement Functions]]-- | |
| 626 | ||
| 627 | function forward() | |
| 628 | update("forward")
| |
| 629 | while not turtle.forward() do | |
| 630 | turtle.dig() | |
| 631 | end | |
| 632 | end | |
| 633 | ||
| 634 | function up() | |
| 635 | update("up")
| |
| 636 | while not turtle.up() do | |
| 637 | turtle.digUp() | |
| 638 | end | |
| 639 | end | |
| 640 | ||
| 641 | function down() | |
| 642 | update("down")
| |
| 643 | while not turtle.down() do | |
| 644 | turtle.digDown() | |
| 645 | end | |
| 646 | end | |
| 647 | ||
| 648 | function right() | |
| 649 | update("right")
| |
| 650 | turtle.turnRight() | |
| 651 | end | |
| 652 | ||
| 653 | function left() | |
| 654 | update("left")
| |
| 655 | turtle.turnLeft() | |
| 656 | end | |
| 657 | ||
| 658 | function turn(dir) | |
| 659 | if face == "north" then | |
| 660 | if dir == "east" then | |
| 661 | while face ~= dir do | |
| 662 | right() | |
| 663 | end | |
| 664 | else | |
| 665 | while face ~= dir do | |
| 666 | left() | |
| 667 | end | |
| 668 | end | |
| 669 | elseif face == "east" then | |
| 670 | if dir == "south" then | |
| 671 | while face ~= dir do | |
| 672 | right() | |
| 673 | end | |
| 674 | else | |
| 675 | while face ~= dir do | |
| 676 | left() | |
| 677 | end | |
| 678 | end | |
| 679 | elseif face == "south" then | |
| 680 | if dir == "west" then | |
| 681 | while face ~= dir do | |
| 682 | right() | |
| 683 | end | |
| 684 | else | |
| 685 | while face ~= dir do | |
| 686 | left() | |
| 687 | end | |
| 688 | end | |
| 689 | elseif face == "west" then | |
| 690 | if dir == "north" then | |
| 691 | while face ~= dir do | |
| 692 | right() | |
| 693 | end | |
| 694 | else | |
| 695 | while face ~= dir do | |
| 696 | left() | |
| 697 | end | |
| 698 | end | |
| 699 | end | |
| 700 | end | |
| 701 | ||
| 702 | function place() | |
| 703 | while not turtle.placeDown() do | |
| 704 | turtle.digDown() | |
| 705 | end | |
| 706 | return true | |
| 707 | end | |
| 708 | ||
| 709 | --[[Working Functions]]-- | |
| 710 | ||
| 711 | function setup() | |
| 712 | a = 0 | |
| 713 | while (a ~= nil) do | |
| 714 | a = handle.read() | |
| 715 | parse(a, handle) | |
| 716 | end | |
| 717 | ||
| 718 | write("length: " .. length)
| |
| 719 | write(" width: " .. width)
| |
| 720 | write(" height: " .. height .. "\n")
| |
| 721 | ||
| 722 | uniqueblocks={}
| |
| 723 | for i,v in ipairs(blocks) do | |
| 724 | found = false | |
| 725 | for j,w in ipairs(uniqueblocks) do | |
| 726 | -- for now, data is only accounted for when the block is wool | |
| 727 | if (w.blockID==v and (w.data==data[i] or w.blockID ~= 35)) then | |
| 728 | found = true | |
| 729 | w.amount = w.amount + 1 | |
| 730 | break | |
| 731 | end | |
| 732 | end | |
| 733 | ||
| 734 | if found==false then | |
| 735 | uniqueblocks[#uniqueblocks+1] = {}
| |
| 736 | uniqueblocks[#uniqueblocks].blockID = v | |
| 737 | uniqueblocks[#uniqueblocks].data = data[i] | |
| 738 | uniqueblocks[#uniqueblocks].amount = 1 | |
| 739 | end | |
| 740 | end | |
| 741 | ||
| 742 | print("number of block types: " .. #uniqueblocks)
| |
| 743 | for i,v in ipairs(uniqueblocks) do | |
| 744 | if (i%9)==0 then | |
| 745 | read() | |
| 746 | end | |
| 747 | print(" -" .. getBlockName(v.blockID, v.data) .. ": " .. v.amount)
| |
| 748 | end | |
| 749 | ||
| 750 | read() | |
| 751 | ||
| 752 | print("Give the numbers of all slots containing the specified block type:")
| |
| 753 | ||
| 754 | slots={}
| |
| 755 | for i,block in ipairs(uniqueblocks) do | |
| 756 | blockData = block.data | |
| 757 | print(" -in which slots is " .. getBlockName(block.blockID, blockData) .. "?")
| |
| 758 | if not slots[block.blockID] then | |
| 759 | slots[block.blockID] = {}
| |
| 760 | end | |
| 761 | slots[block.blockID][blockData] = {}
| |
| 762 | write(" ")
| |
| 763 | str = read() | |
| 764 | for i = 1, #str do | |
| 765 | local c = str:sub(i,i) | |
| 766 | n = tonumber(c) | |
| 767 | if(n) then | |
| 768 | if(n>0 and n<10) then | |
| 769 | table.insert(slots[block.blockID][blockData], n) | |
| 770 | end | |
| 771 | end | |
| 772 | end | |
| 773 | end | |
| 774 | invList = scanInv() | |
| 775 | end | |
| 776 | ||
| 777 | function run() | |
| 778 | print("Press key to start building...")
| |
| 779 | read() | |
| 780 | --invList = scanInv() | |
| 781 | ||
| 782 | up() | |
| 783 | n = 1 | |
| 784 | turtle.select(n) | |
| 785 | ||
| 786 | for x=1,height do | |
| 787 | for y=1,width do | |
| 788 | for z=1,length do | |
| 789 | blockID = getBlockId(x-1,y-1,z-1) | |
| 790 | blockData = getData(x-1,y-1,z-1) | |
| 791 | forward() | |
| 792 | turtle.digDown() | |
| 793 | slot_lst = slots[blockID][blockData] | |
| 794 | if(slot_lst ~= nil) then | |
| 795 | if(#slot_lst > 0) then | |
| 796 | local found=false | |
| 797 | for i,v in ipairs(slot_lst) do | |
| 798 | if(turtle.getItemCount(v) > 0) then | |
| 799 | found=true | |
| 800 | turtle.select(v) | |
| 801 | break | |
| 802 | end | |
| 803 | end | |
| 804 | if not found then | |
| 805 | print("Not enough " .. getBlockName(blockID, blockData) .. ". Please refill...")
| |
| 806 | refill() | |
| 807 | end | |
| 808 | while turtle.getItemCount() == 0 do | |
| 809 | refill() | |
| 810 | end | |
| 811 | if turtle.getFuelLevel() < 200 then | |
| 812 | refill() | |
| 813 | end | |
| 814 | end | |
| 815 | end | |
| 816 | end | |
| 817 | left() | |
| 818 | forward() | |
| 819 | left() | |
| 820 | for i=1,length do | |
| 821 | forward() | |
| 822 | end | |
| 823 | right() | |
| 824 | right() | |
| 825 | end | |
| 826 | right() | |
| 827 | for i=1,width do | |
| 828 | forward() | |
| 829 | end | |
| 830 | left() | |
| 831 | up() | |
| 832 | end | |
| 833 | ||
| 834 | for i=1,height+1 do | |
| 835 | down() | |
| 836 | end | |
| 837 | end | |
| 838 | ||
| 839 | function findNextBlock(x,y,z) | |
| 840 | blockID = getBlockId(x,y,z) | |
| 841 | blockData = getData(x,y,z) | |
| 842 | if blockID then | |
| 843 | slot_lst = slots[blockID][blockData] | |
| 844 | if(slot_lst ~= nil) then | |
| 845 | if(#slot_lst > 0) then | |
| 846 | local found=false | |
| 847 | for i,v in ipairs(slot_lst) do | |
| 848 | if(turtle.getItemCount(v) > 0) then | |
| 849 | found=true | |
| 850 | turtle.select(v) | |
| 851 | break | |
| 852 | end | |
| 853 | end | |
| 854 | if not found then | |
| 855 | print("Not enough " .. getBlockName(blockID, blockData) .. ". Please refill...")
| |
| 856 | refill() | |
| 857 | end | |
| 858 | while turtle.getItemCount() == 0 do | |
| 859 | refill() | |
| 860 | end | |
| 861 | local doubleCheck = turtle.getItemDetail() | |
| 862 | if doubleCheck.name ~= "EnderStorage:enderChest" then | |
| 863 | place() | |
| 864 | else | |
| 865 | findNextBlock(x,y,z) | |
| 866 | end | |
| 867 | end | |
| 868 | if turtle.getFuelLevel() < 200 then | |
| 869 | - | function check() |
| 869 | + | |
| 870 | end | |
| 871 | end | |
| 872 | end | |
| 873 | end | |
| 874 | ||
| 875 | function oldIterate() | |
| 876 | --x,y,z = height,width,length | |
| 877 | if z < length then | |
| 878 | z = z + 1 | |
| 879 | elseif z == length then | |
| 880 | z = 0 | |
| 881 | if y < width then | |
| 882 | y = y + 1 | |
| 883 | elseif y == width then | |
| 884 | y = 0 | |
| 885 | if x < height then | |
| 886 | x = x + 1 | |
| 887 | - | function iterate() |
| 887 | + | |
| 888 | - | check() |
| 888 | + | |
| 889 | y = 'max' | |
| 890 | - | Yiterate() |
| 890 | + | |
| 891 | end | |
| 892 | end | |
| 893 | end | |
| 894 | recordObj(x,y,z) | |
| 895 | end | |
| 896 | - | Yiterate() |
| 896 | + | |
| 897 | function check(x,y,z) | |
| 898 | if x%2==0 then | |
| 899 | evenx = true | |
| 900 | if y%2==0 then | |
| 901 | eveny = true | |
| 902 | else | |
| 903 | eveny = false | |
| 904 | end | |
| 905 | else | |
| 906 | - | function Yiterate() |
| 906 | + | |
| 907 | if y%2==0 then | |
| 908 | eveny = false | |
| 909 | else | |
| 910 | eveny = true | |
| 911 | end | |
| 912 | end | |
| 913 | return evenx,eveny | |
| 914 | - | x = 'max' |
| 914 | + | |
| 915 | ||
| 916 | function Yiterate(x,y,z,length,width,height) | |
| 917 | - | error() |
| 917 | + | |
| 918 | - | end |
| 918 | + | |
| 919 | y = y + 1 | |
| 920 | elseif y == width then | |
| 921 | if x < height then | |
| 922 | x = x + 1 | |
| 923 | elseif x == height then | |
| 924 | x,y,z = "max","max","max" | |
| 925 | end | |
| 926 | end | |
| 927 | else | |
| 928 | if y == 0 then | |
| 929 | if x < height then | |
| 930 | x = x + 1 | |
| 931 | elseif x == height then | |
| 932 | x = "max" | |
| 933 | y = "max" | |
| 934 | z = "max" | |
| 935 | end | |
| 936 | else | |
| 937 | y=y-1 | |
| 938 | end | |
| 939 | end | |
| 940 | return x,y,z | |
| 941 | end | |
| 942 | ||
| 943 | function iterate(x,y,z,length,width,height) | |
| 944 | evenx,eveny = check(x,y,z) | |
| 945 | if z == length and eveny then | |
| 946 | x,y,z = Yiterate(x,y,z,length,width,height) | |
| 947 | elseif z==length and (not eveny) then | |
| 948 | z = z - 1 | |
| 949 | - | local ObjectivesList = {}
|
| 949 | + | |
| 950 | z = z + 1 | |
| 951 | - | while x do |
| 951 | + | |
| 952 | x,y,z = Yiterate(x,y,z,length,width,height) | |
| 953 | elseif z < length then | |
| 954 | if eveny then | |
| 955 | z = z + 1 | |
| 956 | else | |
| 957 | z = z - 1 | |
| 958 | end | |
| 959 | end | |
| 960 | return x,y,z | |
| 961 | end | |
| 962 | ||
| 963 | function checkIfAir() | |
| 964 | while true do | |
| 965 | iterate() | |
| 966 | blockID2 = getBlockId(x,y,z) | |
| 967 | blockData2 = getData(x,y,z) | |
| 968 | if slots[blockID2] then | |
| 969 | slot_2nd = slots[blockID2][blockData2] | |
| 970 | if slot_2nd then | |
| 971 | if #slot_2nd > 0 then | |
| 972 | recordObj(x,y,z) | |
| 973 | break | |
| 974 | end | |
| 975 | end | |
| 976 | end | |
| 977 | end | |
| 978 | end | |
| 979 | ||
| 980 | function checkIfAir2(slots,height,width,length) | |
| 981 | ObjectivesList = {}
| |
| 982 | x,y,z = 0,0,0 | |
| 983 | while true do | |
| 984 | if type(x) ~= "number" then | |
| 985 | break | |
| 986 | end | |
| 987 | local id = getBlockId(x,y,z) | |
| 988 | local data = getData(x,y,z) | |
| 989 | if slots[id] and #slots[id][data] > 0 then | |
| 990 | table.insert(ObjectivesList,{
| |
| 991 | x = x, | |
| 992 | y = y, | |
| 993 | z = z, | |
| 994 | id = id, | |
| 995 | data = data, | |
| 996 | slotNums = slots[id][data], | |
| 997 | }) | |
| 998 | end | |
| 999 | print(x,y,z) | |
| 1000 | x,y,z = iterate(x,y,z,height,width,length) | |
| 1001 | end | |
| 1002 | return ObjectivesList | |
| 1003 | end | |
| 1004 | ||
| 1005 | function autorun() | |
| 1006 | --get the current coords | |
| 1007 | --get the iterater/goal block location | |
| 1008 | while true do | |
| 1009 | shell.run("position")
| |
| 1010 | shell.run("objective")
| |
| 1011 | goto(x,y,z) | |
| 1012 | findNextBlock(x,y,z) | |
| 1013 | checkIfAir() | |
| 1014 | end | |
| 1015 | shell.run("clr")
| |
| 1016 | print("finished")
| |
| 1017 | end | |
| 1018 | ||
| 1019 | function autorun2() | |
| 1020 | while true do | |
| 1021 | shell.run("position")
| |
| 1022 | shell.run("objective2")
| |
| 1023 | goto(ObjectivesList[num].x,ObjectivesList[num].y,ObjectivesList[num].z) | |
| 1024 | turtle.select(ObjectivesList[num].slotNums[1]) | |
| 1025 | place() | |
| 1026 | recordObjNum(num+1) | |
| 1027 | end | |
| 1028 | shell.run("clr")
| |
| 1029 | print("finished")
| |
| 1030 | ||
| 1031 | end |