Posted 06 April 2014 - 11:50 AM
This is my first (semi-useful) program. It crafts using tables to get recipes.
The command is "craft <Item name>.
Code:
recipes = {
chest = {
1,1,1,0,
1,0,1,0,
1,1,1,0,
0,0,0,0 },
furnace = {
1,1,1,0,
1,0,1,0,
1,1,1,0,
0,0,0,0 },
pickaxe = {
1,1,1,0,
0,1,0,0,
0,1,0,0,
0,0,0,0 },
}
r = args[1]
if r == "chest" then r = 0
elseif r == "furnace" then r = 1
elseif r == "pickaxe" then r = 2
end
turtle.select(16)
if r == 0 then
print("Please put 8 planks into slot 16.")
while turtle.getItemCount(16) ~= 8 do sleep(0.5) end
print("Crafting…")
for i=1, #recipes.chest do
if i + 1 == 17 then
turtle.craft()
print("Finished.")
return
else
if recipes.chest == 0 then
else
turtle.transferTo(i,1)
end
if turtle.getItemCount(16) == 0 then
turtle.select(15)
end
end
end
elseif r == 1 then
print("Please put 8 cobblestones into slot 16.")
while turtle.getItemCount(16) ~= 8 do sleep(0.5) end
print("Crafting…")
for i=1, #recipes.furnace do
if i + 1 == 17 then
turtle.craft()
print("Finished.")
return
else
if recipes.furnace == 0 then
else
turtle.transferTo(i,1)
end
if turtle.getItemCount(16) == 0 then
turtle.select(15)
end
end
end
elseif r == 2 then
print("Please put 3 head materials in slot 16 and 2 sticks in slot 15.")
while turtle.getItemCount(16) ~= 3 or turtle.getItemCount(15) ~= 2 do sleep(0.5) end
print("Crafting…")
for i=1, #recipes.pickaxe do
if i + 1 == 17 then
turtle.craft()
print("Finished.")
return
else
if recipes.pickaxe == 0 then
turtle.select(i+1)
else
turtle.transferTo(i,1)
end
if turtle.getItemCount(16) == 0 then
turtle.select(15)
end
end
end
end
Damn it, indentation doesn't show up.
The command is "craft <Item name>.
Code:
Spoiler
args = {…}recipes = {
chest = {
1,1,1,0,
1,0,1,0,
1,1,1,0,
0,0,0,0 },
furnace = {
1,1,1,0,
1,0,1,0,
1,1,1,0,
0,0,0,0 },
pickaxe = {
1,1,1,0,
0,1,0,0,
0,1,0,0,
0,0,0,0 },
}
r = args[1]
if r == "chest" then r = 0
elseif r == "furnace" then r = 1
elseif r == "pickaxe" then r = 2
end
turtle.select(16)
if r == 0 then
print("Please put 8 planks into slot 16.")
while turtle.getItemCount(16) ~= 8 do sleep(0.5) end
print("Crafting…")
for i=1, #recipes.chest do
if i + 1 == 17 then
turtle.craft()
print("Finished.")
return
else
if recipes.chest == 0 then
else
turtle.transferTo(i,1)
end
if turtle.getItemCount(16) == 0 then
turtle.select(15)
end
end
end
elseif r == 1 then
print("Please put 8 cobblestones into slot 16.")
while turtle.getItemCount(16) ~= 8 do sleep(0.5) end
print("Crafting…")
for i=1, #recipes.furnace do
if i + 1 == 17 then
turtle.craft()
print("Finished.")
return
else
if recipes.furnace == 0 then
else
turtle.transferTo(i,1)
end
if turtle.getItemCount(16) == 0 then
turtle.select(15)
end
end
end
elseif r == 2 then
print("Please put 3 head materials in slot 16 and 2 sticks in slot 15.")
while turtle.getItemCount(16) ~= 3 or turtle.getItemCount(15) ~= 2 do sleep(0.5) end
print("Crafting…")
for i=1, #recipes.pickaxe do
if i + 1 == 17 then
turtle.craft()
print("Finished.")
return
else
if recipes.pickaxe == 0 then
turtle.select(i+1)
else
turtle.transferTo(i,1)
end
if turtle.getItemCount(16) == 0 then
turtle.select(15)
end
end
end
end
Damn it, indentation doesn't show up.
Edited on 06 April 2014 - 09:51 AM