SHOW:
|
|
- or go back to the newest paste.
| 1 | local tArgs = { ... }
| |
| 2 | if #tArgs ~= 1 then | |
| 3 | - | print( "Usage: excavate <diameter>" ) |
| 3 | + | print( "Usage: stairs <deepth>" ) |
| 4 | return | |
| 5 | end | |
| 6 | ||
| 7 | - | -- Mine in a quarry pattern until we hit something we can't dig |
| 7 | + | local deepth = tArgs[1]; |
| 8 | - | local size = tonumber( tArgs[1] ) |
| 8 | + | |
| 9 | - | if size < 1 then |
| 9 | + | -- left: 1 |
| 10 | - | print( "Excavate diameter must be positive" ) |
| 10 | + | -- forward: 2 |
| 11 | -- right: 3 | |
| 12 | ||
| 13 | local direction = 2; | |
| 14 | - | local depth = 0 |
| 14 | + | local xPos = -1; |
| 15 | - | local collected = 0 |
| 15 | + | local yPos = 0; |
| 16 | local zPos = 0; | |
| 17 | - | local xPos,zPos = 0,0 |
| 17 | + | |
| 18 | - | local xDir,zDir = 0,1 |
| 18 | + | |
| 19 | if (direction == 1) then | |
| 20 | - | local function dropUseless() |
| 20 | + | return false |
| 21 | - | local x = turtle.getItemCount(1); |
| 21 | + | |
| 22 | - | if (x > 1) then |
| 22 | + | turtle.left(); |
| 23 | - | turtle.drop(x-1); |
| 23 | + | direction = direction - 1; |
| 24 | return true; | |
| 25 | end | |
| 26 | ||
| 27 | - | local function collect() |
| 27 | + | |
| 28 | - | collected = collected + 1 |
| 28 | + | if (direction == 3) then |
| 29 | - | if math.fmod(collected, 25) == 0 then |
| 29 | + | return false |
| 30 | - | print( "Mined "..collected.." blocks." ) |
| 30 | + | |
| 31 | turtle.right(); | |
| 32 | direction = direction + 1; | |
| 33 | - | dropUseless(); |
| 33 | + | return true; |
| 34 | end | |
| 35 | - | for n=1,9 do |
| 35 | + | |
| 36 | - | if turtle.getItemCount(n) == 0 then |
| 36 | + | local function perforate() |
| 37 | - | return true |
| 37 | + | local result = turtle.dig(); |
| 38 | turtle.drop(); | |
| 39 | os.sleep(0.8); | |
| 40 | return result; | |
| 41 | - | print( "No empty slots left." ) |
| 41 | + | |
| 42 | - | return false |
| 42 | + | |
| 43 | local function perforate() | |
| 44 | local result = turtle.digDown(); | |
| 45 | - | local function tryForwards() |
| 45 | + | turtle.drop(); |
| 46 | - | while not turtle.forward() do |
| 46 | + | os.sleep(0.8); |
| 47 | - | if turtle.dig() then |
| 47 | + | return result; |
| 48 | - | if not collect() then |
| 48 | + | |
| 49 | - | return false |
| 49 | + | |
| 50 | - | end |
| 50 | + | local function advance() |
| 51 | - | else |
| 51 | + | if (turtle.detect()) then |
| 52 | - | -- give sand a chance to fall |
| 52 | + | if (not perforate()) then |
| 53 | - | sleep(0.8) |
| 53 | + | return false; |
| 54 | - | if turtle.dig() then |
| 54 | + | end |
| 55 | - | if not collect() then |
| 55 | + | |
| 56 | - | return false |
| 56 | + | turtle.forward(); |
| 57 | - | end |
| 57 | + | if (direction == 2) then |
| 58 | - | else |
| 58 | + | xPos = xPos + 1; |
| 59 | - | return false |
| 59 | + | elseif (direction == 1) then |
| 60 | - | end |
| 60 | + | yPos = yPos - 1; |
| 61 | - | end |
| 61 | + | elseif (direction == 3) then |
| 62 | yPos = yPos + 1; | |
| 63 | - | xPos = xPos + xDir |
| 63 | + | end |
| 64 | - | zPos = zPos + zDir |
| 64 | + | return true; |
| 65 | - | return true |
| 65 | + | |
| 66 | ||
| 67 | local function advanceUp() | |
| 68 | - | local function tryDown() |
| 68 | + | turtle.up(); |
| 69 | - | if not turtle.down() then |
| 69 | + | zPos = zPos + 1; |
| 70 | - | if turtle.digDown() then |
| 70 | + | return true; |
| 71 | - | if not collect() then |
| 71 | + | |
| 72 | - | return false |
| 72 | + | |
| 73 | - | end |
| 73 | + | local function advanceDown() |
| 74 | - | end |
| 74 | + | if (turtle.detectDown()) then |
| 75 | - | if not turtle.down() then |
| 75 | + | if (not perforateDown()) then |
| 76 | - | return false |
| 76 | + | return false; |
| 77 | end | |
| 78 | end | |
| 79 | - | depth = depth + 1 |
| 79 | + | |
| 80 | - | if math.fmod( depth, 10 ) == 0 then |
| 80 | + | turtle.down(); |
| 81 | - | print( "Descended "..depth.." metres." ) |
| 81 | + | zPos = zPos - 1; |
| 82 | return true; | |
| 83 | - | return true |
| 83 | + | |
| 84 | ||
| 85 | local blockEnd = true; | |
| 86 | local done = false; | |
| 87 | - | turtle.turnLeft() |
| 87 | + | |
| 88 | - | xDir, zDir = -zDir, xDir |
| 88 | + | turnRight(); |
| 89 | ||
| 90 | ||
| 91 | local movement = {}
| |
| 92 | - | turtle.turnRight() |
| 92 | + | movement[0] = advance; |
| 93 | - | xDir, zDir = zDir, -xDir |
| 93 | + | movement[1] = advanceUp; |
| 94 | movement[2] = advanceDown; | |
| 95 | movement[3] = turnLeft; | |
| 96 | - | print( "Excavating..." ) |
| 96 | + | movement[4] = turnRight; |
| 97 | ||
| 98 | - | local reseal = false |
| 98 | + | local blockUp = {3,0,2,3,0,0,0,4,4,1,0,0,0,3,3,1,0,0,0,4,4,1,0,0,0};
|
| 99 | - | if turtle.digDown() then |
| 99 | + | local blockDown = {3,2,0,3,0,0,0,2,4,4,0,0,0,2,3,3,0,0,0,2,4,4,0,0,0};
|
| 100 | - | reseal = true |
| 100 | + | |
| 101 | while (not done) do | |
| 102 | local block; | |
| 103 | - | local alternate = 0 |
| 103 | + | if (isDown) then |
| 104 | - | local done = false |
| 104 | + | block = blockDown; |
| 105 | - | while not done do |
| 105 | + | |
| 106 | - | for n=1,size do |
| 106 | + | block = blockUp; |
| 107 | - | for m=1,size-1 do |
| 107 | + | |
| 108 | - | if not tryForwards() then |
| 108 | + | |
| 109 | - | done = true |
| 109 | + | for n = 1,#block do |
| 110 | - | break |
| 110 | + | local mov = block[n]; |
| 111 | - | end |
| 111 | + | if (not movement[mov]()) then |
| 112 | done = true; | |
| 113 | - | if done then |
| 113 | + | break; |
| 114 | - | break |
| 114 | + | |
| 115 | end | |
| 116 | - | if n<size then |
| 116 | + | deepth = deepth - 1; |
| 117 | - | if math.fmod(n + alternate,2) == 0 then |
| 117 | + | if (deepth == 0) then |
| 118 | - | turnLeft() |
| 118 | + | break; |
| 119 | - | if not tryForwards() then |
| 119 | + | |
| 120 | - | done = true |
| 120 | + | |
| 121 | - | break |
| 121 | + | |
| 122 | - | end |
| 122 | + | print("Ended with no errors!"); |