View difference between Paste ID: FRqy1JzH and pkpA4y8W
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-
        turtle.placeDown()
146+
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-
		  turtle.placeDown()
155+
156
		  turtle.place()
157
		  turnAround()
158
		end
159
	  end
160
    end
161
  else
162
    print("Out of torches!")
163
  end
164
end
165
166
function checkTorchPlacement()
167
  torchCounter = torchCounter + 1
168
  if torchCounter == torchPlacePoint then
169
    placeTorch()
170
	torchCounter = 0
171
  end
172
end
173
174
if tArgs[1] == nil then
175
  print("Usage: miner <length of shaft")
176
else
177
  shaftLength = tonumber(tArgs[1])
178
  for i = 1, shaftLength do
179
   print("Working on layer "..i)
180
   digLayer()
181
   checkTorchPlacement()
182
  end
183
  print("Job Done!")
184
end