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