View difference between Paste ID: FzFrCDxw and jeZTyH7G
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
97+
    while turtle.detectUp() == true do
98
	  turtle.digUp()
99
	end
100
  end
101
end
102
103
function dig(distance)
104
  if distance == nil then distance = 1 end
105
  for i = 1, distance do
106-
    while turtle.detect() == true
106+
    while turtle.detect() == true do
107
	  turtle.dig()
108
	end
109
  end
110
end
111
112
function digDown(distance)
113
  if distance == nil then distance = 1 end
114
  for i = 1, distance do
115
	turtle.digDown()
116
  end
117
end
118
119
function goToFloor()
120
  if currentLevel > 0 then
121-
    while turtle.detectDown == false()
121+
    while turtle.detectDown == false() do
122
      goDown()
123
	  if currentLevel == 0 then
124
	     print("Possibly over a chasm. Breaking")
125
		 return false
126
	  end
127
    end
128
  end
129
  return true
130
end
131
132
function placeTorch()
133
  turtle.select(torchSlot)
134
  if turtle.compareTo(torchCompareSlot) == true then
135
    if turtle.detectDown == true then
136
	  turnAround()
137
	  goForward(1)
138
	  if turtle.detectDown() == true then
139
	    goBack(1)
140
        turtle.placeDown()
141
	    turnAround()
142
	  end
143
    else
144
      if goToFloor() == true then
145
	    turnAround()
146
		goForward(1)
147-
		if turtle.detectDown == true then
147+
		if turtle.detectDown() == true then
148
		  goBack(1)
149
		  turtle.placeDown()
150
		  turnAround()
151
		end
152
    end
153
  else
154
    print("Out of torches!")
155
  end
156
end
157
158
function checkTorchPlacement()
159
  torchCounter = torchCounter + 1
160
  if torchCounter == torchPlacePoint then
161
    placeTorch()
162
	torchCounter = 0
163
  end
164
end
165
166
if tArgs[1] == nil then
167
  print("Usage: miner <length of shaft")
168
else
169
  shaftLength = tonumber(tArgs[1])
170
  for i = 1, shaftLength do
171
   print("Working on layer "..i)
172
   digLayer()
173
   checkTorchPlacement()
174
  end
175
  print("Job Done!")
176
end