View difference between Paste ID: QV9HP0yJ and vBsSi0E6
SHOW: | | - or go back to the newest paste.
1
tArgs = {...}
2
 
3
local torchSlot = 15
4
local fuelSlot = 16
5
local torchCompareSlot = 14
6
local torchCounter = 0
7
local torchPlacePoint = 7
8
local currentLevel = 0
9
10
function refuel(fuelAmount)
11
 if fuelAmount == nil then fuelAmount = 1 end
12
 turtle.select(fuelSlot)
13
 if turtle.refuel(fuelAmount) == true then
14
   turtle.select(1)
15
   return true
16
 else
17
   turtle.select(1)
18
   return false
19
 end
20
end
21
22
function getFuel()
23
  return turtle.getFuelLevel()
24
end
25
26
function turnRight(revolutions)
27
  if revolutions == nil then revolutions = 1 end
28
  for i =1, revolutions do
29
    turtle.turnRight()
30
  end
31
end
32
33
function turnLeft(revolutions)
34
  if revolutions == nil then revolutions = 1 end
35
  for i = 1, revolutions do
36
    turtle.turnLeft()
37
  end
38
end
39
40
function digLayer()
41
 dig()
42
 goForward(1)
43
 digUp(2)
44
 turnRight()
45
 dig()
46
 goForward()
47
 turnLeft()
48
 digDown(2)
49
 turnLeft()
50
 goForward(2)
51
 dig()
52
 goForward(1)
53
 turnRight()
54
 digUp(2)
55
 turnRight()
56
 goForward(1)
57
 turnLeft()
58
 goDown(2)
59
end
60
61
function goUp(distance)
62
  if distance == nil then distance = 1 end
63
  for i = 1, distance do
64
    turtle.up()
65
	currentLevel = currentLevel + 1
66
  end
67
end
68
69
function goDown(distance)
70
  if distance == nil then distance = 1 end
71
  for i = 1, distance do
72
    turtle.down()
73
	currentLevel = currentLevel - 1
74
  end
75
end
76
77
function goForward(distance)
78
  if distance == nil then distance = 1 end
79
  for i = 1, distance do
80
    turtle.forward()
81
  end
82
end
83
84
function goBack(distance)
85
  if distance == nil then distance = 1 end
86
  for i = 1, distance do
87
    turtle.back()
88
  end
89
end
90
91
function turnAround()
92
  turnRight(2)
93
end
94
95
function digUp(distance)
96
  if distance == nil then distance = 1 end
97
  for i = 1, distance do
98
    while turtle.detectUp() == true do
99
	  turtle.digUp()
100
	  slee(0.5)
101
	end
102
	if distance > 1 then
103
	  goUp()
104
	end
105
  end
106
end
107
108
function dig(distance)
109
  if distance == nil then distance = 1 end
110
  for i = 1, distance do
111
    while turtle.detect() == true do
112
	  turtle.dig()
113
	  sleep(0.5)
114
	end
115
  end
116
end
117
118
function digDown(distance)
119
  if distance == nil then distance = 1 end
120
  for i = 1, distance do
121
	turtle.digDown()
122
	sleep(0.5)
123
	if distance > 1 then
124
	  goDown()
125
	end
126
  end
127
end
128
129
function goToFloor()
130
  if currentLevel > 0 then
131
    while turtle.detectDown == false do
132
      goDown()
133
	  if currentLevel == 0 then
134
	     print("Possibly over a chasm. Breaking")
135
		 return false
136
	  end
137
    end
138
  end
139
  return true
140
end
141
142
function placeTorch()
143
  turtle.select(torchSlot)
144
  if turtle.compareTo(torchCompareSlot) == true then
145
    if turtle.detectDown() == true then
146
	  turnAround()
147
	  goForward(1)
148
	  if turtle.detectDown() == true then
149
	    goBack(1)
150
        turtle.place()
151
	    turnAround()
152
	  end
153
    else
154
      if goToFloor() == true then
155
	    turnAround()
156
		goForward(1)
157
		if turtle.detectDown() == true then
158
		  goBack(1)
159
		  turtle.place()
160
		  turnAround()
161
		end
162
	  end
163
    end
164
  else
165
    print("Out of torches!")
166
  end
167
  turtle.select(1)
168
end
169
170
function returnToStart(distance)
171
  turnAround()
172
  goForward(distance)
173
  turnAround()
174
end
175
176
177
function checkTorchPlacement()
178
  torchCounter = torchCounter + 1
179
  if torchCounter == torchPlacePoint then
180
    placeTorch()
181
	torchCounter = 0
182
  end
183
end
184
185
function dropLoad()
186
  for i = 1, 13 do
187
    turtle.select(i)
188
	turtle.drop()
189
  end
190
  turtle.select(1)
191
end
192
193
if tArgs[1] == nil then
194
  print("Usage: miner <length of shaft")
195
else
196
  shaftLength = tonumber(tArgs[1])
197
  for i = 1, shaftLength do
198
   print("Working on layer "..i)
199
   digLayer()
200
   checkTorchPlacement()
201
   if getFuel() == 0 then
202
     refuel(5)
203
   end	 
204
  end
205
  returnToStart(shaftLength)
206
  turnAround()
207
  dropLoad()
208
  turnAround()
209
  print("Job Done!")
210
end