View difference between Paste ID: pkpA4y8W and ctsstKVy
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
 turnLeft()
47
 digDown(2)
48
 turnLeft()
49
 goForward(2)
50
 dig()
51
 goForward(1)
52
 turnRight()
53
 digUp(2)
54
 turnRight()
55
 goForward(1)
56
 turnLeft()
57
 goDown(2)
58
end
59
60
function goUp(distance)
61
  if distance == nil then distance = 1 end
62
  for i = 1, distance do
63
    turtle.up()
64
	currentLevel = currentLevel + 1
65
  end
66
end
67
68
function goDown(distance)
69
  if distance == nil then distance = 1 end
70
  for i = 1, distance do
71
    turtle.down()
72
	currentLevel = currentLevel - 1
73
  end
74
end
75
76
function goForward(distance)
77
  if distance == nil then distance = 1 end
78
  for i = 1, distance do
79
    turtle.forward()
80
  end
81
end
82
83
function goBack(distance)
84
  if distance == nil then distance = 1 end
85
  for i = 1, distance do
86
    turtle.back()
87
  end
88
end
89
90
function turnAround()
91
  turnRight(2)
92
end
93
94
function digUp(distance)
95
  if distance == nil then distance = 1 end
96
  for i = 1, distance do
97
    while turtle.detectUp() == true do
98
	  turtle.digUp()
99
	end
100
	if distance > 1 then
101
	  goUp()
102
	end
103
  end
104
end
105
106
function dig(distance)
107
  if distance == nil then distance = 1 end
108
  for i = 1, distance do
109
    while turtle.detect() == true do
110
	  turtle.dig()
111
	end
112
  end
113
end
114
115
function digDown(distance)
116
  if distance == nil then distance = 1 end
117
  for i = 1, distance do
118
	turtle.digDown()
119
	if distance > 1 then
120
	  goDown()
121
	end
122
  end
123
end
124
125
function goToFloor()
126
  if currentLevel > 0 then
127
    while turtle.detectDown == false do
128
      goDown()
129
	  if currentLevel == 0 then
130
	     print("Possibly over a chasm. Breaking")
131
		 return false
132
	  end
133
    end
134
  end
135
  return true
136
end
137
138
function placeTorch()
139
  turtle.select(torchSlot)
140
  if turtle.compareTo(torchCompareSlot) == true then
141
    if turtle.detectDown() == true then
142
	  turnAround()
143
	  goForward(1)
144
	  if turtle.detectDown() == true then
145
	    goBack(1)
146
        turtle.placeDown()
147
	    turnAround()
148
	  end
149
    else
150
      if goToFloor() == true then
151
	    turnAround()
152
		goForward(1)
153
		if turtle.detectDown() == true then
154
		  goBack(1)
155
		  turtle.placeDown()
156
		  turnAround()
157
		end
158
	  end
159
    end
160
  else
161
    print("Out of torches!")
162
  end
163
end
164
165
function checkTorchPlacement()
166
  torchCounter = torchCounter + 1
167
  if torchCounter == torchPlacePoint then
168
    placeTorch()
169
	torchCounter = 0
170
  end
171
end
172
173
if tArgs[1] == nil then
174
  print("Usage: miner <length of shaft")
175
else
176
  shaftLength = tonumber(tArgs[1])
177
  for i = 1, shaftLength do
178
   print("Working on layer "..i)
179
   digLayer()
180
   checkTorchPlacement()
181
  end
182
  print("Job Done!")
183
end