Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --nb of item per packet (1 for simple conversion, 4 for 2*2 grid crafting, 9 for 3*3 grid crafting)
- psize=9
- --packager side
- side="bottom"
- function compactInv()
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 and turtle.getItemCount(i) < 64 then
- turtle.select(i)
- for j = i+1,16 do
- if turtle.compareTo(j) then
- turtle.select(j)
- turtle.transferTo(i)
- turtle.select(i)
- end
- end
- end
- end
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 then
- for j = 1,i do
- if turtle.getItemCount(j) == 0 then
- turtle.select(i)
- turtle.transferTo(j)
- break
- end
- end
- end
- end
- end
- function nextSlot(slot)
- if slot == 16 then
- return 1
- else
- return slot + 1
- end
- end
- function sendStackToPackager(packager,slot,packetSize)
- print("Sending slot "..slot.. " to packager in packets of "..packetSize.." items.")
- waitBeforeNextSlot = not turtle.compareTo(nextSlot(slot))
- while turtle.getItemCount(slot) >= packetSize do
- --print(" enough items left to package ("..turtle.getItemCount(slot)..").")
- buffer = packager.getStackInSlot(1)
- while buffer ~= null and buffer["qty"] >= (64-packetSize) do
- print("--Packager Overflow : Waiting 3s ("..buffer["qty"].." items left).")
- sleep(3)
- buffer = packager.getStackInSlot(1)
- end
- print("--Packager OK : dropping down "..packetSize.." items from slot "..slot..".")
- turtle.dropDown(packetSize)
- sleep(0.2)
- end
- if waitBeforeNextSlot then
- buffer = packager.getStackInSlot(1)
- while buffer ~= null and buffer["qty"] > 0 do
- if bak == buffer["qty"] then
- print("There seems to be a problem with the packager : buffer size("..bak..") doesn't change.")
- end
- bak = buffer["qty"]
- print("--Slot Transiton : waiting ...")
- sleep(1.2)
- buffer = packager.getStackInSlot(1)
- end
- end
- end
- local packager = peripheral.wrap(side)
- while true do
- print("Compacting ...")
- compactInv()
- for i=1,16 do
- turtle.select(i)
- sendStackToPackager(packager,i,psize)
- sleep(0.2)
- end
- sleep(2)
- end
Add Comment
Please, Sign In to add comment