-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcraft.lua
More file actions
117 lines (105 loc) · 2 KB
/
craft.lua
File metadata and controls
117 lines (105 loc) · 2 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
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
local arg = { ... }
print("Recieved " .. #arg .. " arguments.")
if(#arg ~= 1) then
print("Usage: craft.lua <single | 4square | 8ring | 9full>")
exit()
else
recipeID = arg[1]
end
recipes = {
["single"] = {
true, false, false,
false, false, false,
false, false, false
},
["4square"] = {
true, true, false,
true, true, false,
false, false, false
},
["8ring"] = {
true, true, true,
true, false, true,
true, true, true
},
["9full"] = {
true, true, true,
true, true, true,
true, true, true
}
}
recipe = recipes[recipeID]
print("Recipe: ")
storage = 16
firstUsedSlot = 0
needCount = 0
for i = 1, 9 do
if(recipe[i]) then
needCount = needCount + 1
io.write("[X] ")
if(firstUsedSlot < 1) then
firstUsedSlot = i
end
else
io.write("[ ] ")
end
if((i % 3) == 0) then
print(" ")
end
end
print("Needed: " .. needCount)
function dropAll(direction)
for i = 1, 16 do
turtle.select(i)
if(direction == "up") then
turtle.dropUp()
elseif(direction == "down") then
turtle.dropDown()
else
turtle.drop()
end
end
end
function dropExtra()
extra = turtle.getItemCount(storage) % needCount
print("Dropping " .. extra .. " extra items...")
turtle.dropUp(extra)
end
function arrange()
itemsPerSlot = turtle.getItemCount(storage) / needCount
print(itemsPerSlot .. " items per slot.")
c = 1
for i = 1, 11 do
if((i % 4) ~= 0) then
if(recipe[c]) then
turtle.transferTo(i, itemsPerSlot)
end
c = c + 1
end
sleep(0.1)
end
end
function craft()
while(turtle.getItemCount(firstUsedSlot) > 0) do
turtle.craft()
turtle.dropDown()
end
end
dropAll("up")
turtle.select(storage)
while true do
if(turtle.suckUp()) then
suckCount = turtle.getItemCount(storage)
print(suckCount .. " items were sucked. At least " .. needCount .. " are needed.")
if(suckCount >= needCount) then
print("Enough items were sucked.")
dropExtra()
arrange()
craft()
else
print("Not enough items were sucked. Dropping items...")
turtle.dropDown()
end
end
sleep(0.5)
end