Advertisement
ccraftersanonmoose

Auto-sorter

Feb 17th, 2025 (edited)
133
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1. -- Peripheral names
  2. local inputChest = "quark:variant_chest_4"  -- Main input chest
  3. local storageController = "storagedrawers:controller_0"  -- Storage controller for drawers
  4. local fallbackChest = "minecraft:chest_1"  -- Fallback chest for unrecognized items
  5.  
  6. -- Validate peripherals
  7. if not peripheral.isPresent(inputChest) then
  8.     error("Input chest not found! Check connections and name.")
  9. end
  10. if not peripheral.isPresent(storageController) then
  11.     error("Storage controller not found! Check connections and name.")
  12. end
  13. if not peripheral.isPresent(fallbackChest) then
  14.     error("Fallback chest not found! Check connections and name.")
  15. end
  16.  
  17. -- Main sorting loop
  18. while true do
  19.     local chest = peripheral.wrap(inputChest)
  20.     local controller = peripheral.wrap(storageController)
  21.     local items = chest.list()
  22.  
  23.     for slot, item in pairs(items) do
  24.         local itemName = item.name
  25.  
  26.         -- Attempt to insert into the storage controller
  27.         local moved = chest.pushItems(storageController, slot)
  28.         if moved > 0 then
  29.             print("Moved " .. moved .. "x " .. itemName .. " to storage drawers")
  30.         else
  31.             -- If failed, move to fallback chest
  32.             moved = chest.pushItems(fallbackChest, slot)
  33.             if moved > 0 then
  34.                 print("Moved " .. moved .. "x " .. itemName .. " to fallback chest")
  35.             else
  36.                 print("Failed to move " .. itemName .. " anywhere")
  37.             end
  38.         end
  39.     end
  40.  
  41.     sleep(5)  -- Wait before checking again
  42. end
Advertisement
Comments
  • ccraftersanonmoose
    41 days (edited)
    # text 0.17 KB | 0 0
    1. Auto sorting script to sort any item placed into a chest into its respective storage bin. Works with cc tweaked and storagebins. Originally developed for plexiglass mountain.
Add Comment
Please, Sign In to add comment
Advertisement