Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the peripherals
- local inputInventory = peripheral.wrap("sophisticatedstorage:chest_1")
- local outputInventories = {}
- -- Automatically find and sort connected output inventories
- for i = 1, 25 do
- local outputName = "create:mechanical_crafter_" .. i
- if peripheral.isPresent(outputName) then
- table.insert(outputInventories, peripheral.wrap(outputName))
- else
- error("Output inventory " .. outputName .. " not found!")
- end
- end
- -- Sort outputInventories by number
- table.sort(outputInventories, function(a, b)
- local aName = peripheral.getName(a)
- local bName = peripheral.getName(b)
- local aNumber = tonumber(aName:match("_(%d+)$"))
- local bNumber = tonumber(bName:match("_(%d+)$"))
- return aNumber < bNumber
- end)
- -- Constants
- local IGNORED_ITEM = "securitycraft:reinforced_red_stained_glass_pane"
- local DELAY_SECONDS = 5
- local REDSTONE_SIDES = {"top", "bottom", "left", "right", "front", "back"} -- Add all possible sides
- -- Function to check if any side has redstone input
- local function isRedstoneActive()
- for _, side in ipairs(REDSTONE_SIDES) do
- if redstone.getInput(side) then
- return true
- end
- end
- return false
- end
- -- Function to run the transfer logic
- local function distributeItems()
- local outputInventoriesIndex = 1
- -- Loop through each slot in the input inventory
- for slot = 1, inputInventory.size() do
- if outputInventoriesIndex > #outputInventories then
- print("All output inventories are full or processed.")
- break
- end
- local item = inputInventory.getItemDetail(slot)
- if item then
- if item.name == IGNORED_ITEM then
- -- Ignore this item
- print("Ignored item in slot " .. slot)
- else
- -- Transpose the item to the corresponding output inventory using pullItems
- local transferred = outputInventories[outputInventoriesIndex].pullItems(
- peripheral.getName(inputInventory),
- slot,
- item.count
- )
- if transferred > 0 then
- outputInventoriesIndex = outputInventoriesIndex + 1
- end
- end
- else
- -- Empty slot, move to the next output inventory
- outputInventoriesIndex = outputInventoriesIndex + 1
- end
- end
- end
- -- Main loop
- while true do
- if isRedstoneActive() then
- distributeItems()
- end
- sleep(DELAY_SECONDS)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement