View difference between Paste ID: vBsSi0E6 and FRqy1JzH
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
	end
101
	if distance > 1 then
102
	  goUp()
103
	end
104
  end
105
end
106
107
function dig(distance)
108
  if distance == nil then distance = 1 end
109
  for i = 1, distance do
110
    while turtle.detect() == true do
111
	  turtle.dig()
112
	end
113
  end
114
end
115
116
function digDown(distance)
117
  if distance == nil then distance = 1 end
118
  for i = 1, distance do
119
	turtle.digDown()
120
	if distance > 1 then
121
	  goDown()
122
	end
123
  end
124
end
125
126
function goToFloor()
127
  if currentLevel > 0 then
128
    while turtle.detectDown == false do
129
      goDown()
130
	  if currentLevel == 0 then
131
	     print("Possibly over a chasm. Breaking")
132
		 return false
133
	  end
134
    end
135
  end
136
  return true
137
end
138
139
function placeTorch()
140
  turtle.select(torchSlot)
141
  if turtle.compareTo(torchCompareSlot) == true then
142
    if turtle.detectDown() == true then
143
	  turnAround()
144
	  goForward(1)
145
	  if turtle.detectDown() == true then
146
	    goBack(1)
147
        turtle.place()
148
	    turnAround()
149
	  end
150
    else
151
      if goToFloor() == true then
152
	    turnAround()
153
		goForward(1)
154
		if turtle.detectDown() == true then
155
		  goBack(1)
156
		  turtle.place()
157
		  turnAround()
158
		end
159
	  end
160
    end
161
  else
162
    print("Out of torches!")
163
  end
164
  turtle.select(1)
165
end
166
167
function returnToStart(distance)
168
  turnAround()
169
  goForward(distance)
170
end
171
172
173
function checkTorchPlacement()
174
  torchCounter = torchCounter + 1
175
  if torchCounter == torchPlacePoint then
176
    placeTorch()
177
	torchCounter = 0
178
  end
179
end
180
181
function dropLoad()
182
  for i = 1, 13 do
183
    turtle.select(i)
184
	turtle.drop()
185
  end
186
  turtle.select(1)
187
end
188
189
if tArgs[1] == nil then
190
  print("Usage: miner <length of shaft")
191
else
192
  shaftLength = tonumber(tArgs[1])
193
  for i = 1, shaftLength do
194
   print("Working on layer "..i)
195
   digLayer()
196
   checkTorchPlacement()
197
   if getFuel() == 0 then
198
     refuel(5)
199
   end	 
200
  end
201
  returnToStart(shaftLength)
202
  dropLoad()
203
  print("Job Done!")
204
end