SHOW:
|
|
- or go back to the newest paste.
1 | --[[ | |
2 | Version | |
3 | 0.08 5/3/2015 1:01 AM | |
4 | Changelog | |
5 | 0.01 - Starting Of Rewriting | |
6 | 0.02 - More Writing | |
7 | 0.03 - Adding Fuel Code | |
8 | 0.04 - Small but many program Error fixed | |
9 | 0.05 - Fully Test | |
10 | 0.06 - Fixing Minor Bug when add 3 to deep because firstdig had no 3 add to deepcount | |
11 | 0.07 - Fixing High Error | |
12 | 0.08 - Adding Red stone Starting and change error to Error since lua has error as function. | |
13 | --]] | |
14 | ||
15 | -- Local Variables | |
16 | -- Starting | |
17 | local wide = 0 | |
18 | local wideCount = 0 | |
19 | local long = 0 | |
20 | local longCount = 0 | |
21 | local deep = 0 | |
22 | local deepCount = 0 | |
23 | local totalBlocks = 0 | |
24 | local coalNeeded = 0 | |
25 | local corrent = n | |
26 | -- Inventory This Will Check At Start Code | |
27 | local chest = 0 | |
28 | local fuelCount = 0 | |
29 | local fuelCount1 = 0 | |
30 | local noFuelNeed = 0 -- if Config has fuel no need on | |
31 | local Error = 0 -- Error Code | |
32 | local reCheck = 0 -- Recheck Code | |
33 | -- Others | |
34 | local totalBlocks = 0 | |
35 | local totalBlockDone = 0 -- How many Block Mined | |
36 | local LSorWS = 0 -- Go Left or Go Right This is for Wide Code | |
37 | local ALorAR = 0 -- align left Or align Right | |
38 | local processRaw = 0 | |
39 | local process = 0 | |
40 | local enderChest = 0 -- TODO | |
41 | local blockUp = 0 -- Fixing to Chest Probleem and moving probleem | |
42 | local processRaw = 0 | |
43 | local process = 0 | |
44 | local starting = 0 -- if 0 normal if 1 then redstone starting. | |
45 | local on = 0 | |
46 | ||
47 | -- Checking | |
48 | local function check() | |
49 | if noFuelNeed == 0 then | |
50 | if fuelCount == 0 then | |
51 | print("Turtle has no fuel") | |
52 | print("Put fuel in Second and Thrid slot") | |
53 | Error = 1 | |
54 | else | |
55 | print("Turtle has Fuel") | |
56 | end | |
57 | if fuelCount1 == 0 then | |
58 | print("Turtle has no extra fuel but if is short job it okey") | |
59 | end | |
60 | end | |
61 | if chest == 0 then | |
62 | print("No chest in Turtle") | |
63 | print("Put chest in 1 slot") | |
64 | Error = 1 | |
65 | else | |
66 | print("Turtle has chest") | |
67 | end | |
68 | if Error == 1 then | |
69 | print("Items are missing please try again") | |
70 | print("Turtle will recheck in 8 sec") | |
71 | end | |
72 | end | |
73 | ||
74 | -- Recheck if user forget something turtle will check after 6 sec | |
75 | local function reCheck() | |
76 | chest = turtle.getItemCount(1) | |
77 | fuelCount = turtle.getItemCount(2) | |
78 | fuelCount1 = turtle.getItemCount(3) | |
79 | Error = 0 | |
80 | end | |
81 | ||
82 | local function chestDump() | |
83 | if turtle.getItemCount(16)> 0 then -- If slot 16 in turtle has item slot 4 to 16 will go to chest | |
84 | repeat -- The Fix to Gravel Chest Bug. It check if gravel above then it dig till it gone | |
85 | turtle.digUp() | |
86 | sleep(0.6) | |
87 | if turtle.detectUp() then | |
88 | turtle.digUp() | |
89 | blockUp = 1 | |
90 | else | |
91 | blockUp = 0 | |
92 | end | |
93 | until blockUp == 0 | |
94 | turtle.select(1) | |
95 | turtle.placeUp() | |
96 | chest = chest - 1 | |
97 | for slot = 4, 16 do | |
98 | turtle.select(slot) | |
99 | sleep(0.6) -- Small fix for slow pc because i had people problem with this | |
100 | turtle.dropUp() | |
101 | end | |
102 | turtle.select(4) | |
103 | if Chest == 0 then | |
104 | print("Out Of Chest") | |
105 | os.shutdown() | |
106 | end | |
107 | end | |
108 | end | |
109 | ||
110 | -- Refuel | |
111 | local function refuel() | |
112 | if noFuelNeed == 0 then | |
113 | repeat | |
114 | if turtle.getFuelLevel() < 160 then | |
115 | if fuelCount > 0 then | |
116 | turtle.select(2) | |
117 | turtle.refuel(1) | |
118 | fuelCount = fuelCount - 1 | |
119 | elseif fuelCount1 > 0 then | |
120 | turtle.select(3) | |
121 | turtle.refuel(1) | |
122 | fuelCount1 = fuelCount1 - 1 | |
123 | else | |
124 | print("out of fuel") | |
125 | os.shutdown() | |
126 | end | |
127 | end | |
128 | until turtle.getFuelLevel() >= 160 | |
129 | end | |
130 | end | |
131 | ||
132 | local function mineLong() | |
133 | if turtle.detect() then | |
134 | turtle.dig() | |
135 | end | |
136 | if turtle.forward() then | |
137 | longCount = longCount + 1 | |
138 | else | |
139 | repeat | |
140 | turtle.dig() | |
141 | sleep(0.6) | |
142 | if turtle.forward() then | |
143 | blockUp = 0 | |
144 | else | |
145 | blockUp = 1 | |
146 | end | |
147 | until blockUp == 0 | |
148 | longCount = longCount + 1 | |
149 | print(totalBlocks - totalBlockDone) | |
150 | end | |
151 | if turtle.detectUp() then | |
152 | turtle.digUp() | |
153 | end | |
154 | if turtle.detectDown() then | |
155 | turtle.digDown() | |
156 | end | |
157 | totalBlockDone = totalBlockDone + 3 | |
158 | end | |
159 | ||
160 | local function wideMineLeft() | |
161 | turtle.turnLeft() | |
162 | if turtle.detect() then | |
163 | turtle.dig() | |
164 | sleep(0.6) -- Minor bug fix if there is gravel | |
165 | end | |
166 | if turtle.forward() then | |
167 | --notting | |
168 | else | |
169 | repeat | |
170 | turtle.dig() | |
171 | sleep(0.6) | |
172 | if turtle.forward() then | |
173 | blockUp = 0 | |
174 | else | |
175 | blockUp = 1 | |
176 | end | |
177 | until blockUp == 0 | |
178 | end | |
179 | if turtle.detectUp() then | |
180 | turtle.digUp() | |
181 | end | |
182 | if turtle.detectDown() then | |
183 | turtle.digDown() | |
184 | end | |
185 | turtle.turnLeft() | |
186 | LSorWS = 0 | |
187 | longCount = 0 | |
188 | wideCount = wideCount + 1 | |
189 | totalBlockDone = totalBlockDone + 3 | |
190 | end | |
191 | ||
192 | local function wideMineRight() | |
193 | turtle.turnRight() | |
194 | if turtle.detect() then | |
195 | turtle.dig() | |
196 | sleep(0.6) | |
197 | end | |
198 | if turtle.forward() then | |
199 | --Notting | |
200 | else | |
201 | repeat | |
202 | turtle.dig() | |
203 | sleep(0.6) | |
204 | if turtle.forward() then | |
205 | blockUp = 0 | |
206 | else | |
207 | blockUp = 1 | |
208 | end | |
209 | until blockUp == 0 | |
210 | end | |
211 | if turtle.detectUp() then | |
212 | turtle.digUp() | |
213 | end | |
214 | if turtle.detectDown() then | |
215 | turtle.digDown() | |
216 | end | |
217 | turtle.turnRight() | |
218 | LSorWS = 1 | |
219 | longCount = 0 | |
220 | wideCount = wideCount + 1 | |
221 | totalBlockDone = totalBlockDone + 3 | |
222 | end | |
223 | ||
224 | local function deepMine() | |
225 | turtle.digDown() | |
226 | turtle.down() | |
227 | turtle.digDown() | |
228 | turtle.down() | |
229 | turtle.digDown() | |
230 | turtle.down() | |
231 | turtle.digDown() | |
232 | turtle.turnRight() | |
233 | turtle.turnRight() | |
234 | wideCount = 0 | |
235 | longCount = 0 | |
236 | deepCount = deepCount + 3 | |
237 | totalBlockDone = totalBlockDone + 3 | |
238 | end | |
239 | ||
240 | local function main() | |
241 | repeat --Repeat for each level | |
242 | mineLong() | |
243 | refuel() | |
244 | chestDump() | |
245 | if longCount == long then | |
246 | if wideCount ~= wide then | |
247 | process = totalBlockDone / totalBlocks * 100 | |
248 | processRaw = totalBlocks - totalBlockDone | |
249 | print("How Much Is Done: " .. math.floor(process+0.5) .. " %") | |
250 | print("TotalBlocks Still Need To Dig Is " .. processRaw) | |
251 | if LSorWS == 0 then | |
252 | wideMineRight() | |
253 | else | |
254 | wideMineLeft() | |
255 | end | |
256 | elseif wideCount >= wide then | |
257 | deepMine() | |
258 | end | |
259 | end | |
260 | until deepCount >= deep | |
261 | print("turtle is Done") | |
262 | end | |
263 | ||
264 | local function firstDig() | |
265 | turtle.digDown() | |
266 | turtle.down() | |
267 | turtle.digDown() | |
268 | turtle.down() | |
269 | turtle.digDown() | |
270 | wideCount = 0 | |
271 | longCount = 0 | |
272 | totalBlockDone = totalBlockDone + 3 | |
273 | end | |
274 | ||
275 | local function powerOn() | |
276 | if starting == 0 then | |
277 | print("Turtle will now start!") | |
278 | firstDig() | |
279 | main() | |
280 | elseif starting == 1 then | |
281 | while true do | |
282 | sleep(0) | |
283 | local event = os.pullEvent() | |
284 | if event == "redstone" then | |
285 | break | |
286 | end | |
287 | end | |
288 | print("Turtle will now start!") | |
289 | firstDig() | |
290 | main() | |
291 | end | |
292 | end | |
293 | ||
294 | local function start() | |
295 | print("Welcome To Excavation Turtle Program") | |
296 | print("Slot 1: Chest, Slot 2: Fuel, Slot 3: Fuel") | |
297 | print("Note: If now put item in then it say Error just wait it fix it self") | |
298 | print("How long(Lenght) you want") | |
299 | input = io.read() | |
300 | long = tonumber(input) | |
301 | long = long - 1 | |
302 | print("How wide(Width) you want") | |
303 | input2 = io.read() | |
304 | wide = tonumber(input2) | |
305 | wide = wide - 1 | |
306 | print("How Deep(Depth) You Want") | |
307 | input3 = io.read() | |
308 | deep = tonumber(input3) | |
309 | print("Is This Corrent Lenght " .. "Lenght = " .. (long + 1) .. " Width = " .. (wide + 1) .. " Depth = " .. (deep)) | |
310 | print("Type y Or Y if it is correct and if not then n or N") | |
311 | corrent = io.read() | |
312 | if corrent == n or N then | |
313 | os.reboot() | |
314 | end | |
315 | print("Okey Program Will Do Calculations") | |
316 | totalBlocks = (wide + 1) * (long + 1) * deep -- 1 is add because above it removed for wide and long code | |
317 | print("Total amount for block to mine is " .. totalBlocks) | |
318 | coalNeeded = totalBlocks / 3 / 80 | |
319 | print("Total amount for Coal needed is " .. math.floor(coalNeeded+0.5)) | |
320 | if turtle.getFuelLevel() == "unlimited" then | |
321 | print("Your turtle config does need fuel") | |
322 | noFuelNeed = 1 | |
323 | elseif turtle.getFuelLevel() < 160 then | |
324 | turtle.select(2) | |
325 | turtle.refuel(2) | |
326 | end | |
327 | print("Do You Want Redstone as Starting Input") | |
328 | print("Note: It Only Detect Back of Turtle") | |
329 | print("if not then type 0 if yes then type 1") | |
330 | input4 = io.read() | |
331 | starting = tonumber(input4) | |
332 | reCheck() | |
333 | check() | |
334 | if Error == 1 then | |
335 | repeat | |
336 | sleep(6) | |
337 | reCheck() | |
338 | check() | |
339 | until Error == 0 | |
340 | end | |
341 | powerOn() | |
342 | end | |
343 | ||
344 | start() |