-
Notifications
You must be signed in to change notification settings - Fork 0
/
Template.lua
129 lines (118 loc) · 3.38 KB
/
Template.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
local Helper = require("Helper")
local args = {...}
local states = Helper.readState()
local temp = {
1,
1
}
if(states[1] == nil) then
print("Generating New States.txt")
Helper.writeState(temp)
states = temp
end
local acceptedFuels = {
"minecraft:coal_block",
"minecraft:coal",
"minecraft:lava_bucket",
"bloodmagic:lava_crystal"
}
local fuelSlots = {}
for x = 1, #acceptedFuels do
local slot = Helper.GetItem(acceptedFuels[x])
if(slot ~= nil) then
table.insert(fuelSlots, slot)
end
end
-- 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
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
-- just walks the desired length forward
local function walk(length)
for i = 1, length, 1 do
turtle.forward()
end
end
local function deposit()
turtle.turnLeft()
turtle.turnLeft()
local isBlock, block = turtle.inspect()
if(isBlock) then
if(string.match(block.name, "chest") ~= nil) then
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
for i = 1, 16, 1 do
turtle.select(i)
local allowed = true
for x = 1, #unallowedSlots do
if(i == unallowedSlots[x]) then
allowed = false
end
end
if(allowed)then
turtle.drop()
end
end
turtle.turnLeft()
turtle.turnLeft()
return
end
end
turtle.turnLeft()
turtle.turnLeft()
print("Please place a chest behind the turtle")
end
local function doStuff()
print("doStuff finished")
end
term.setTextColor( colors.yellow )
-- 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
-- Normal Operation
term.setTextColor( colors.white )
print("Startup finished")
while true do
fuelling()
doStuff()
deposit()
sleep(400)
end