Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get Em2sZPSF Filter
- SE = require("SE")
- SDM = require("SDM")
- local function getAvailableItems(list, itemInfo)
- if not list or not itemInfo or not itemInfo.name then return 0 end
- local name = itemInfo.name
- local count = 0
- local cnt = 0
- for _, item in pairs(list) do
- cnt = cnt + 1
- if item.name == name then
- count = count + item.count
- end
- end
- return count
- end
- local function transportFirstType()
- local chestBack = peripheral.wrap("back")
- if #textutils.serialize(chestBack.list()) > 2 then return nil end
- local chestFront = peripheral.wrap("front")
- local chestTop = peripheral.wrap("top")
- local itemInfo = {
- name = "", dName = "itemDName",
- stackSize = 64, number = 0
- }
- local cnt = 1
- local itemList = chestFront.list()
- local numItems = #textutils.serialize(itemList)
- local maxItems = itemInfo.stackSize * 16
- while cnt <= 54 and itemInfo.number < maxItems and numItems > 2 do
- local item = chestFront.getItemDetail(cnt, true)
- local itemD = SE.getItemInfo(item)
- if itemD then
- if itemInfo.name == "" then
- itemInfo = itemD
- maxItems = math.min(itemInfo.stackSize * 16, getAvailableItems(itemList, item))
- itemInfo.number = math.min(itemInfo.number, itemInfo.stackSize * 16)
- print(maxItems)
- chestBack.pullItems("front", cnt, itemInfo.number)
- elseif itemInfo.name == itemD.name then
- local missing = maxItems - itemInfo.number
- local pullNumber = math.min(itemD.number, missing)
- itemInfo.number = itemInfo.number + pullNumber
- chestBack.pullItems("front", cnt, pullNumber)
- end
- elseif item then
- chestTop.pullItems("front", cnt)
- end
- cnt = cnt + 1
- end
- if itemInfo.name == "" then return nil end
- return itemInfo
- end
- Filter = {}
- function Filter.main()
- local bSleep = false
- while true do
- local incomingItem = SDM.getIncomingItem()
- if incomingItem and #textutils.serialize(incomingItem) == 2 then
- local itemInfo = transportFirstType()
- if itemInfo then
- SDM.setIncomingItem(itemInfo)
- bSleep = false
- else
- sleep(0.5)
- end
- else
- if not bSleep then print("Item already incoming") bSleep = true end
- sleep(0.5)
- end
- end
- end
- return Filter
Advertisement
Add Comment
Please, Sign In to add comment