SHOW:
|
|
- or go back to the newest paste.
| 1 | local args = {...}
| |
| 2 | ||
| 3 | if #args ~= 3 then | |
| 4 | print("Usage: quarry <row length> <number of rows> <current y>")
| |
| 5 | error() | |
| 6 | end | |
| 7 | ||
| 8 | rowLength = args[1] | |
| 9 | rows = args[2] | |
| 10 | startingY = args[3] | |
| 11 | curRow = 1 | |
| 12 | ||
| 13 | y = startingY | |
| 14 | ||
| 15 | function full() | |
| 16 | fullSlots = 0 | |
| 17 | for i=2,15 do | |
| 18 | if turtle.getItemCount(i) > 0 then | |
| 19 | fullSlots = fullSlots + 1 | |
| 20 | end | |
| 21 | end | |
| 22 | print(fullSlots .. " slots are full") | |
| 23 | return(fullSlots == 14) | |
| 24 | end | |
| 25 | ||
| 26 | function checkFuel() | |
| 27 | if turtle.getFuelLevel() < 10 then | |
| 28 | turtle.select(1) | |
| 29 | turtle.refuel(1) | |
| 30 | end | |
| 31 | end | |
| 32 | ||
| 33 | function digMove() | |
| 34 | checkFuel() | |
| 35 | while turtle.detect() do | |
| 36 | turtle.dig() | |
| 37 | os.sleep(0.5) | |
| 38 | end | |
| 39 | turtle.forward() | |
| 40 | turtle.digUp() | |
| 41 | turtle.digDown() | |
| 42 | end | |
| 43 | ||
| 44 | function turn() | |
| 45 | if curRow % 2 == 0 then | |
| 46 | turtle.turnRight() | |
| 47 | else | |
| 48 | turtle.turnLeft() | |
| 49 | end | |
| 50 | end | |
| 51 | ||
| 52 | function dig() | |
| 53 | turtle.digDown() | |
| 54 | turtle.down() | |
| 55 | y = y - 1 | |
| 56 | end | |
| 57 | ||
| 58 | function back() | |
| 59 | turtle.turnLeft() | |
| 60 | for i=1,rows do | |
| 61 | checkFuel() | |
| 62 | turtle.forward() | |
| 63 | end | |
| 64 | turtle.turnLeft() | |
| 65 | end | |
| 66 | ||
| 67 | function up() | |
| 68 | for i=1,(startingY - y) do | |
| 69 | checkFuel() | |
| 70 | turtle.up() | |
| 71 | y = y + 1 | |
| 72 | end | |
| 73 | end | |
| 74 | ||
| 75 | ||
| 76 | function down(x) | |
| 77 | for i=1,x do | |
| 78 | checkFuel() | |
| 79 | dig(x) | |
| 80 | end | |
| 81 | end | |
| 82 | ||
| 83 | function chest() | |
| 84 | turtle.turnLeft() | |
| 85 | turtle.turnLeft() | |
| 86 | for i=2,16 do | |
| 87 | turtle.select(i) | |
| 88 | turtle.drop() | |
| 89 | end | |
| 90 | if turtle.getItemCount(1) < 3 then | |
| 91 | turtle.up() | |
| 92 | turtle.select(1) | |
| 93 | turtle.suck() | |
| 94 | turtle.down() | |
| 95 | end | |
| 96 | turtle.turnRight() | |
| 97 | turtle.turnRight() | |
| 98 | end | |
| 99 | ||
| 100 | function level() | |
| 101 | curRow = 1 | |
| 102 | for i=1,rows do | |
| 103 | for i=1,rowLength-1 do | |
| 104 | digMove() | |
| 105 | end | |
| 106 | if curRow == tonumber(rows) then | |
| 107 | ||
| 108 | else | |
| 109 | turn() | |
| 110 | digMove() | |
| 111 | turn() | |
| 112 | curRow = curRow + 1 | |
| 113 | end | |
| 114 | end | |
| 115 | back() | |
| 116 | tempY = y | |
| 117 | if full() then | |
| 118 | up() | |
| 119 | chest() | |
| 120 | down(startingY - tempY + 3) | |
| 121 | else | |
| 122 | down(3) | |
| 123 | end | |
| 124 | turtle.digDown() | |
| 125 | end | |
| 126 | ||
| 127 | function quarry() | |
| 128 | down(2) | |
| 129 | turtle.digDown() | |
| 130 | while y > 5 do | |
| 131 | level() | |
| 132 | end | |
| 133 | up() | |
| 134 | end | |
| 135 | ||
| 136 | quarry() |