Advertisement
NiallDoherty

Item Sorting System

Dec 5th, 2020 (edited)
1,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.00 KB | None | 0 0
  1. local ender = peripheral.find("enderstorage:ender_chest")
  2. local enderName = peripheral.getName(ender)
  3.  
  4. local controllers = table.pack({peripheral.find("storagedrawers:controller")})
  5.  
  6.  
  7. local mek = peripheral.wrap("ironchest:obsidian_chest_2")
  8. local mekName = peripheral.getName(mek)
  9.  
  10. local imm = peripheral.wrap("ironchest:obsidian_chest_0")
  11. local immName = peripheral.getName(imm)
  12.  
  13. local foregoing = peripheral.wrap("ironchest:obsidian_chest_6")
  14. local foregoingName = peripheral.getName(foregoing)
  15.  
  16. local organics = peripheral.wrap("ironchest:obsidian_chest_3")
  17. local organicsName = peripheral.getName(organics)
  18.  
  19. local organicNames = {"petal", "dye", "flower", "mushroom", "head", "tear", "shell", "kelp", "wing"}
  20.  
  21. local woodItems = peripheral.wrap("ironchest:obsidian_chest_5")
  22. local woodItemsName = peripheral.getName(woodItems)
  23.  
  24. local potions = peripheral.wrap("ironchest:iron_chest_0")
  25. local potionsName = peripheral.getName(potions)
  26.  
  27. local forbiddenArtifacts = peripheral.wrap("ironchest:obsidian_chest_4")
  28. local forbiddenArtifactsName = peripheral.getName(forbiddenArtifacts)
  29.  
  30. local woodItemNames = {
  31.     "scaffold", "minecraft:chest", "sign", "fence_gate", "crafting_table",
  32.     "storagedrawers", "bowl"
  33. }
  34.  
  35. local itemStored = false
  36.  
  37. function moveItems()
  38.     for i = 1, ender.size() do
  39.         item = ender.getItemDetail(i)
  40.         itemStored = false
  41.         if (item) then
  42.             for key, drawer in pairs(controllers[1]) do
  43.                 if not itemStored
  44.                         and ender.pushItems(peripheral.getName(drawer), i) == item.count then
  45.                     itemStored = true
  46.                 end
  47.             end
  48.  
  49.             if not itemStored then
  50.                 if item.name:find("mekanism") then
  51.                     if ender.pushItems(mekName, i) == item.count
  52.                     then itemStored = true end
  53.                 elseif item.name:find("immersive") then
  54.                     if ender.pushItems(immName, i) == item.count
  55.                     then itemStored = true end
  56.                 elseif item.name:find("foregoing")
  57.                         or item.name:find("computercraft")
  58.                         or item.name:find("enderstorage")
  59.                         or item.name:find("fluxnetworks")
  60.                     then
  61.                         if ender.pushItems(foregoingName, i) == item.count
  62.                         then itemStored = true end
  63.                 elseif item.name:find("potion") then
  64.                         if ender.pushItems(potionsName, i) == item.count
  65.                         then itemStored = true end
  66.                 elseif item.name:find("forbidden")
  67.                         or item.name:find("artifacts")
  68.                 then
  69.                     if ender.pushItems(forbiddenArtifactsName, i) == item.count
  70.                     then itemStored = true end
  71.                 else
  72.                     for j = 1, #woodItemNames do
  73.                         if item.name:find(woodItemNames[j]) then
  74.                             if ender.pushItems(woodItemsName, i) == item.count
  75.                             then
  76.                                 j = #woodItemNames
  77.                                 itemStored = true
  78.                             end
  79.                         end
  80.                     end
  81.  
  82.                     if not itemStored  then
  83.                         for j = 1, #organicNames do
  84.                             if item.name:find(organicNames[j]) then
  85.                                 if ender.pushItems(organicsName, i) == item.count
  86.                                 then
  87.                                     j = #organicNames
  88.                                     itemStored = true
  89.                                 end
  90.                             end
  91.                         end
  92.                     end
  93.                 end
  94.  
  95.                 if not itemStored then
  96.                     ender.pushItems("ironchest:diamond_chest_1", i)
  97.                 end
  98.             end
  99.         end
  100.     end
  101. end
  102.  
  103. while true do
  104.     moveItems()
  105.     sleep(1)
  106. end
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement