Advertisement
toastonrye

Inventory Filter for Mining v1 Youtube

Jul 14th, 2022 (edited)
1,438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --inventory filter, ore dumping for mining
  2. --by toastonrye
  3.  
  4. --Warning this script may break between versions 1.16.5 - 1.19.2
  5.  
  6. local im = peripheral.find("inventoryManager")
  7. local cb = peripheral.find("chatBox")
  8.  
  9. if not im then error("inventoryManager not found") end
  10. if not cb then error("chatBox not found") end
  11.  
  12. local filter, match = false, false
  13. local tagFilter = {"forge:ores", "forge:raw_materials"}
  14.  
  15. local function chatListener()
  16.     while true do
  17.         local event = { os.pullEvent("chat") }
  18.         if event[3]:lower() == "ore on" then
  19.             filter = true
  20.             cb.sendMessageToPlayer("ORE ON", event[2])        
  21.         elseif event[3]:lower() == "ore off" then
  22.             filter = false
  23.             cb.sendMessageToPlayer("ORE OFF", event[2])        
  24.         end
  25.     end
  26. end
  27.  
  28. local function pushItems()
  29.     while true do
  30.         if filter then
  31.             myInv = im.getItems()  
  32.             for slot, item in pairs(myInv) do
  33.                 for _, tag in pairs(item.tags) do
  34.                     for k, v in pairs(tagFilter) do
  35.                         if string.find(tag, v) then
  36.                             match = true
  37.                             break
  38.                         end
  39.                     end
  40.                 end
  41.                 if match then
  42.                     --im.removeItemFromPlayer("UP", item.count, item.slot) NO LONGER WORKS IN 1.19.2
  43.                     print(item.name .. " | " .. item.count)
  44.                     im.removeItemFromPlayerNBT("top", item.count, -1, {fromSlot=item.slot, count=item.count})
  45.                     match = false
  46.                 end    
  47.             end
  48.         end
  49.     os.sleep(10)
  50.     end
  51. end
  52.  
  53. parallel.waitForAny(chatListener, pushItems)   
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement