SHOW:
|
|
- or go back to the newest paste.
| 1 | - | -- Tunnel script V2.1 -- |
| 1 | + | -- Tunnel script Unnoficial Fixed 2.1 -- |
| 2 | -- By Ninetainedo -- NoFake Dev Team-- | |
| 3 | -- English Comments, additional comments, and Wall gravel fix by Ryusho, but mostly his friend. -- | |
| 4 | - | |
| 4 | + | |
| 5 | ||
| 6 | args = {...}
| |
| 7 | local width, height, length = 3, 3, 10 | |
| 8 | - | |
| 8 | + | |
| 9 | ||
| 10 | if (#args == 1 and args[1] == "-c") then | |
| 11 | config = true | |
| 12 | elseif #args ~= 1 then | |
| 13 | shell.run("clear")
| |
| 14 | print("Usage : tunnel option\n")
| |
| 15 | print("Option can be :")
| |
| 16 | print(" -c to run in config mode.")
| |
| 17 | print(" -d to run in default mode.\n")
| |
| 18 | print("In default mode, it makes a 3x3x10 tunnel and fills walls, floor and ceiling.\nIt also empties itself and comes back when it needs blocks.")
| |
| 19 | return | |
| 20 | - | |
| 20 | + | |
| 21 | ||
| 22 | local name = "Tunnel" | |
| 23 | local side, x, y, z = 0, 0, 0, 0 | |
| 24 | local moved = 0 | |
| 25 | local a, b, c | |
| 26 | local blockSlotsToKeep = 8 | |
| 27 | local slots = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
| |
| 28 | local goBackForCobble, goBackForEmpty, digOnly, sendOnRednet = true, true, false, true | |
| 29 | local fillCeiling, fillFloor, fillLeftWall, fillRightWall, fillBackWall = true, true, true, true, true | |
| 30 | local pos = "left" | |
| 31 | local percent, oldPercent = 0, -1 | |
| 32 | local wTerm, hTerm = term.getSize() | |
| 33 | local screen = {}
| |
| 34 | local messages = {}
| |
| 35 | local percent = 50 | |
| 36 | local msgLen = math.ceil(hTerm / 2) - 2 | |
| 37 | local currentMsgIndex = 1 | |
| 38 | local infos = { blocksDug = 0, blocksPlaced = 0}
| |
| 39 | - | |
| 39 | + | |
| 40 | ||
| 41 | function main() | |
| 42 | shell.run("clear")
| |
| 43 | if (config == true) then | |
| 44 | configMode() | |
| 45 | - | |
| 45 | + | |
| 46 | ||
| 47 | if (sendOnRednet) then | |
| 48 | rednet.open("right")
| |
| 49 | - | |
| 49 | + | |
| 50 | ||
| 51 | screenQuery("init")
| |
| 52 | tell("Launching !")
| |
| 53 | checkBlock() | |
| 54 | - | |
| 54 | + | |
| 55 | - | -- Boucle sur la longueur -- |
| 55 | + | |
| 56 | -- Loop on the Length -- | |
| 57 | while (a < length) do | |
| 58 | b = 0 | |
| 59 | if (side == 3) then | |
| 60 | turnRight() | |
| 61 | elseif (side == 1) then | |
| 62 | turnLeft() | |
| 63 | end | |
| 64 | if (turtle.detect()) then dig() end | |
| 65 | - | |
| 65 | + | |
| 66 | - | -- Boucle de balayage vertical -- |
| 66 | + | |
| 67 | -- Loop Vertical Scanning -- | |
| 68 | while (b < height) do | |
| 69 | c = 0 | |
| 70 | if (side == 0 and pos == "left") then | |
| 71 | turnLeft() | |
| 72 | elseif (side == 0 and pos == "right") then | |
| 73 | turnRight() | |
| 74 | end | |
| 75 | putBlock() | |
| 76 | if (pos == "right") then | |
| 77 | turnLeft() | |
| 78 | elseif (pos == "left") then | |
| 79 | turnRight() | |
| 80 | end | |
| 81 | if (side == 0 and pos == "right") then | |
| 82 | turnLeft() | |
| 83 | elseif (side == 0 and pos == "left") then | |
| 84 | turnRight() | |
| 85 | - | |
| 85 | + | |
| 86 | - | -- Boucle de balayage horizontal -- |
| 86 | + | |
| 87 | -- Loop Horizontal Scanning -- | |
| 88 | while (c < width) do | |
| 89 | if (c == width - 1) then | |
| 90 | putBlock() | |
| 91 | end | |
| 92 | if (z == 0) then | |
| 93 | putBlock("down")
| |
| 94 | end | |
| 95 | if (z == height - 1) then | |
| 96 | putBlock("up")
| |
| 97 | end | |
| 98 | ||
| 99 | if (not digOnly and fillBackWall and a == length - 1) then | |
| 100 | if (pos == "left") then | |
| 101 | turnLeft() | |
| 102 | else | |
| 103 | turnRight() | |
| 104 | end | |
| 105 | putBlock() | |
| 106 | if (pos == "right") then | |
| 107 | turnLeft() | |
| 108 | else | |
| 109 | turnRight() | |
| 110 | end | |
| 111 | - | |
| 111 | + | |
| 112 | ||
| 113 | if (c < width - 1) then | |
| 114 | if (turtle.detect()) then dig() end | |
| 115 | end | |
| 116 | if (z < height - 1) then | |
| 117 | if (turtle.detectUp()) then dig("up") end
| |
| 118 | end | |
| 119 | if (c < width - 1) then | |
| 120 | forward() | |
| 121 | end | |
| 122 | c = c + 1 | |
| 123 | checkBlock() | |
| 124 | checkInventory() | |
| 125 | updatePercent() | |
| 126 | end -- While y | |
| 127 | if (z < height - 1) then | |
| 128 | up() | |
| 129 | end | |
| 130 | if (pos == "left") then | |
| 131 | pos = "right" | |
| 132 | else | |
| 133 | pos = "left" | |
| 134 | end | |
| 135 | b = b + 1 | |
| 136 | end -- While z | |
| 137 | while (z ~= 0) do down() end | |
| 138 | a = a + 1 | |
| 139 | end -- While x | |
| 140 | goToPos(-1 * x, -1 * y, -1 * z, -1 * side, "szyx") | |
| 141 | - | |
| 141 | + | |
| 142 | ||
| 143 | if (sendOnRednet) then | |
| 144 | rednet.close("right")
| |
| 145 | end | |
| 146 | - | |
| 146 | + | |
| 147 | ||
| 148 | function updatePercent() | |
| 149 | percent = math.floor(reMap(p, 0, length * width * height, 0, 100)) | |
| 150 | screenQuery("update", "progress", percent)
| |
| 151 | screenQuery("draw")
| |
| 152 | - | |
| 152 | + | |
| 153 | ||
| 154 | function reMap(val, min1, max1, min2, max2) | |
| 155 | - | |
| 155 | + | |
| 156 | ||
| 157 | if (div == 0) then div = 1 end | |
| 158 | return ((val - min1) * (max2 - min2) / div + min2) | |
| 159 | - | |
| 159 | + | |
| 160 | ||
| 161 | function screenQuery(query, ...) | |
| 162 | local tArgs = {...}
| |
| 163 | local writeAtPos = function(message, x, y) | |
| 164 | term.setCursorPos(x, y) | |
| 165 | write(message) | |
| 166 | end | |
| 167 | local getCenteredX = function(message) | |
| 168 | return math.ceil((wTerm / 2) - (#message / 2)) | |
| 169 | end | |
| 170 | local writeInTable = function(message, x, y) | |
| 171 | if (x + #message > wTerm) then | |
| 172 | return false | |
| 173 | end | |
| 174 | for i = 1, #message do | |
| 175 | screen[y][x + i - 1] = message:sub(i, i) | |
| 176 | end | |
| 177 | return true | |
| 178 | end | |
| 179 | local printProgressBar = function(percent) | |
| 180 | local y = math.ceil(hTerm / 2 * 3 / 2) | |
| 181 | local barPercent = reMap(percent, 0, 100, 4, wTerm - 2) | |
| 182 | - | |
| 182 | + | |
| 183 | ||
| 184 | screen[y][3] = '[' | |
| 185 | screen[y][wTerm - 2] = ']' | |
| 186 | while (a < barPercent) do | |
| 187 | screen[y][a] = '=' | |
| 188 | a = a + 1 | |
| 189 | end | |
| 190 | writeInTable(tostring(percent).."%", getCenteredX(tostring(percent).."%") + 1, y + 1) | |
| 191 | - | |
| 191 | + | |
| 192 | ||
| 193 | if (query == "init") then | |
| 194 | local mid = math.ceil(hTerm / 2) | |
| 195 | for j = 1, hTerm do | |
| 196 | screen[j] = {}
| |
| 197 | for i = 1, wTerm do | |
| 198 | if ((i == 1 or i == wTerm) and (j == 1 or j == hTerm)) then | |
| 199 | screen[j][i] = '+' | |
| 200 | elseif (i == 1 or i == wTerm) then | |
| 201 | screen[j][i] = '|' | |
| 202 | elseif (j == 1 or j == hTerm) then | |
| 203 | screen[j][i] = '-' | |
| 204 | elseif (j == mid) then | |
| 205 | screen[j][i] = '-' | |
| 206 | else | |
| 207 | screen[j][i] = ' ' | |
| 208 | end | |
| 209 | end | |
| 210 | end | |
| 211 | printProgressBar(0) | |
| 212 | for j = 1, msgLen do | |
| 213 | messages[j] = "" | |
| 214 | end | |
| 215 | elseif (query == "draw") then | |
| 216 | for j = 1, hTerm do | |
| 217 | for i = 1, wTerm do | |
| 218 | writeAtPos(screen[j][i], i, j) | |
| 219 | end | |
| 220 | end | |
| 221 | elseif (query == "update" and tArgs[1] == "progress") then | |
| 222 | printProgressBar(tArgs[2]) | |
| 223 | elseif (query == "update" and tArgs[1] == "message") then | |
| 224 | messages[currentMsgIndex] = tArgs[2] | |
| 225 | for j = 1, msgLen do | |
| 226 | writeInTable(messages[j], 2, j + 1) | |
| 227 | end | |
| 228 | if (currentMsgIndex + 1 > msgLen)then | |
| 229 | table.remove(messages, 1) | |
| 230 | currentMsgIndex = msgLen | |
| 231 | else | |
| 232 | currentMsgIndex = currentMsgIndex + 1 | |
| 233 | end | |
| 234 | end | |
| 235 | - | |
| 235 | + | |
| 236 | ||
| 237 | function checkInventory() | |
| 238 | - | |
| 238 | + | |
| 239 | ||
| 240 | if (goBackForEmpty and isInventoryFull()) then | |
| 241 | tell("Need empty")
| |
| 242 | goToPos(-1 * x, -1 * y, -1 * z, -1 * side, "szyx") | |
| 243 | turtle.turnLeft() | |
| 244 | turtle.turnLeft() | |
| 245 | for i = 2,16 do | |
| 246 | turtle.select(i) | |
| 247 | if (count >= blockSlotsToKeep or not turtle.compareTo(1)) then | |
| 248 | turtle.drop() | |
| 249 | else | |
| 250 | count = count + 1 | |
| 251 | end | |
| 252 | end | |
| 253 | turtle.select(1) | |
| 254 | tell("Empty done !")
| |
| 255 | turtle.turnRight() | |
| 256 | turtle.turnRight() | |
| 257 | goToPos(x, y, z, side, "zyxs") | |
| 258 | end | |
| 259 | - | |
| 259 | + | |
| 260 | ||
| 261 | function manageInventory() | |
| 262 | local blockSlots = {}
| |
| 263 | - | |
| 263 | + | |
| 264 | - | -- Superposition d'un maximum d'items -- |
| 264 | + | |
| 265 | -- Superposition of a maximum of items -- | |
| 266 | for i, slot in ipairs(slots) do | |
| 267 | turtle.select(slot) | |
| 268 | if (turtle.getItemCount(slot) > 0) then | |
| 269 | for j, slot2 in ipairs(slots) do | |
| 270 | if (slot2 > slot) then | |
| 271 | if (turtle.getItemSpace(slot) == 0) then | |
| 272 | break | |
| 273 | end | |
| 274 | if (turtle.compareTo(slot2)) then | |
| 275 | turtle.select(slot2) | |
| 276 | turtle.transferTo(slot) | |
| 277 | turtle.select(slot) | |
| 278 | end | |
| 279 | end | |
| 280 | end | |
| 281 | end | |
| 282 | - | |
| 282 | + | |
| 283 | - | -- On met tous les items le plus en haut à gauche possible -- |
| 283 | + | |
| 284 | -- We put all items uppermost left as possible -- | |
| 285 | for i, slot in ipairs(slots) do | |
| 286 | if (turtle.getItemCount(slot) == 0) then | |
| 287 | for j, slot2 in ipairs(slots) do | |
| 288 | if (slot2 > slot and turtle.getItemCount(slot2) > 0) then | |
| 289 | turtle.select(slot2) | |
| 290 | turtle.transferTo(slot) | |
| 291 | turtle.select(slot) | |
| 292 | break | |
| 293 | end | |
| 294 | end | |
| 295 | end | |
| 296 | - | |
| 296 | + | |
| 297 | - | -- Chargement des infos de l'inventaire pour la gestion des blocs de remplissage -- |
| 297 | + | |
| 298 | -- Loading information for inventory management filler blocks -- | |
| 299 | for i, slot in ipairs(slots) do | |
| 300 | turtle.select(slot) | |
| 301 | if (turtle.compareTo(1)) then | |
| 302 | table.insert(blockSlots, slot) | |
| 303 | end | |
| 304 | - | |
| 304 | + | |
| 305 | - | -- On cherche un slot vide -- |
| 305 | + | |
| 306 | -- We're looking for an empty slot -- | |
| 307 | for i, slot in ipairs(slots) do | |
| 308 | if (slot > blockSlotsToKeep and turtle.getItemCount(slot) == 0) then | |
| 309 | emptySlot = slot | |
| 310 | break | |
| 311 | end | |
| 312 | - | |
| 312 | + | |
| 313 | ||
| 314 | if (emptySlot == -1) then | |
| 315 | return false | |
| 316 | - | -- On supprime de la table le slot de référence -- |
| 316 | + | |
| 317 | -- It removes the reference table slot -- | |
| 318 | table.remove(blockSlots, 1) | |
| 319 | - | |
| 319 | + | |
| 320 | - | -- Pour chaque emplacement de block qu'on |
| 320 | + | |
| 321 | - | -- veut "reserver", on y place de la block |
| 321 | + | -- for each block location it needs to reserve for filler/wall blocks |
| 322 | - | -- s'il y en a ailleurs -- |
| 322 | + | -- check if the block is in a different slot == |
| 323 | -- -- | |
| 324 | - | -- Ex : Si le slot 2 est vide alors que |
| 324 | + | -- Ex : If Slot 2 is Empty when blocks to keep is 4 |
| 325 | - | -- blockslotsToKeep vaut 4, on va chercher |
| 325 | + | --it will search for the block in slots 3 to 16 |
| 326 | - | -- de la block dans les slots de 3 a 16 et, |
| 326 | + | -- and move the block to slot 2 -- |
| 327 | - | -- si on en trouve, on va la mettre dans le |
| 327 | + | |
| 328 | - | -- slot 2 -- |
| 328 | + | |
| 329 | if (not turtle.compareTo(1) and turtle.getItemCount(i) > 0) then | |
| 330 | if (blockSlotsLen > 0) then | |
| 331 | slotTransfer(blockSlots[1], i, emptySlot) | |
| 332 | table.remove(blockSlots, 1) | |
| 333 | blockSlotsLen = blockSlotsLen - 1 | |
| 334 | else | |
| 335 | break | |
| 336 | end | |
| 337 | end | |
| 338 | end | |
| 339 | end | |
| 340 | ||
| 341 | function slotTransfer(slotSrc, slotDest, slotEmpty) | |
| 342 | - | |
| 342 | + | |
| 343 | ||
| 344 | if (turtle.getItemCount(slotEmpty) > 0) then | |
| 345 | - | |
| 345 | + | |
| 346 | turtle.drop() | |
| 347 | hasEmpty = true | |
| 348 | end | |
| 349 | if (turtle.getItemCount(slotDest) == 0) then | |
| 350 | turtle.select(slotSrc) | |
| 351 | turtle.transferTo(slotDest) | |
| 352 | else | |
| 353 | turtle.select(slotDest) | |
| 354 | turtle.transferTo(slotEmpty) | |
| 355 | turtle.select(slotSrc) | |
| 356 | turtle.transferTo(slotDest) | |
| 357 | turtle.select(slotEmpty) | |
| 358 | turtle.transferTo(slotSrc) | |
| 359 | end | |
| 360 | if (hasEmpty) then | |
| 361 | turtle.suck() | |
| 362 | end | |
| 363 | end | |
| 364 | ||
| 365 | function isInventoryFull(var) | |
| 366 | - | |
| 366 | + | |
| 367 | if (turtle.getItemCount(slot) == 0) then | |
| 368 | return false | |
| 369 | end | |
| 370 | end | |
| 371 | if (not var) then | |
| 372 | manageInventory() | |
| 373 | return isInventoryFull(true) | |
| 374 | end | |
| 375 | return true | |
| 376 | end | |
| 377 | ||
| 378 | function putBlock(face) | |
| 379 | - | |
| 379 | + | |
| 380 | ||
| 381 | if (digOnly) then | |
| 382 | - | |
| 382 | + | |
| 383 | end | |
| 384 | ||
| 385 | if (face == nil) then | |
| 386 | - | |
| 386 | + | |
| 387 | -- While the space here is not the block we want, do what has to in order to clear the space -- | |
| 388 | while ( not turtle.compare() ) do | |
| 389 | - | if (not turtle.detect()) then |
| 389 | + | -- Try and place our block, if that fails, clear the space. This should account for water and lava tiles |
| 390 | - | while (not turtle.place()) do |
| 390 | + | if ( not turtle.place() ) then |
| 391 | -- If there is no block in the space, must be an enemy | |
| 392 | if (not turtle.detect() ) then | |
| 393 | - | infos.blocksPlaced = infos.blocksPlaced + 1 |
| 393 | + | turtle.attack() |
| 394 | - | elseif (not turtle.compare()) then |
| 394 | + | -- If we did detect a block, then dig that block -- |
| 395 | - | dig() |
| 395 | + | else |
| 396 | - | while (not turtle.place()) do |
| 396 | + | turtle.dig() |
| 397 | end | |
| 398 | end | |
| 399 | - | infos.blocksPlaced = infos.blocksPlaced + 1 |
| 399 | + | end |
| 400 | -- Increase the blocks placed by 1 for the one we just put down -- | |
| 401 | infos.blocksPlaced = infos.blocksPlaced + 1 | |
| 402 | end | |
| 403 | elseif (face == "up") then | |
| 404 | - | if (not turtle.detectUp()) then |
| 404 | + | |
| 405 | - | while (not turtle.placeUp()) do |
| 405 | + | -- While the space here is not the block we want, do what has to in order to clear the space -- |
| 406 | while ( not turtle.compareUp() ) do | |
| 407 | -- Try and place our block, if that fails, clear the space. This should account for water and lava tiles | |
| 408 | - | infos.blocksPlaced = infos.blocksPlaced + 1 |
| 408 | + | if ( not turtle.placeUp() ) then |
| 409 | - | elseif (not turtle.compareUp()) then |
| 409 | + | -- If there is no block in the space, must be an enemy |
| 410 | - | dig("up")
|
| 410 | + | if (not turtle.detectUp() ) then |
| 411 | - | while (not turtle.placeUp()) do |
| 411 | + | turtle.attackUp() |
| 412 | -- If we did detect a block, then dig that block -- | |
| 413 | else | |
| 414 | - | infos.blocksPlaced = infos.blocksPlaced + 1 |
| 414 | + | turtle.digUp() |
| 415 | end | |
| 416 | end | |
| 417 | end | |
| 418 | -- Increase the blocks placed by 1 for the one we just put down -- | |
| 419 | - | if (not turtle.detectDown()) then |
| 419 | + | infos.blocksPlaced = infos.blocksPlaced + 1 |
| 420 | - | while (not turtle.placeDown()) do |
| 420 | + | |
| 421 | elseif (face == "down") then | |
| 422 | if (fillFloor) then | |
| 423 | - | infos.blocksPlaced = infos.blocksPlaced + 1 |
| 423 | + | -- While the space here is not the block we want, do what has to in order to clear the space -- |
| 424 | - | elseif (not turtle.compareDown()) then |
| 424 | + | while ( not turtle.compareDown() ) do |
| 425 | - | dig("down")
|
| 425 | + | -- Try and place our block, if that fails, clear the space. This should account for water and lava tiles |
| 426 | - | while (not turtle.placeDown()) do |
| 426 | + | if ( not turtle.placeDown() ) then |
| 427 | -- If there is no block in the space, must be an enemy | |
| 428 | if (not turtle.detectDown() ) then | |
| 429 | - | infos.blocksPlaced = infos.blocksPlaced + 1 |
| 429 | + | turtle.attackDown() |
| 430 | -- If we did detect a block, then dig that block -- | |
| 431 | else | |
| 432 | turtle.digDown() | |
| 433 | end | |
| 434 | - | |
| 434 | + | end |
| 435 | end | |
| 436 | -- Increase the blocks placed by 1 for the one we just put down -- | |
| 437 | - | |
| 437 | + | infos.blocksPlaced = infos.blocksPlaced + 1 |
| 438 | end | |
| 439 | end | |
| 440 | end | |
| 441 | ||
| 442 | function readPrompt(prompt, mode, onError, onSuccess, needClear, stricly) | |
| 443 | local value = nil | |
| 444 | ||
| 445 | while (value == nil) do | |
| 446 | if (needClear) then | |
| 447 | shell.run("clear")
| |
| 448 | end | |
| 449 | write(prompt) | |
| 450 | value = read() | |
| 451 | if (mode == 1) then | |
| 452 | value = tonumber(value) | |
| 453 | if (value == nil or (stricly and value <= 0)) then | |
| 454 | onError() | |
| 455 | value = nil | |
| 456 | end | |
| 457 | elseif (mode == 2) then | |
| 458 | if (value ~= "y" and value ~= "n") then | |
| 459 | onError() | |
| 460 | - | |
| 460 | + | |
| 461 | end | |
| 462 | end | |
| 463 | end | |
| 464 | onSuccess() | |
| 465 | return value | |
| 466 | end | |
| 467 | ||
| 468 | function configMode() | |
| 469 | local isOk = false | |
| 470 | local widTmp, heiTmp, lenTmp, tmpBlockSlotsToKeep = nil, nil, nil, nil | |
| 471 | local goBackForCobbleTmp, goBackToEmptyTmp, sendOnRednetTmp = nil, nil, nil | |
| 472 | local fillLeftWallTmp, fillRightWallTmp, fillFloorTmp, fillCeilingTmp, fillBackWallTmp = nil, nil, nil, nil, nil | |
| 473 | local digOnlyTmp = nil | |
| 474 | local timeToWait = 0 | |
| 475 | local success = function() | |
| 476 | print("Hum... Ok !")
| |
| 477 | os.sleep(timeToWait) | |
| 478 | end | |
| 479 | local numberError = function() | |
| 480 | - | |
| 480 | + | |
| 481 | os.sleep(timeToWait) | |
| 482 | end | |
| 483 | local ynError = function() | |
| 484 | print("I told you to ask y or n.")
| |
| 485 | os.sleep(timeToWait) | |
| 486 | end | |
| 487 | ||
| 488 | while (not isOk) do | |
| 489 | widTmp = readPrompt("Tunnel width : ", 1, numberError, success, true, true)
| |
| 490 | heiTmp = readPrompt("Tunnel height : ", 1, numberError, success, true, true)
| |
| 491 | lenTmp = readPrompt("Tunnel length : ", 1, numberError, success, true, true)
| |
| 492 | digOnlyTmp = readPrompt("Run in dig only ? (y/n) ", 2, ynError, success, true)
| |
| 493 | if (digOnlyTmp == "n") then | |
| 494 | fillLeftWallTmp = readPrompt("Should I fill the left wall ? (y/n) ", 2, ynError, success, true)
| |
| 495 | fillRightWallTmp = readPrompt("Should I fill the right wall ? (y/n) ", 2, ynError, success, true)
| |
| 496 | fillBackWallTmp = readPrompt("Should I fill the back wall ? (y/n) ", 2, ynError, success, true)
| |
| 497 | fillFloorTmp = readPrompt("Should I fill the floor ? (y/n) ", 2, ynError, success, true)
| |
| 498 | fillCeilingTmp = readPrompt("Should I fill the ceiling ? (y/n) ", 2, ynError, success, true)
| |
| 499 | if (fillLeftWallTmp == "n" and fillRightWallTmp == "n" and fillBackWallTmp == "n" and fillFloorTmp == "n" and fillCeilingTmp == "n") then | |
| 500 | digOnlyTmp = "y" | |
| 501 | end | |
| 502 | end | |
| 503 | if (digOnlyTmp == "n") then | |
| 504 | tmpBlockSlotsToKeep = readPrompt("How many slots do you want me to keep for filling blocks ? ", 1, numberError, success, true, true)
| |
| 505 | goBackForCobbleTmp = readPrompt("Should I go back to start when I need filling blocks ? (y/n) ", 2, ynError, success, true)
| |
| 506 | end | |
| 507 | goBackToEmptyTmp = readPrompt("Should I empty when I'm full ? (y/n) ", 2, ynError, success, true)
| |
| 508 | sendOnRednetTmp = readPrompt("Should I send infos on rednet ? (y/n) ", 2, ynError, success, true)
| |
| 509 | shell.run("clear")
| |
| 510 | print("Tunnel w = "..widTmp.." h = "..heiTmp.." l = "..lenTmp)
| |
| 511 | print("Dig Only : "..digOnlyTmp)
| |
| 512 | if (digOnlyTmp == "n") then | |
| 513 | print("Fill left wall : "..fillLeftWallTmp)
| |
| 514 | print("Fill right wall : "..fillRightWallTmp)
| |
| 515 | print("Fill back wall : "..fillBackWallTmp)
| |
| 516 | print("Fill floor wall : "..fillFloorTmp)
| |
| 517 | print("Fill ceiling wall : "..fillCeilingTmp)
| |
| 518 | print("Blocks to keep : "..tmpBlockSlotsToKeep)
| |
| 519 | print("Back when need blocks : "..goBackForCobbleTmp)
| |
| 520 | end | |
| 521 | print("Empty when full : "..goBackToEmptyTmp)
| |
| 522 | print("Infos on rednet : "..sendOnRednetTmp)
| |
| 523 | print("")
| |
| 524 | isOk = readPrompt("Is this ok for you ? (y/n) ", 2, ynError, success, false)
| |
| 525 | - | |
| 525 | + | |
| 526 | end | |
| 527 | width = widTmp | |
| 528 | height = heiTmp | |
| 529 | length = lenTmp | |
| 530 | blockSlotsToKeep = tmpBlockSlotsToKeep | |
| 531 | - | |
| 531 | + | |
| 532 | ||
| 533 | if (fillLeftWallTmp == "y") then fillLeftWall = true else fillLeftWall = false end | |
| 534 | if (fillRightWallTmp == "y") then fillRightWall = true else fillRightWall = false end | |
| 535 | if (fillBackWallTmp == "y") then fillBackWall = true else fillBackWall = false end | |
| 536 | - | |
| 536 | + | |
| 537 | if (fillFloorTmp == "y") then fillFloor = true else fillFloor = false end | |
| 538 | ||
| 539 | - | while (turtle.detect()) do |
| 539 | + | |
| 540 | - | while (not turtle.dig()) do |
| 540 | + | |
| 541 | - | turtle.attack() |
| 541 | + | |
| 542 | end | |
| 543 | - | os.sleep(0.4) |
| 543 | + | |
| 544 | - | infos.blocksDug = infos.blocksDug + 1 |
| 544 | + | |
| 545 | if (face == nil) then | |
| 546 | -- Detect if there is a block this direction and keep looking till the space is fully clear -- | |
| 547 | - | while (turtle.detectUp()) do |
| 547 | + | while (turtle.detect()) do |
| 548 | - | while (not turtle.digUp()) do |
| 548 | + | turtle.dig() |
| 549 | - | turtle.attackUp() |
| 549 | + | -- Give it some time incase a block falls into place -- |
| 550 | os.sleep(1) | |
| 551 | - | os.sleep(0.4) |
| 551 | + | infos.blocksDug = infos.blocksDug + 1 |
| 552 | - | infos.blocksDug = infos.blocksDug + 1 |
| 552 | + | end |
| 553 | elseif (face == "up") then | |
| 554 | -- Detect if there is a block this direction and keep looking till the space is fully clear -- | |
| 555 | - | while (not turtle.digDown()) do |
| 555 | + | while (turtle.detectUp()) do |
| 556 | - | turtle.attackDown() |
| 556 | + | turtle.digUp() |
| 557 | -- Give it some time incase a block falls into place -- | |
| 558 | - | infos.blocksDug = infos.blocksDug + 1 |
| 558 | + | os.sleep(0.4) |
| 559 | infos.blocksDug = infos.blocksDug + 1 | |
| 560 | end | |
| 561 | - | |
| 561 | + | elseif (face == "down") then |
| 562 | -- Since we are digging down, just dig down whether there is a block or not and carry on -- | |
| 563 | turtle.digDown() | |
| 564 | - | |
| 564 | + | infos.blocksDug = infos.blocksDug + 1 |
| 565 | end | |
| 566 | end | |
| 567 | ||
| 568 | - | |
| 568 | + | |
| 569 | local countBlock = 0 | |
| 570 | ||
| 571 | if (digOnly) then | |
| 572 | return | |
| 573 | end | |
| 574 | - | |
| 574 | + | |
| 575 | if (turtle.getItemCount(1) < 5) then | |
| 576 | manageInventory() | |
| 577 | else | |
| 578 | return | |
| 579 | end | |
| 580 | ||
| 581 | - | |
| 581 | + | |
| 582 | turtle.select(i) | |
| 583 | if (turtle.compareTo(1)) then | |
| 584 | countBlock = countBlock + turtle.getItemCount(i) | |
| 585 | end | |
| 586 | end | |
| 587 | ||
| 588 | if (countBlock < 5 and goBackForCobble) then | |
| 589 | tell("Need block !")
| |
| 590 | if (moved == 0) then goToPos(-1 * x, -1 * y, -1 * z, -1 * side, "szyx") end | |
| 591 | moved = 1 | |
| 592 | os.sleep(10) | |
| 593 | return checkBlock() | |
| 594 | end | |
| 595 | - | |
| 595 | + | |
| 596 | tell("Going back to work !")
| |
| 597 | goToPos(x, y, z, side, "zyxs") | |
| 598 | moved = 0 | |
| 599 | end | |
| 600 | end | |
| 601 | - | |
| 601 | + | |
| 602 | function left() | |
| 603 | turnLeft() | |
| 604 | forward() | |
| 605 | turnRight() | |
| 606 | end | |
| 607 | ||
| 608 | function forward() | |
| 609 | while (not turtle.forward()) do | |
| 610 | turtle.attack() | |
| 611 | end | |
| 612 | if (side == 0) then | |
| 613 | x = x + 1 | |
| 614 | elseif (side == 1) then | |
| 615 | y = y + 1 | |
| 616 | elseif (side == 2) then | |
| 617 | x = x - 1 | |
| 618 | elseif (side == 3) then | |
| 619 | - | |
| 619 | + | |
| 620 | else | |
| 621 | tell("Unknown side found : "..side)
| |
| 622 | end | |
| 623 | p = p + 1 | |
| 624 | end | |
| 625 | ||
| 626 | function back() | |
| 627 | if (turtle.back()) then | |
| 628 | if (side == 0) then | |
| 629 | x = x - 1 | |
| 630 | elseif (side == 1) then | |
| 631 | y = y - 1 | |
| 632 | elseif (side == 2) then | |
| 633 | x = x + 1 | |
| 634 | elseif (side == 3) then | |
| 635 | y = y + 1 | |
| 636 | else | |
| 637 | tell("Unknown side found : "..side)
| |
| 638 | end | |
| 639 | else | |
| 640 | turtle.turnLeft() | |
| 641 | - | |
| 641 | + | |
| 642 | forward() | |
| 643 | turtle.turnRight() | |
| 644 | turtle.turnRight() | |
| 645 | end | |
| 646 | end | |
| 647 | ||
| 648 | - | |
| 648 | + | |
| 649 | if (turtle.up()) then | |
| 650 | z = z + 1 | |
| 651 | end | |
| 652 | p = p + 1 | |
| 653 | end | |
| 654 | - | |
| 654 | + | |
| 655 | function down() | |
| 656 | if (turtle.down()) then | |
| 657 | z = z - 1 | |
| 658 | end | |
| 659 | end | |
| 660 | ||
| 661 | function turnLeft() | |
| 662 | - | |
| 662 | + | |
| 663 | side = side - 1 | |
| 664 | if (side < 0) then | |
| 665 | side = side + 4 | |
| 666 | end | |
| 667 | end | |
| 668 | ||
| 669 | function turnRight() | |
| 670 | - | |
| 670 | + | |
| 671 | side = side + 1 | |
| 672 | if (side >= 4) then | |
| 673 | side = side - 4 | |
| 674 | end | |
| 675 | end | |
| 676 | - | |
| 676 | + | |
| 677 | function right() | |
| 678 | turnRight() | |
| 679 | forward() | |
| 680 | turnLeft() | |
| 681 | end | |
| 682 | ||
| 683 | function tell(message) | |
| 684 | - | |
| 684 | + | |
| 685 | screenQuery("draw")
| |
| 686 | if (sendOnRednet) then | |
| 687 | rednet.broadcast(name.." "..message) | |
| 688 | end | |
| 689 | end | |
| 690 | ||
| 691 | function goToPos(xTmp, yTmp, zTmp, sideTmp, order) | |
| 692 | local xMove = function() | |
| 693 | while (xTmp ~= 0) do | |
| 694 | if (xTmp > 0) then | |
| 695 | while (not turtle.forward()) do | |
| 696 | turtle.dig() | |
| 697 | turtle.attack() | |
| 698 | os.sleep(0.4) | |
| 699 | end | |
| 700 | xTmp = xTmp - 1 | |
| 701 | else | |
| 702 | if (not turtle.back()) then | |
| 703 | turtle.turnLeft() | |
| 704 | turtle.turnLeft() | |
| 705 | while (not turtle.forward()) do | |
| 706 | turtle.dig() | |
| 707 | turtle.attack() | |
| 708 | os.sleep(0.4) | |
| 709 | end | |
| 710 | turtle.turnRight() | |
| 711 | turtle.turnRight() | |
| 712 | end | |
| 713 | xTmp = xTmp + 1 | |
| 714 | end | |
| 715 | end | |
| 716 | end | |
| 717 | local yMove = function() | |
| 718 | if (yTmp > 0) then | |
| 719 | turtle.turnRight() | |
| 720 | while (yTmp > 0) do | |
| 721 | while (not turtle.forward()) do | |
| 722 | turtle.dig() | |
| 723 | turtle.attack() | |
| 724 | os.sleep(0.4) | |
| 725 | end | |
| 726 | yTmp = yTmp - 1 | |
| 727 | end | |
| 728 | turtle.turnLeft() | |
| 729 | elseif (yTmp < 0) then | |
| 730 | turtle.turnLeft() | |
| 731 | while (yTmp < 0) do | |
| 732 | while (not turtle.forward()) do | |
| 733 | turtle.dig() | |
| 734 | turtle.attack() | |
| 735 | os.sleep(0.4) | |
| 736 | end | |
| 737 | yTmp = yTmp + 1 | |
| 738 | end | |
| 739 | turtle.turnRight() | |
| 740 | end | |
| 741 | end | |
| 742 | local zMove = function() | |
| 743 | while (zTmp ~= 0) do | |
| 744 | if (zTmp < 0) then | |
| 745 | while (not turtle.down()) do | |
| 746 | turtle.attackDown() | |
| 747 | turtle.digDown() | |
| 748 | os.sleep(0.4) | |
| 749 | end | |
| 750 | zTmp = zTmp + 1 | |
| 751 | else | |
| 752 | while (not turtle.up()) do | |
| 753 | turtle.attackUp() | |
| 754 | turtle.digUp() | |
| 755 | os.sleep(0.4) | |
| 756 | end | |
| 757 | zTmp = zTmp - 1 | |
| 758 | end | |
| 759 | end | |
| 760 | end | |
| 761 | local sMove = function() | |
| 762 | while (sideTmp ~= 0) do | |
| 763 | if (sideTmp > 0) then | |
| 764 | turtle.turnRight() | |
| 765 | sideTmp = sideTmp - 1 | |
| 766 | - | |
| 766 | + | |
| 767 | turtle.turnLeft() | |
| 768 | sideTmp = sideTmp + 1 | |
| 769 | end | |
| 770 | end | |
| 771 | end | |
| 772 | ||
| 773 | for a = 1, 4 do | |
| 774 | if (order:sub(a, a) == "x") then | |
| 775 | xMove() | |
| 776 | elseif (order:sub(a, a) == "y") then | |
| 777 | yMove() | |
| 778 | elseif (order:sub(a, a) == "z") then | |
| 779 | - | |
| 779 | + | |
| 780 | - | -- Point de départ du programme -- |
| 780 | + | |
| 781 | sMove() | |
| 782 | end | |
| 783 | end | |
| 784 | end | |
| 785 | ||
| 786 | -- move to program start? -- | |
| 787 | main() |