SHOW:
|
|
- or go back to the newest paste.
1 | - | --This code is developed by me (onix331) and modified by Xenomurks and is availiable under the GNU General Public License (Version 3) |
1 | + | --This code is developed by me (onix331) and modified by Xenomurks and is availiable under the GNU General Public License (Version 3) |
2 | --See http://opensource.org/licenses/GPL-3.0 | |
3 | --Have fun | |
4 | ||
5 | shaftcount = 0--Used later in the program, usually not necessary do modify it | |
6 | space = 15--Defines the space of the turtle | |
7 | ver = 1.7--For updates | |
8 | chest = 0--If the turtle has stopped at a chest | |
9 | stop = 0--If the turtle has stopped at a chest | |
10 | ||
11 | ||
12 | function returnmining()--Beta-feature | |
13 | stop = 1 | |
14 | chest = 0 | |
15 | if direction=="r" then | |
16 | turnaround() | |
17 | for i = 1, shaftcount do | |
18 | turtle.forward() | |
19 | turtle.forward() | |
20 | turtle.forward() | |
21 | end | |
22 | turtle.turnRight() | |
23 | for i = 1, count do | |
24 | move() | |
25 | turnaround() | |
26 | move() | |
27 | move() | |
28 | turnaround() | |
29 | move() | |
30 | nextshaft() | |
31 | shaftcount = shaftcount + 1 | |
32 | count = count - 1 | |
33 | checkspace() | |
34 | end | |
35 | end | |
36 | end | |
37 | ||
38 | ||
39 | ||
40 | function checkl() --To check if length is valid (>0, not a String), also transforms the string into a number | |
41 | length = tonumber(length) | |
42 | if length==nil then | |
43 | print ("Invalid number!") | |
44 | length = read() | |
45 | checkl() | |
46 | elseif length <= 0 then | |
47 | print ("Invalid number!") | |
48 | length = read() | |
49 | checkl() | |
50 | end | |
51 | end | |
52 | ||
53 | function checka()--To check if count is valid (>0, not a String), also transforms the string into a number | |
54 | count = tonumber(count) | |
55 | if count==nil then | |
56 | print ("Invalid number!") | |
57 | count = read() | |
58 | checka() | |
59 | elseif count <= 0 then | |
60 | print ("Invalid number!") | |
61 | count = read() | |
62 | checka() | |
63 | end | |
64 | end | |
65 | ||
66 | function checkr()--To check if direction is valid ((r) or (l)) | |
67 | if direction=="r" then | |
68 | print ("") | |
69 | elseif direction=="l" then | |
70 | print ("") | |
71 | else | |
72 | print ("Invalid input!") | |
73 | direction = io.read() | |
74 | checkr() | |
75 | end | |
76 | end | |
77 | ||
78 | function checkref()--To check if refuel is valid ((r) or (l)) | |
79 | if refuel=="y" then | |
80 | print ("") | |
81 | elseif refuel=="n" then | |
82 | print ("") | |
83 | else | |
84 | print ("Invalid number!") | |
85 | refuel = io.read() | |
86 | checkref() | |
87 | end | |
88 | end | |
89 | ||
90 | function checktor()--To check if torch is valid ((y) or (n)) | |
91 | if torch=="y" then | |
92 | print ("") | |
93 | elseif torch=="n" then | |
94 | print ("") | |
95 | else | |
96 | print ("Invalid number!") | |
97 | torch = io.read() | |
98 | checktor() | |
99 | end | |
100 | end | |
101 | ||
102 | function move()--Basic movement funktion | |
103 | local debug = 8--Used to avoid gavel, sand, etc. | |
104 | for i = 1, length do | |
105 | if turtle.detect() then | |
106 | for i = 1, debug do | |
107 | turtle.dig() | |
108 | end | |
109 | turtle.forward() | |
110 | else | |
111 | turtle.forward() | |
112 | end | |
113 | if turtle.detectUp() then | |
114 | for i = 1, debug do | |
115 | turtle.digUp() | |
116 | end | |
117 | end | |
118 | end | |
119 | end | |
120 | ||
121 | function turnaround()--Turns the turtle at 90 degrees | |
122 | turtle.turnRight() | |
123 | turtle.turnRight() | |
124 | end | |
125 | ||
126 | function nextshaft()--Next shaft (right) | |
127 | turtle.turnLeft() | |
128 | turtle.dig() | |
129 | turtle.digUp() | |
130 | turtle.forward() | |
131 | turtle.dig() | |
132 | turtle.digUp() | |
133 | turtle.turnRight() | |
134 | turtle.select(16) | |
135 | turtle.placeUp() | |
136 | turtle.turnLeft() | |
137 | turtle.forward() | |
138 | turtle.dig() | |
139 | turtle.digUp() | |
140 | turtle.forward() | |
141 | turtle.digUp() | |
142 | turtle.turnRight() | |
143 | end | |
144 | ||
145 | function returnpoint()--Return to initial point | |
146 | ||
147 | turtle.turnRight() | |
148 | if shaftcount>=2 then | |
149 | turtle.forward() | |
150 | end | |
151 | turtle.forward() | |
152 | for i = 1, shaftcount do | |
153 | turtle.forward() | |
154 | turtle.forward() | |
155 | end | |
156 | if stop==1 then | |
157 | turtle.forward() | |
158 | end | |
159 | --turtle.turnLeft() | |
160 | for i = 1, space do | |
161 | turtle.select(i) | |
162 | turtle.drop() | |
163 | end | |
164 | turtle.select(1) | |
165 | ||
166 | turnaround() | |
167 | if chest==1 then | |
168 | returnmining() | |
169 | end | |
170 | end | |
171 | ||
172 | ||
173 | function checkspace()--Check for space and if necessary, return to initial point to the chest | |
174 | local spaceleft = 0 | |
175 | for i = 1, space do | |
176 | if turtle.getItemSpace(i) > 10 then | |
177 | spaceleft = spaceleft + 1 | |
178 | end | |
179 | end | |
180 | if spaceleft < 5 then | |
181 | chest = 1 | |
182 | count = count - 1 | |
183 | returnpoint() | |
184 | end | |
185 | end | |
186 | ||
187 | shell.run ("clear") | |
188 | print ("Strip-mining-program by onix331") | |
189 | print ("Version ", ver) | |
190 | ||
191 | --Start user input | |
192 | print ("Length of the single shaft(s):") | |
193 | length = read() | |
194 | checkl() | |
195 | ||
196 | print ("Count of the shafts:") | |
197 | count = read() | |
198 | checka() | |
199 | ||
200 | ||
201 | print ("Want to put some Torches on the Wall?") | |
202 | print ("Now? (Yes (y), No (n):") | |
203 | torch = read() | |
204 | checktor() | |
205 | if torch=="y" then | |
206 | print ("Please Put some in Slot 16") | |
207 | print ("When done, press ENTER") | |
208 | local sEvent, param = os.pullEvent("key") | |
209 | if sEvent == "key" then | |
210 | ||
211 | end | |
212 | end | |
213 | direction = r | |
214 | ||
215 | --Refueling, a little bit complicated | |
216 | print ("Dont forget to refuel!") | |
217 | print ("Now? (Yes (y), No (n):") | |
218 | refuel = read() | |
219 | checkref() | |
220 | if refuel=="y" then | |
221 | print ("Please insert fuel anywhere") | |
222 | print ("When done, press ENTER") | |
223 | while true do | |
224 | local sEvent, param = os.pullEvent("key") | |
225 | if sEvent == "key" then | |
226 | if param == 28 then | |
227 | for i = 1, space do | |
228 | for i = 1, 64 do | |
229 | shell.run("refuel", rafzahl) | |
230 | end | |
231 | turtle.select(i) | |
232 | end | |
233 | turtle.select(1) | |
234 | break | |
235 | end | |
236 | end | |
237 | end | |
238 | end | |
239 | ||
240 | --Print user inputs | |
241 | shell.run ("clear") | |
242 | print ("Input of Length:") | |
243 | print (length) | |
244 | print ("Input of count") | |
245 | print (count) | |
246 | os.sleep(2) | |
247 | print ("3") | |
248 | os.sleep(1) | |
249 | print ("2") | |
250 | os.sleep(1) | |
251 | print ("1") | |
252 | os.sleep(1) | |
253 | print("Start!") | |
254 | ||
255 | --Main Program | |
256 | ||
257 | turtle.turnRight() | |
258 | for i = 1, count do | |
259 | move() | |
260 | turnaround() | |
261 | move() | |
262 | move() | |
263 | turnaround() | |
264 | move() | |
265 | nextshaft() | |
266 | shaftcount = shaftcount + 1 | |
267 | count = count - 1 | |
268 | checkspace() | |
269 | end | |
270 | returnpoint() | |
271 | print ("Done!") |