NiallDoherty

Sorting System 2.0

Dec 5th, 2020 (edited)
855
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local ender = peripheral.find("enderstorage:ender_chest")
  2.  
  3. local controllers = table.pack(peripheral.find("storagedrawers:controller"))
  4.  
  5. local mekanismLocation = "ironchest:obsidian_chest_2"
  6. local mekanismFilter = "mekanism"
  7.  
  8. local immersiveLocation = "ironchest:obsidian_chest_0"
  9. local immersiveFilter = "immersive"
  10.  
  11. local someMachinesLocation = "ironchest:obsidian_chest_6"
  12. local machineFilter = {"foregoing", "computercraft", "enderstorage", "fluxnetworks"}
  13.  
  14. local organicsLocation = "ironchest:obsidian_chest_3"
  15. local organicItemsFilter = {"petal", "dye", "flower", "mushroom", "head", "tear", "shell", "kelp", "bat_wing"}
  16.  
  17. local woodItemsLocation = "ironchest:obsidian_chest_5"
  18. local woodItemsFilter = {
  19.     "scaffold", "minecraft:chest", "sign", "fence_gate", "crafting_table",
  20.     "storagedrawers", "bowl"}
  21.  
  22. local potionsLocation = "ironchest:iron_chest_0"
  23. local potionsFilter = "potions"
  24.  
  25. local forbiddenArtifactsLocation = "ironchest:obsidian_chest_4"
  26. local forbiddenArtifactsFilter = {"forbidden", "artifacts"}
  27.  
  28. local locationsMap = {
  29.     [mekanismLocation] = mekanismFilter,
  30.     [immersiveLocation] = immersiveFilter,
  31.     [someMachinesLocation] = machineFilter,
  32.     [potionsLocation] = potionsFilter,
  33.     [forbiddenArtifactsLocation] = forbiddenArtifactsFilter,
  34.     [woodItemsLocation] = woodItemsFilter,
  35.     [organicsLocation] = organicItemsFilter
  36. }
  37.  
  38. local function moveItem(itemName, slot)
  39.     for i = 1, #controllers do
  40.         local amount = ender.pushItems(peripheral.getName(controllers[i]), slot)
  41.         if amount > 0 then
  42.             if amount == item.count then
  43.                 return item.count
  44.             end
  45.             print("Sending " .. itemName .. " to overflow.")
  46.             i = #controllers
  47.         end
  48.     end
  49.     for k, v in pairs(locationsMap) do
  50.         if type(v) == "string" then
  51.             if itemName:find(v) then
  52.                 return ender.pushItems(k, slot)
  53.             end
  54.         end
  55.         if type(v) == "table" then
  56.             for i = 1, #v do
  57.                 if itemName:find(v[i]) then
  58.                     return ender.pushItems(k, slot)
  59.                 end
  60.             end
  61.         end  
  62.     end
  63.     return ender.pushItems("ironchest:diamond_chest_5", slot)
  64. end
  65.  
  66. local function moveItems()
  67.     for i = 1, ender.size() do
  68.         item = ender.getItemDetail(i)
  69.         if item then
  70.             if moveItem(item.name, i) < item.count then
  71.                 print("No space for: " .. item.name)
  72.             end
  73.         end
  74.     end
  75. end
  76.  
  77. while true do
  78.     moveItems()
  79.     sleep(1)
  80. end
  81.  
RAW Paste Data