SHOW:
|
|
- or go back to the newest paste.
1 | local function move(f) | |
2 | if turtle.getFuelLevel() == 0 then | |
3 | for slot=1,16 do | |
4 | turtle.select(slot) | |
5 | if turtle.refuel(0) then | |
6 | turtle.refuel(1) | |
7 | break | |
8 | end | |
9 | end | |
10 | if turtle.getFuelLevel() == 0 then | |
11 | print("No fuel, stopping...") | |
12 | return false | |
13 | end | |
14 | end | |
15 | -- mooooooveeee soooooo4aaaaraaa | |
16 | while not f() do | |
17 | turtle.dig() | |
18 | turtle.attack() | |
19 | sleep(1) | |
20 | end | |
21 | end | |
22 | ||
23 | -- return true if item count in slot 2 == 64 | |
24 | - | local function refill2(needRefill) |
24 | + | local function refill2() |
25 | local cobbleCount = turtle.getItemCount(2) | |
26 | local refillCount = 64 - cobbleCount | |
27 | if (cobbleCount == 0) then | |
28 | print("Out of tunnel buildblock: place buildblock in slot 2 to continue") | |
29 | repeat | |
30 | sleep(1) | |
31 | until (turtle.getItemCount(2) > 0) | |
32 | - | elseif (cobbleCount < 16 or needRefill) then |
32 | + | else |
33 | for n = 3,16 do | |
34 | turtle.select(2) | |
35 | if (turtle.compareTo(n) == true) then | |
36 | turtle.select(n) | |
37 | if (refillCount > turtle.getItemCount(n)) then | |
38 | turtle.transferTo(2, turtle.getItemCount(n)) | |
39 | refillCount = 64 - turtle.getItemCount(2) | |
40 | else | |
41 | turtle.transferTo(2, refillCount) | |
42 | break | |
43 | end | |
44 | end | |
45 | end | |
46 | end | |
47 | return turtle.getItemCount(2) == 64 | |
48 | end | |
49 | ||
50 | ||
51 | local function place() | |
52 | - | refill2(false) |
52 | + | |
53 | refill2() | |
54 | turtle.select(2) | |
55 | turtle.place() | |
56 | return true | |
57 | end | |
58 | return false | |
59 | end | |
60 | ||
61 | ||
62 | local function placeUp() | |
63 | - | refill2(false) |
63 | + | |
64 | refill2() | |
65 | turtle.select(2) | |
66 | turtle.placeUp() | |
67 | return true | |
68 | end | |
69 | return false | |
70 | end | |
71 | ||
72 | ||
73 | local function placeDown() | |
74 | - | refill2(false) |
74 | + | |
75 | refill2() | |
76 | turtle.select(2) | |
77 | turtle.placeDown() | |
78 | return true | |
79 | end | |
80 | return false | |
81 | end | |
82 | ||
83 | ||
84 | - | refill2(true) |
84 | + | |
85 | for slot=3,16 do | |
86 | inSlot = turtle.getItemDetail(slot) | |
87 | if inSlot.name == "minecraft:cobblestone" then | |
88 | turtle.select(slot) | |
89 | turtle.drop() | |
90 | end | |
91 | end | |
92 | end | |
93 | ||
94 | ||
95 | local function dig() | |
96 | while turtle.detect() do | |
97 | turtle.dig() | |
98 | end | |
99 | end | |
100 | ||
101 | ||
102 | local function digUp() | |
103 | while turtle.detectUp() do | |
104 | turtle.digUp() | |
105 | end | |
106 | end | |
107 | ||
108 | -- 1 floor step | |
109 | local function step1() | |
110 | dig() | |
111 | move(turtle.forward) | |
112 | placeDown() | |
113 | end | |
114 | ||
115 | -- 2 floor step | |
116 | local function step2() | |
117 | dig() | |
118 | move(turtle.forward) | |
119 | placeUp() | |
120 | end | |
121 | ||
122 | ||
123 | local function placeTorch() | |
124 | turtle.select(1) | |
125 | if turtle.getItemCount() < 1 then | |
126 | print("No torches in slot 1, place torches in slot 1") | |
127 | return false | |
128 | end | |
129 | turtle.turnRight() | |
130 | turtle.place() | |
131 | turtle.turnLeft() | |
132 | return true | |
133 | end | |
134 | ||
135 | ||
136 | -- MAIN | |
137 | local args = { ... } | |
138 | local length = 0 | |
139 | local width = 3 | |
140 | local depth = 0 | |
141 | ||
142 | if #args < 1 then | |
143 | print( "Usage: tunnel <length> [width, default 3]" ) | |
144 | return | |
145 | else | |
146 | length = tonumber( args[1] ) | |
147 | if length < 1 then | |
148 | print( "Tunnel length must be > 0" ) | |
149 | return | |
150 | end | |
151 | end | |
152 | ||
153 | if #args > 1 then | |
154 | width = tonumber( args[2] ) | |
155 | if width < 1 then | |
156 | print( "Tunnel width must be > 0" ) | |
157 | return | |
158 | end | |
159 | end | |
160 | ||
161 | print( "Tunnelling: length="..length.." width="..width.." height=2" ) | |
162 | ||
163 | for i=1,length do | |
164 | step1(false) | |
165 | ||
166 | turtle.turnRight() | |
167 | ||
168 | for j=2,width do | |
169 | step1() | |
170 | - | if (i % 8 == 0) and (j % 8 == 0) then |
170 | + | if (i % 7 == 0) and (j % 7 == 0) then |
171 | placeTorch() | |
172 | end | |
173 | end | |
174 | ||
175 | place() | |
176 | digUp() | |
177 | move(turtle.up) | |
178 | place() | |
179 | placeUp() | |
180 | ||
181 | turtle.turnRight() | |
182 | turtle.turnRight() | |
183 | ||
184 | for j=2,width do | |
185 | step2() | |
186 | end | |
187 | ||
188 | place() | |
189 | move(turtle.down) | |
190 | place() | |
191 | turtle.turnRight() | |
192 | ||
193 | - | if i % 8 == 0 then |
193 | + | if (i == 2) or (i % 7 == 0) then |
194 | placeTorch() | |
195 | end | |
196 | ||
197 | depth = depth + 1 | |
198 | ||
199 | - | if turtle.getItemCount(2) > 50 then |
199 | + | if refill2() then |
200 | emptyStash() | |
201 | end | |
202 | end | |
203 | ||
204 | print( "Returning to start..." ) | |
205 | ||
206 | -- Return to where we started | |
207 | turtle.turnLeft() | |
208 | turtle.turnLeft() | |
209 | while depth > 0 do | |
210 | move(turtle.forward) | |
211 | depth = depth - 1 | |
212 | end | |
213 | turtle.turnRight() | |
214 | turtle.turnRight() | |
215 | ||
216 | print( "Tunnel complete." ) |