NiallDoherty

Sorting System 2.0

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