So as many of us know, automating the crystallizer from Factorization is a bit of a pain because it doesn't automatically distribute items placed into it, and it can only create 1 type of item at a time. To that end, and with the help of OpenPeripherals and Computercraft, I give you... what I have yet to come up with a name for.
A little preface, this proof of concept was created in the Direwolf20 1.6.4 1.0.16 (1.0.14 and below don't work correctly with peripheral proxies, which are required on the chest) modpack. In my example, the buffer chest is south of the crystallizer (note that this seems backwards in the code and I'm not sure why but that's how it works), and both are hooked up to a computer using wired modems (though in theory wireless should work too) with the peripheral names crystallizer_1 and container_chest_0 respectively. An impulse itemduct sits below the crystallizer to pull out all the goods.
The program assumes the bottle of aqua regia to be in slot #6 of the crystallizer (left of the topmost slot) and it assumes that no one will be throwing other items into the crystallizer manually (no fault tolerance, figuring out what to do with those items was more of a headache than I could afford right now). Otherwise it's completely autonomous and utilizes (container).pullItemIntoSlot to move items around.
Feel free to suggest improvements, I've been sick while working on this (hence the time to do it). And feel free to repost this, just drop my name and it's all good.
A pastebin of the code is at Mq013acZ (http://pastebin.com/Mq013acZ)
A little preface, this proof of concept was created in the Direwolf20 1.6.4 1.0.16 (1.0.14 and below don't work correctly with peripheral proxies, which are required on the chest) modpack. In my example, the buffer chest is south of the crystallizer (note that this seems backwards in the code and I'm not sure why but that's how it works), and both are hooked up to a computer using wired modems (though in theory wireless should work too) with the peripheral names crystallizer_1 and container_chest_0 respectively. An impulse itemduct sits below the crystallizer to pull out all the goods.
The program assumes the bottle of aqua regia to be in slot #6 of the crystallizer (left of the topmost slot) and it assumes that no one will be throwing other items into the crystallizer manually (no fault tolerance, figuring out what to do with those items was more of a headache than I could afford right now). Otherwise it's completely autonomous and utilizes (container).pullItemIntoSlot to move items around.
Feel free to suggest improvements, I've been sick while working on this (hence the time to do it). And feel free to repost this, just drop my name and it's all good.
A pastebin of the code is at Mq013acZ (http://pastebin.com/Mq013acZ)
Code:
prfCrystal = peripheral.wrap("crystallizer_1")
prfChest = peripheral.wrap("container_chest_0")
dirChest = "north"
dirCrystal = "south"
function getInv(prfSource)
return prfSource.getAllStacks()
end
function filterInv(prfSource, intId, intDmg)
intDmg = intDmg or 0
arrSource = getInv(prfSource)
arrInv = {}
for i,v in pairs(arrSource) do
if (v["id"] == intId and v["dmg"] == intDmg) then
arrInv[i] = v["qty"]
end
end
return arrInv
end
function countId(prfSource, intId, intDmg) -- return the number of intId:intDmg in inventory prfSource
intCount = 0
intDmg = intDmg or 0
arrInv = getInv(prfSource)
for i,v in pairs(arrInv) do
if (v["id"] == intId and v["dmg"] == intDmg) then
intCount = intCount + v["qty"]
end
end
return intCount
end
function filterInCrystallizer(prfSource, intItem, intDmg)
intDmg = intDmg or 0
arrContent = getInv(prfSource)
arrInv = {0,0,0,0,0}
for i=1, 5 do
if arrContent[i] then
if (arrContent[i]["id"] == intItem and arrContent[i]["dmg"] == intDmg) then
arrInv[i] = arrContent[i]["qty"]
end
end
end
return arrInv
end
function inCrystallizer(prfSource)
arrContent = getInv(prfSource)
arrInv= {}
tmp = {}
for i=1, 5 do
if arrContent[i] then
tmp["id"] = arrContent[i]["id"]
tmp["dmg"] = arrContent[i]["dmg"]
arrInv[i] = tmp
end
end
return arrInv
end
function equalize(prfSource, prfDest)
intQty = 0
intSplit = 0
intId = 0
intDmg = 0
intOdd = 0
intPullList = {0,0,0,0,0}
destInv = inCrystallizer(prfDest)
prfSource.condenseItems()
if table.getn(destInv) == 0 then
if table.getn(getInv(prfSource)) == 0 then return end
tgt = prfSource.getStackInSlot(1)
intId = tgt["id"]
intDmg = tgt["dmg"]
else
for _,v in pairs(destInv) do
intId = v["id"]
intDmg = v["dmg"]
end
end
intQty = countId(prfSource, intId, intDmg) + countId(prfDest, intId, intDmg)
intSplit = math.min(64, math.floor(intQty / 5))
if intSplit ~= 64 then
intOdd = intQty % 5
end
term.clear()
print (intId .. ":" .. intDmg .. " " .. intQty .. " " .. intSplit .. "*5 + " .. intOdd)
for i=1, 5 do
tmpPull = intSplit - filterInCrystallizer(prfDest, intId, intDmg)[i]
if i <= intOdd then tmpPull = tmpPull + 1 end
sourceInv = filterInv(prfSource, intId, intDmg)
for j,k in pairs(sourceInv) do
tmpPull = tmpPull - prfDest.pullItem(dirCrystal, j, tmpPull, i)
if tmpPull == 0 then break end
end
end
end
-- main loop
while true do
equalize(prfChest, prfCrystal)
sleep(0.5)
end
Last edited: