-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrip.lua
More file actions
78 lines (76 loc) · 2.06 KB
/
strip.lua
File metadata and controls
78 lines (76 loc) · 2.06 KB
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
local args = {...}
if not args[1] then
args[1] = 5
end
function torch()
for i=1,16 do
if turtle.getItemCount(i)>0 and turtle.getItemDetail(i).name == "minecraft:torch" then
turtle.select(i)
turtle.placeDown()
return true
end
end
return false
end
function refuel()
if turtle.getFuelLevel() < 200 then
-- Going backwards to use newer materials first
for i=16,1,-1 do
select(i)
if turtle.refuel(10) then return true end
end
end
return false
end
function isInvFull()
local full = true
for i=1,16 do
-- if every slot has items, the var full will be true
full = full and turtle.getItemCount(i)>0
end
return full
end
-- returns the index of a barrel
function getBarrel()
for i=1,16 do
if turtle.getItemCount(i)>0 and string.find(turtle.getItemDetail(i).name, "barrel") then
return i
end
end
return nil
end
-- returns false on failure, true in all other cases
function deposit(dis)
if isInvFull() then
local barrel = getBarrel()
if not barrel then print("No Barrels Found to use!") return false end
turtle.select(barrel)
turtle.turnRight()
turtle.dig()
turtle.place()
-- place all items in the barrel
for i=1,16 do
turtle.select(i)
local name = turtle.getItemDetail().name
if not (name == "minecraft:torch" or string.find(name,"barrel")) then
turtle.drop()
end
end
turtle.turnLeft()
print("Items deposited at "..dis.." blocks.")
end
return true
end
for i=1,args[1]+1 do
if refuel() then print("Turtle Refueled") end
turtle.digDown()
turtle.digUp()
if i%8==0 then torch() end
if i%5==0 then deposit(i) end -- hopefully this check is often enough
while not turtle.forward() do
turtle.dig()
turtle.attack()
end
if i%25==0 then print("Mined "..i.." Blocks") end
end
print("Strip Mining Complete")