-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStripMining.lua
265 lines (245 loc) · 7.97 KB
/
StripMining.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
local Helper = require("Helper")
local args = {...}
local amountCrossings = 5 -- DEFAULT
local sideTunnelLength = 5 -- DEFAULT
local distanceBetweenCrossings = 3 -- DEFAULT
local acceptedFuels = {
"minecraft:coal_block",
"minecraft:coal",
"minecraft:lava_bucket"
}
local fluids = {
"minecraft:water",
"minecraft:lava",
"galacticraftcore:crude_oil"
}
local trash = {
"minecraft:cobblestone"
}
local fuelSlots = {}
for x = 1, #acceptedFuels do
local slot = Helper.GetItem(acceptedFuels[x])
if(slot ~= nil) then
table.insert(fuelSlots, slot)
end
end
local torchSlot = Helper.GetItem("minecraft:torch")
local chestSlot = Helper.GetItem("minecraft:chest")
-- fuels the turtle and updates the fueltable
local function fuelling()
if(turtle.getFuelLevel ~= "unlimited" and turtle.getFuelLevel() < 50) then
for x = 1, #fuelSlots do
local data = turtle.getItemDetail(fuelSlots[x])
if(data ~= nil) then
turtle.select(fuelSlots[x])
turtle.refuel()
return
else
table.remove(fuelSlots, x)
end
end
if(next(fuelSlots) == nil) then
for x = 1, #acceptedFuels do
local slot = Helper.GetItem(acceptedFuels[x])
if(slot ~= nil) then
table.insert(fuelSlots, slot)
return
end
end
if(next(fuelSlots) == nil) then
local isnil = true
term.setTextColor( colors.red )
print("No Fuel Any more")
term.setTextColor( colors.white )
while(isnil) do
for x = 1, #acceptedFuels do
local slot = Helper.GetItem(acceptedFuels[x])
if(slot ~= nil) then
table.insert(fuelSlots, slot)
isnil = false
end
end
end
term.setTextColor( colors.yellow )
print("Got Fuel, Continuing")
term.setTextColor( colors.white )
fuelling()
end
end
end
end
-- cleans the Inventory from any ores and stone/ obsidian
-- without putting torches fuel or chests out of its inventory
local function clearInventory()
for x = 1, #trash do
Helper.DropItem(trash[x])
end
if(Helper.isInvFull()) then
print("Inventory is full")
if(chestSlot ~= nil) then
if(turtle.getItemDetail(chestSlot).name == "minecraft:chest") then
print("Depositing into Chest")
turtle.back()
turtle.select(chestSlot)
turtle.placeDown()
local unallowedSlots = {}
for x = 1, #fuelSlots do
local data = turtle.getItemDetail(fuelSlots[x])
if(data ~= nil and data.name ~= "minecraft:bucket") then
table.insert(unallowedSlots, fuelSlots[x])
else
table.remove(fuelSlots, x)
end
end
if(turtle.getItemDetail(torchSlot) ~= nil) then
table.insert(unallowedSlots, torchSlot)
end
if(turtle.getItemDetail(chestSlot) ~= nil) then
table.insert(unallowedSlots, chestSlot)
end
for i = 1, 16, 1 do
local allowed = true
for x = 1, #unallowedSlots do
if(i == unallowedSlots[x]) then
allowed = false
end
end
if(allowed)then
turtle.dropDown()
end
end
turtle.forward()
end
end
end
end
-- just walks the desired length forward
local function walk(length)
for i = 1, length, 1 do
turtle.forward()
end
end
local function checkforFuild()
local isBlock, block = turtle.inspect()
for x = 1, #fluids do
if(block.name == fluids[x]) then
return true
end
end
return false
end
local function digUp()
local isBlock, block = turtle.inspectUp()
while(isBlock) do
isBlock, block = turtle.inspectUp()
if(checkforFuild()) then
return
else
turtle.digUp()
end
end
end
local function dig()
local isBlock, block = turtle.inspect()
while(isBlock) do
isBlock, block = turtle.inspect()
if(checkforFuild()) then
return
else
turtle.dig()
end
end
end
-- another (unused) possibility:
local function unuseddig()
if(turtle.dig()) then
unuseddig()
else
return
end
end
local function digDown()
local isBlock, block = turtle.inspectDown()
while(isBlock) do
isBlock, block = turtle.inspectDown()
if(checkforFuild()) then
return
else
turtle.digDown()
end
end
end
-- is just digging a three high one wide tunnel (digs down, up and forward)
local function digForwardTunnel(tunnelLength)
for i = 1, tunnelLength, 1 do
dig()
turtle.forward()
digUp()
digDown()
end
end
-- Does the whole stripmine from one crossing to another
-- aka. form one sidetunnel to another
local function crossingToCrossing(tunnelLength, distanceBetween)
turtle.turnLeft()
for i = 1, 2, 1 do
digForwardTunnel(tunnelLength)
turtle.turnRight()
turtle.turnRight()
walk(tunnelLength)
end
turtle.turnRight()
digForwardTunnel(distanceBetween)
end
-- check if args are filled in, or args == -h (-h stands for --help)
if(args == nil or args == "-h") then
error("stripmine AMOUNTOFCROSSINGS SIDETUNNELLENGTH DISTANCEBETWEENCROSSINGS \n all in CAPS are variables which you have to replace with your desired values (integer / numbers)",4)
else
-- FIXME: this check of args doesn't work, and args are not used yet
if(args[1] ~= nil ) then
amountCrossings = tonumber(args[1])
else
--error("You have to specify the amount of Crossings you want\n more info try: StripMining -h",4)
end
if(args[2] ~= nil ) then
sideTunnelLength = tonumber(args[2])
else
--error("You have to specify how long the sideTunnel should be\n more info try: StripMining -h",4)
end
if(args[3] ~= nil ) then
distanceBetweenCrossings = tonumber(args[3])
else
--error("You have to specify how long the Distance between two Crossings should be\n more info try: StripMining -h",4)
end
end
term.setTextColor( colors.yellow )
-- check if enough torches
if(torchSlot == nil or turtle.getItemCount(torchSlot) <= amountCrossings /2 ) then
print("WARNING: you do not have enough torches in the inventory to light up the mine")
end
-- check if fuel exists
if(next(fuelSlots) == nil ) then
print("WARNING: you do not have any fuel, the turtle is likely to run out of juice \nCurrent Fuel: ", turtle.getFuelLevel())
end
-- check if chests exist
if(chestSlot == nil or turtle.getItemCount(chestSlot) < 1 ) then
print("WARNING: you do not have any chests in the inventory, some ores will likely be lost")
end
-- Normal Operation
term.setTextColor( colors.white )
for i = 1, amountCrossings, 1 do
fuelling()
clearInventory()
crossingToCrossing(sideTunnelLength, distanceBetweenCrossings)
if(i % 2 == 0 and torchSlot ~= nil) then
print(turtle.getItemDetail(torchSlot).name, " == minecraft:torch")
if(turtle.getItemDetail(torchSlot).name == "minecraft:torch") then
turtle.select(torchSlot)
turtle.placeDown()
end
end
print("Finished Crossing ",i, " with ", turtle.getFuelLevel(), " Fuel")
end
term.setTextColor( colors.green )
print("Stripmining finished")
term.setTextColor( colors.white )