Posted 29 April 2014 - 03:45 PM
Well, since Buildcraft has nerfed the Auto crafting table pretty heavily, I needed something with a bit more speed.
After hours of headache, I've come up with basically a turtle equivalent of the ACT from the old Buildcraft :D/>
It can craft up to whole stacks-1 in a single operation. It won't pull items out of adjacent chests unfortunately, but you can pump items into it from all sides but the front, where it spits out the crafted items. It also can not use multi-use tools (saws, hammers etc) as the turtle only sees 1 of those items per slot, and thinks crafting it would leave the slot empty.
To use, simply place your recipe in the top left 3x3 grid as you would a crafting table, and start the program. You will need to restart the program if you change the recipe. It will always leave a copy of the recipe in the turtle, and it'll evenly distribute the items so that it can craft with the bare minimum resources, just like the ACT. It will also check the slots outside of the 3x3 area and clear them if needed, as they interfere with the crafting.
By default the turtle re-checks every 2 seconds, but you can change that with the os.sleep right at the bottom, or modify it to run from a redstone input, whatever :D/>
I've tested it a few times and all seems good, but please let me know if you decide to try it and come across any bugs :)/>
The code:
http://pastebin.com/bkVFmFzX
Updated 30/4, prevents crafting out of range error.
Thanks to Lyqyd for the item comparison script :)/>
Hope it's useful!
After hours of headache, I've come up with basically a turtle equivalent of the ACT from the old Buildcraft :D/>
It can craft up to whole stacks-1 in a single operation. It won't pull items out of adjacent chests unfortunately, but you can pump items into it from all sides but the front, where it spits out the crafted items. It also can not use multi-use tools (saws, hammers etc) as the turtle only sees 1 of those items per slot, and thinks crafting it would leave the slot empty.
To use, simply place your recipe in the top left 3x3 grid as you would a crafting table, and start the program. You will need to restart the program if you change the recipe. It will always leave a copy of the recipe in the turtle, and it'll evenly distribute the items so that it can craft with the bare minimum resources, just like the ACT. It will also check the slots outside of the 3x3 area and clear them if needed, as they interfere with the crafting.
By default the turtle re-checks every 2 seconds, but you can change that with the os.sleep right at the bottom, or modify it to run from a redstone input, whatever :D/>
I've tested it a few times and all seems good, but please let me know if you decide to try it and come across any bugs :)/>
The code:
http://pastebin.com/bkVFmFzX
local slots = {}
--# Fill a table with the sixteen slot IDs.
for i = 1, 16 do
slots[i] = i
end
local matches = {}
local itemCount = 0
local numItems = 0
local leastItems = 64
function clearOuterSlots()
for i=4,16,4 do
if turtle.getItemCount(i) > 0 then
turtle.select(i)
turtle.drop(i)
end
end
for i = 13,15 do
if turtle.getItemCount(i) > 0 then
turtle.select(i)
turtle.drop(i)
end
end
end
clearOuterSlots()
print("Reading recipe ..")
while #slots > 0 do
--# Get the next slot number from the slot ID table
local current = table.remove(slots, 1)
--# Create a new match set including it.
if turtle.getItemCount(current) > 0 then
local match = {current}
turtle.select(current)
--# Check the contents of that slot against the remaining unmatched slots.
for i = #slots, 1, -1 do
if turtle.compareTo(slots[i]) then
table.insert(match, table.remove(slots, i))
end
end
--# Sort the slot IDs in the current set of matches (optional)
table.sort(match)
--# Add the current set of matches to the final table.
table.insert(matches, match)
end
end
print("Done! Running ...")
print("Make sure to restart script to change recipe!")
while true do
clearOuterSlots()
for i = 1,#matches do
for k = 1,#matches[i] do
itemCount = itemCount + turtle.getItemCount(matches[i][k])
--print(string.format("Match %d: %d / %d", i, matches[i][k], itemCount))
numItems = k
end
local perSlot = math.floor(itemCount / numItems)
--print(string.format("Item %d per slot: %d", numItems, perSlot))
for k = 1,#matches[i] do
local slotItemCount = turtle.getItemCount(matches[i][k])
if slotItemCount < perSlot then
--print(string.format("Slot %d has less than %d items", matches[i][k], perSlot))
for j = 1,#matches[i] do
if turtle.getItemCount(matches[i][j]) > perSlot then
local requiredItems = perSlot - turtle.getItemCount(matches[i][k])
if (turtle.getItemCount(matches[i][j]) - requiredItems) >= perSlot then
turtle.select(matches[i][j])
turtle.transferTo(matches[i][k], requiredItems)
else
for w=1,requiredItems do
while turtle.getItemCount(matches[i][j]) > perSlot do
turtle.select(matches[i][j])
turtle.transferTo(matches[i][k], 1)
end
end
end
--print(requiredItems)
--print(string.format("Transferring %d items from %d to %d", requiredItems, matches[i][j], matches[i][k]))
end
end
end
end
itemCount = 0
numItems = 0
end
for i=1,3 do
if turtle.getItemCount(i) < leastItems then
leastItems = turtle.getItemCount(i)
end
end
for i=5,7 do
if turtle.getItemCount(i) < leastItems then
leastItems = turtle.getItemCount(i)
end
end
for i=9,11 do
if turtle.getItemCount(i) < leastItems then
leastItems = turtle.getItemCount(i)
end
end
if leastItems-1 > 0 then
--print(string.format("Crafting %d items ..", (leastItems-1)))
turtle.select(16)
turtle.craft(leastItems-1)
turtle.drop()
end
leastItems = 64
os.sleep(2)
end
Updated 30/4, prevents crafting out of range error.
Thanks to Lyqyd for the item comparison script :)/>
Hope it's useful!
Edited on 29 April 2014 - 11:08 PM