SHOW:
|
|
- or go back to the newest paste.
| 1 | p=peripheral.wrap("right")
| |
| 2 | url = "192.168.1.2:92" | |
| 3 | --url = "tools.uk.ms" | |
| 4 | ||
| 5 | webVarName = "t1blocks" | |
| 6 | ||
| 7 | local tArgs = { ... }
| |
| 8 | if #tArgs ~= 1 then | |
| 9 | print( "Usage: tunnel <length>" ) | |
| 10 | return | |
| 11 | end | |
| 12 | ||
| 13 | -- Mine in a quarry pattern until we hit something we can't dig | |
| 14 | local length = tonumber( tArgs[1] ) | |
| 15 | if length < 1 then | |
| 16 | print( "Tunnel length must be positive" ) | |
| 17 | return | |
| 18 | end | |
| 19 | ||
| 20 | local depth = 0 | |
| 21 | local collected = 0 | |
| 22 | ||
| 23 | local function collect() | |
| 24 | collected = collected + 1 | |
| 25 | while type(http.get("http://" .. url .. "/cc/variables/altervariable.php?cmd=add&var=" .. webVarName)) ~= "table" do
| |
| 26 | sleep(1) | |
| 27 | end | |
| 28 | if math.fmod(collected, 25) == 0 then | |
| 29 | print( "Mined "..collected.." items." ) | |
| 30 | end | |
| 31 | end | |
| 32 | ||
| 33 | local function tryDig() | |
| 34 | while turtle.detect() do | |
| 35 | if turtle.dig() then | |
| 36 | collect() | |
| 37 | sleep(0.5) | |
| 38 | else | |
| 39 | return false | |
| 40 | end | |
| 41 | end | |
| 42 | return true | |
| 43 | end | |
| 44 | ||
| 45 | local function tryDigUp() | |
| 46 | while turtle.detectUp() do | |
| 47 | if turtle.digUp() then | |
| 48 | collect() | |
| 49 | sleep(0.5) | |
| 50 | else | |
| 51 | return false | |
| 52 | end | |
| 53 | end | |
| 54 | return true | |
| 55 | end | |
| 56 | ||
| 57 | local function tryDigDown() | |
| 58 | while turtle.detectDown() do | |
| 59 | if turtle.digDown() then | |
| 60 | collect() | |
| 61 | sleep(0.5) | |
| 62 | else | |
| 63 | return false | |
| 64 | end | |
| 65 | end | |
| 66 | return true | |
| 67 | end | |
| 68 | ||
| 69 | local function refuel() | |
| 70 | local fuelLevel = turtle.getFuelLevel() | |
| 71 | if fuelLevel == "unlimited" or fuelLevel > 0 then | |
| 72 | return | |
| 73 | end | |
| 74 | ||
| 75 | local function tryRefuel() | |
| 76 | for n=1,16 do | |
| 77 | if turtle.getItemCount(n) > 0 then | |
| 78 | turtle.select(n) | |
| 79 | if turtle.refuel(1) then | |
| 80 | turtle.select(1) | |
| 81 | return true | |
| 82 | end | |
| 83 | end | |
| 84 | end | |
| 85 | turtle.select(1) | |
| 86 | return false | |
| 87 | end | |
| 88 | ||
| 89 | if not tryRefuel() then | |
| 90 | print( "Add more fuel to continue." ) | |
| 91 | while not tryRefuel() do | |
| 92 | os.pullEvent( "turtle_inventory" ) | |
| 93 | end | |
| 94 | print( "Resuming Tunnel." ) | |
| 95 | end | |
| 96 | end | |
| 97 | ||
| 98 | local function tryUp() | |
| 99 | refuel() | |
| 100 | while not turtle.up() do | |
| 101 | if turtle.detectUp() then | |
| 102 | if not tryDigUp() then | |
| 103 | return false | |
| 104 | end | |
| 105 | elseif turtle.attackUp() then | |
| 106 | collect() | |
| 107 | else | |
| 108 | sleep( 0.5 ) | |
| 109 | end | |
| 110 | end | |
| 111 | return true | |
| 112 | end | |
| 113 | ||
| 114 | local function tryDown() | |
| 115 | refuel() | |
| 116 | while not turtle.down() do | |
| 117 | if turtle.detectDown() then | |
| 118 | if not tryDigDown() then | |
| 119 | return false | |
| 120 | end | |
| 121 | elseif turtle.attackDown() then | |
| 122 | collect() | |
| 123 | else | |
| 124 | sleep( 0.5 ) | |
| 125 | end | |
| 126 | end | |
| 127 | return true | |
| 128 | end | |
| 129 | ||
| 130 | local function tryForward() | |
| 131 | refuel() | |
| 132 | while not turtle.forward() do | |
| 133 | if turtle.detect() then | |
| 134 | if not tryDig() then | |
| 135 | return false | |
| 136 | end | |
| 137 | elseif turtle.attack() then | |
| 138 | collect() | |
| 139 | else | |
| 140 | sleep( 0.5 ) | |
| 141 | end | |
| 142 | end | |
| 143 | return true | |
| 144 | end | |
| 145 | ||
| 146 | print( "Tunnelling..." ) | |
| 147 | ||
| 148 | for n=1,length do | |
| 149 | turtle.placeDown() | |
| 150 | tryDigUp() | |
| 151 | turtle.turnLeft() | |
| 152 | tryDig() | |
| 153 | tryUp() | |
| 154 | tryDig() | |
| 155 | turtle.turnRight() | |
| 156 | turtle.turnRight() | |
| 157 | tryDig() | |
| 158 | tryDown() | |
| 159 | tryDig() | |
| 160 | turtle.turnLeft() | |
| 161 | ||
| 162 | if n<length then | |
| 163 | tryDig() | |
| 164 | if not tryForward() then | |
| 165 | print( "Aborting Tunnel." ) | |
| 166 | break | |
| 167 | end | |
| 168 | else | |
| 169 | print( "Tunnel complete." ) | |
| 170 | end | |
| 171 | ||
| 172 | end | |
| 173 | ||
| 174 | --[[ | |
| 175 | print( "Returning to start..." ) | |
| 176 | ||
| 177 | -- Return to where we started | |
| 178 | turtle.turnLeft() | |
| 179 | turtle.turnLeft() | |
| 180 | while depth > 0 do | |
| 181 | if turtle.forward() then | |
| 182 | depth = depth - 1 | |
| 183 | else | |
| 184 | turtle.dig() | |
| 185 | end | |
| 186 | end | |
| 187 | turtle.turnRight() | |
| 188 | turtle.turnRight() | |
| 189 | ]] | |
| 190 | ||
| 191 | print( "Tunnel complete." ) | |
| 192 | print( "Mined "..collected.." items total." ) |