View difference between Paste ID: QAzqLjEB and fgPQF2ZH
SHOW: | | - or go back to the newest paste.
1
	
2
    --Variable Declarations
3
    local mainShaftDim = "3x2"
4
    local sideShaftDim = "2x1"
5
    local shaftFreq = "3"
6
    local totalCost = 0
7
    local input = ""
8
    local length = 0
9
    local currentPos = 1
10
    local chestDist = 0
11
    local doFuel = false
12
     
13
    --Function Declarations
14
    function oreDetect()
15
            --[[ This function is a WIP system for the turtle to detect ores when it
16
            is mining and dig out the entire vein.  It will do so by comparing items
17
            around it to specific slots in its inventory which will contain common
18
            blocks such as smooth stone, gravel, dirt, etc.
19
            If one of these ores is identified, then the turtle will dig out the block
20
            and then move into the space that the block occupied and 'sense' the blocks
21
            around it again to try and find the continuation of the vein.
22
            Once the turtle has finished identifying the vein, it will return to it's
23
            initial position.  This last task may either be completed by recording
24
            movement as the turtle moves or by using a GPS wireless system and a
25
            basic 'goto' function for the initial coordinates.
26
            ]]
27
    end
28
     
29
    function refuel()
30
            for i=1,15,1 do
31
                    turtle.select(i)
32
                    turtle.refuel(turtle.getItemCount(i))
33
            end
34
            turtle.select(1)
35
    end
36
     
37
    function mainShaft()
38
            turtle.select(1)
39
            for i=1,4,1 do
40
                    while turtle.detect() == true do
41
                            turtle.dig()
42
                    end
43
                    turtle.forward()
44-
					while turtle.detect() == true do
44+
45
                            turtle.placeDown()
46
                    end
47
                    while turtle.detectUp() do
48
                            turtle.digUp()
49
                    end
50
                    turtle.turnRight()
51
                    while turtle.detect() == true do
52
                            turtle.dig()
53
                    end
54
                    turtle.forward()
55
                    if not turtle.detectDown() then
56
                            turtle.placeDown()
57
                    end
58
                    while turtle.detectUp() do
59
                            turtle.digUp()
60
                    end
61
                    turtle.turnRight()
62
                    turtle.turnRight()
63
                    while turtle.detect() do
64
                            turtle.dig()
65
                    end
66
                    turtle.forward()
67
                    if not turtle.detectDown() then
68
                            turtle.placeDown()
69
                    end
70
                    turtle.turnRight()
71
            end
72
            turtle.turnRight()
73
            turtle.turnRight()
74
            turtle.select(16)
75
            turtle.forward()
76
            turtle.placeUp()
77
            turtle.turnLeft()
78
            turtle.forward()
79
            turtle.placeUp()
80
            turtle.turnLeft()
81
            turtle.forward()
82
            turtle.turnLeft()
83
            turtle.forward()
84
            turtle.turnRight()
85
    end
86
     
87
    function sideShaft()
88
            turtle.select(1)
89
            for i=0,20,1 do
90
                    while turtle.detect() == true do
91
                            turtle.dig()
92
                    end
93
                    turtle.forward()
94
                    if turtle.detectDown() == false then
95
                            turtle.placeDown()
96
                    end
97
                    while turtle.detectUp() == true do
98
                            turtle.digUp()
99
                    end
100
					while turtle.detectDown() == true do
101
							turtle.digdown()
102
							turtle.down()
103
					end
104
            end
105
            turtle.select(16)
106
            turtle.turnRight()
107
            turtle.turnRight()
108
            turtle.place()
109
            turtle.turnRight()
110
            turtle.turnRight()
111
            turtle.select(1)
112
            for i=0,20,1 do
113
                    while turtle.detect() == true do
114
                            turtle.dig()
115
                    end
116
                    turtle.forward()
117
                    if turtle.detectDown() == false then
118
                            turtle.placeDown()
119
                    end
120
                    while turtle.detectUp() == true do
121
                            turtle.digUp()
122
                    end
123
            end
124
            turtle.turnRight()
125
            turtle.turnRight()
126
            turtle.select(16)
127
            turtle.place()
128
            turtle.up()
129
            for i=1,23,1 do
130
                    while turtle.detect() do
131
                            turtle.dig()
132
                    end
133
                    turtle.forward()
134
            end
135
            turtle.down()
136
    end
137
     
138
    function deposit()
139
            for i=1, (chestDist), 1 do
