SHOW:
|
|
- or go back to the newest paste.
1 | direction=1 | |
2 | floors=25 | |
3 | rows=25 | |
4 | blocks=25 | |
5 | x=0 | |
6 | y=0 | |
7 | z=0 | |
8 | ||
9 | function turnLeft() | |
10 | position(-1) | |
11 | turtle.turnLeft() | |
12 | end | |
13 | ||
14 | function turnRight() | |
15 | position(1) | |
16 | turtle.turnRight() | |
17 | end | |
18 | ||
19 | function dig() | |
20 | while turtle.detect() == true do | |
21 | turtle.attack() | |
22 | turtle.dig() | |
23 | os.sleep(0.5) | |
24 | end | |
25 | end | |
26 | ||
27 | function digUp() | |
28 | while turtle.detectUp() == true do | |
29 | turtle.digUp() | |
30 | os.sleep(0.5) | |
31 | end | |
32 | end | |
33 | ||
34 | function digDown() | |
35 | - | turtle.digDown() |
35 | + | while turtle.detectDown() == true do |
36 | turtle.digDown() | |
37 | os.sleep(0.5) | |
38 | end | |
39 | end | |
40 | ||
41 | function down(times) | |
42 | if times==nil then times=1 end | |
43 | for i=1,times do | |
44 | turtle.digDown() | |
45 | turtle.down() | |
46 | turtle.digDown() | |
47 | turtle.down() | |
48 | turtle.digDown() | |
49 | turtle.down() | |
50 | z=z-1 | |
51 | end | |
52 | end | |
53 | ||
54 | function up(times) | |
55 | if times == nil then times=1 end | |
56 | for i=1,times do | |
57 | digUp() | |
58 | turtle.up() | |
59 | digUp() | |
60 | turtle.up() | |
61 | digUp() | |
62 | turtle.up() | |
63 | z=z+1 | |
64 | end | |
65 | end | |
66 | ||
67 | function forward(times) | |
68 | if times == nil then times=1 end | |
69 | for i=1, times do | |
70 | dig() | |
71 | turtle.forward() | |
72 | if direction == 1 then x=x-1 elseif | |
73 | direction == 2 then y=y+1 elseif | |
74 | direction == 3 then x=x+1 elseif | |
75 | direction == 4 then y=y-1 end | |
76 | end | |
77 | end | |
78 | ||
79 | function position(x,h) | |
80 | if x<0 then | |
81 | if direction == 1 then | |
82 | direction = 4 | |
83 | else | |
84 | direction = direction - 1 | |
85 | end | |
86 | elseif x>0 then | |
87 | if direction == 4 then | |
88 | direction = 1 | |
89 | else | |
90 | direction = direction + 1 | |
91 | end | |
92 | end | |
93 | end | |
94 | ||
95 | function default_direction() | |
96 | while direction > 1 do | |
97 | turnLeft() | |
98 | end | |
99 | end | |
100 | ||
101 | function drop() | |
102 | for i=2,16 do | |
103 | turtle.select(i) | |
104 | turtle.drop() | |
105 | end | |
106 | turtle.select(1) | |
107 | end | |
108 | ||
109 | function spaceAviable() | |
110 | turtle.select(15) | |
111 | if turtle.getItemDetail() then | |
112 | return false | |
113 | else | |
114 | turtle.select(1) | |
115 | return true | |
116 | end | |
117 | end | |
118 | ||
119 | function checkChest() | |
120 | turtle.select(1) | |
121 | if turtle.compare() == false then | |
122 | dig() | |
123 | digUp() | |
124 | forward() | |
125 | digUp() | |
126 | turnLeft() | |
127 | turnLeft() | |
128 | forward() | |
129 | turnLeft() | |
130 | turnLeft() | |
131 | turtle.place() | |
132 | end | |
133 | turnLeft() | |
134 | forward() | |
135 | turnRight() | |
136 | if turtle.compare() == false then | |
137 | dig() | |
138 | digUp() | |
139 | forward() | |
140 | digUp() | |
141 | turnLeft() | |
142 | turnLeft() | |
143 | forward() | |
144 | turnLeft() | |
145 | turnLeft() | |
146 | turtle.place() | |
147 | end | |
148 | turnRight() | |
149 | forward() | |
150 | turnLeft() | |
151 | end | |
152 | ||
153 | function emptyTurtle(finish, start) | |
154 | if spaceAviable() and finish==nil then | |
155 | return false | |
156 | else | |
157 | local curx=x | |
158 | local cury=y | |
159 | local curz=z | |
160 | default_direction() | |
161 | if start == nil or start == false then | |
162 | if finish == true then | |
163 | up(-z) | |
164 | end | |
165 | end | |
166 | forward(x) | |
167 | turnLeft() | |
168 | forward(y) | |
169 | default_direction() | |
170 | checkChest() | |
171 | drop() | |
172 | if finish==nil or finish==false then | |
173 | turnRight() | |
174 | forward(cury) | |
175 | turnRight() | |
176 | forward(curx) | |
177 | turnLeft() | |
178 | down(-curz) | |
179 | end | |
180 | if start==true then | |
181 | turnRight() | |
182 | forward(cury) | |
183 | -- down(-curz) | |
184 | end | |
185 | end | |
186 | end | |
187 | ||
188 | ||
189 | turnRight() | |
190 | forward(2) | |
191 | for h=1, floors do | |
192 | for i=1, rows do | |
193 | for j=1, blocks do | |
194 | emptyTurtle() | |
195 | dig() | |
196 | digUp() | |
197 | digDown() | |
198 | forward() | |
199 | digUp() | |
200 | digDown() | |
201 | end | |
202 | turnLeft() | |
203 | turnLeft() | |
204 | for j=1, blocks do | |
205 | dig() | |
206 | forward() | |
207 | end | |
208 | if i~=rows then | |
209 | turnLeft() | |
210 | dig() | |
211 | forward() | |
212 | digUp() | |
213 | turnLeft() | |
214 | end | |
215 | end | |
216 | if h~=floors then | |
217 | emptyTurtle(true, true) | |
218 | down() | |
219 | end | |
220 | end | |
221 | emptyTurtle(true) | |
222 | term.write(direction) | |
223 | term.write(" ") | |
224 | term.write('x: ') | |
225 | term.write(x) | |
226 | term.write(' y: ') | |
227 | term.write(y) |