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