140
                    turtle.forward()
141
            end
142
            for i=1, 15, 1 do
143
                    turtle.select(i)
144
                    turtle.drop()
145
            end
146
            refuel()
147
            if turtle.getItemCount(16) < 6 then
148
                    stopMining()
149
            end
150
            if turtle.getFuelLevel() < (108 + 2 * chestDist) then
151
                    stopMining()
152
            end
153
            turtle.turnRight()
154
            turtle.turnRight()
155
            for i=1, (chestDist), 1 do
156
                    turtle.forward()
157
            end
158
     
159
    end
160
     
161
    function stopMining()
162
            if turtle.getFuelLevel() < (108 + 2 * chestDist) then
163
                    print("I am low on fuel.")
164
                    local remainFuel = 0
165
                    for i=currentPos, length, 1 do
166
                            remainFuel = (108 + 2 * (4 * i + 1))
167
                    end
168
                    print("I need "..remainFuel.." to finish.")
169
                    print("That's "..(remainFuel/80).." coal or "..(remainFuel/1000).." lava.")
170
                    print("Type (cont) to refuel & continue mining.")
171
                    doFuel = true
172
            end
173
            if turtle.getItemCount(16) < 6 then
174
                    print("I am low on torches.")
175
                    print("Place more in slot 16...")
176
                    while turtle.getItemCount(16) < 6 do
177
                            sleep(1)
178
                    end
179
                    print("Type (cont) to continue mining.")
180
                    doFuel = false
181
            end
182
            local cont = false
183
            while cont == false do
184
                    --[[if rs.getInput("right") == true then --Flickers RS torch on right of chest
185
                            rs.setOutput("right", false)
186
                    else
187
                            rs.setOutput("right", true)
188
                    end]]
189
                    local input = io.read()
190
                    if input == "cont" then
191
                            if doFuel then
192
                                    refuel()
193
                            end
194
                            turtle.turnRight()
195
                            turtle.turnRight()
196
                            for i=1, chestDist, 1 do
197
                                    turtle.forward()
198
                            end
199
                            currentPos = currentPos + 1
200
                            run()
201
                    else
202
                            print("Incorrect input.")
203
                    end
204
            end
205
    end
206
     
207
    function run()
208
            while currentPos < length do
209
                    chestDist = (currentPos * 4 + 4)
210
                    mainShaft()
211
                    turtle.turnLeft()
212
                    sideShaft()
213
                    sideShaft()
214
                    turtle.turnLeft()
215
                    deposit()
216
                    currentPos = currentPos + 1
217
            end
218
    end
219
     
220
    function idle()
221
            print("Mining Complete")
222
            print("Type (end) to terminate program")
223
            local input = "null"
224
            rs.setOutput("right", true)
225
            while input ~= "end" do
226
                    input = io.read()
227
            end
228
            rs.setOutput("right", false)
229
    end
230
     
231
    --Execution
232
    print("----------------------------------")
233
    print("Branch Mine Turtle Activated")
234
    print("----------------------------------")
235
    sleep(2)
236
    print("Beginning Mine w. Following Specs:")
237
    print("Main Shaft: "..mainShaftDim)
238
    print("Side Shafts: "..sideShaftDim)
239
    print("Branch Frequency: "..shaftFreq)
240
    print("----------------------------------")
241
     
242
    print("Number of Shafts:")
243
    length = tonumber(read())
244
    currentPos = 0
245
    print("----------------------------------")
246
    for x = length, 0, -1 do
247
            totalCost = totalCost + (108 + 2 * (4 * x + 1))
248
    end
249
    print("Current Fuel: "..turtle.getFuelLevel())
250
    print("Fuel cost: "..totalCost)
251
    print("Coal cost: "..(totalCost/80))
252
    print("Lava cost: "..(totalCost/1000))
253
    sleep(2)
254
    print("----------------------------------")
255
    print("Would you like to refuel now (y/n)?")
256
    input = io.read()
257
    if input == "y" then
258
            refuel()
259
            print("Refueled.")
260
    else
261
            print("Did not refuel.")
262
    end
263
    print("Turtle now has "..turtle.getFuelLevel().." fuel.")
264
    print("----------------------------------")
265
    print("Now beginning mining!")
266
     
267
    run()
268
    turtle.turnRight()
269
    turtle.turnRight()
270
    for i=1, chestDist, 1 do
271
            turtle.forward()
272
    end
273
    idle()