Blackhome

Filter

Apr 7th, 2025 (edited)
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.94 KB | Gaming | 0 0
  1.     -- pastebin get Em2sZPSF Filter
  2.    
  3.     SE = require("SE")
  4.     SDM = require("SDM")
  5.  
  6.     local function getAvailableItems(list, itemInfo)
  7.         if not list or not itemInfo or not itemInfo.name then return 0 end
  8.         local name = itemInfo.name
  9.  
  10.         local count = 0
  11.        
  12.         local cnt = 0
  13.         for _, item in pairs(list) do
  14.             cnt = cnt + 1
  15.             if item.name == name then
  16.                 count = count + item.count
  17.             end
  18.         end
  19.         return count
  20.     end
  21.  
  22.     local function transportFirstType()
  23.         local chestBack = peripheral.wrap("back")
  24.         if #textutils.serialize(chestBack.list()) > 2 then return nil end
  25.  
  26.         local chestFront = peripheral.wrap("front")
  27.         local chestTop = peripheral.wrap("top")
  28.  
  29.  
  30.         local itemInfo = {
  31.                     name = "", dName = "itemDName",
  32.                     stackSize = 64, number = 0
  33.                 }
  34.         local cnt = 1
  35.        
  36.         local itemList = chestFront.list()
  37.  
  38.         local numItems = #textutils.serialize(itemList)
  39.         local maxItems = itemInfo.stackSize * 16
  40.         while cnt <= 54 and itemInfo.number < maxItems and numItems > 2 do
  41.             local item = chestFront.getItemDetail(cnt, true)
  42.             local itemD = SE.getItemInfo(item)
  43.             if itemD then
  44.                 if itemInfo.name == "" then
  45.                     itemInfo = itemD
  46.                     maxItems = math.min(itemInfo.stackSize * 16, getAvailableItems(itemList, item))
  47.                    
  48.                     itemInfo.number = math.min(itemInfo.number, itemInfo.stackSize * 16)
  49.                     print(maxItems)
  50.                     chestBack.pullItems("front", cnt, itemInfo.number)
  51.                 elseif itemInfo.name == itemD.name then
  52.                     local missing = maxItems - itemInfo.number
  53.                     local pullNumber = math.min(itemD.number, missing)
  54.                     itemInfo.number = itemInfo.number + pullNumber
  55.                     chestBack.pullItems("front", cnt, pullNumber)
  56.                 end
  57.             elseif item then
  58.                 chestTop.pullItems("front", cnt)
  59.             end
  60.             cnt = cnt + 1
  61.         end
  62.         if itemInfo.name == "" then return nil end
  63.         return itemInfo
  64.     end
  65.  
  66.     Filter = {}
  67.  
  68.     function Filter.main()
  69.         local bSleep = false
  70.         while true do
  71.             local incomingItem = SDM.getIncomingItem()
  72.             if incomingItem and #textutils.serialize(incomingItem) == 2 then
  73.                 local itemInfo = transportFirstType()
  74.                 if itemInfo then
  75.                     SDM.setIncomingItem(itemInfo)
  76.                     bSleep = false
  77.                 else
  78.                     sleep(0.5)
  79.                 end
  80.             else
  81.                 if not bSleep then print("Item already incoming") bSleep = true end
  82.                 sleep(0.5)
  83.             end
  84.         end
  85.     end
  86.  
  87.     return Filter
Advertisement
Add Comment
Please, Sign In to add comment