Advertisement
hornedcommando

Minecraft ComputerCraft Modem Trashcan Above and Beyond

Nov 15th, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.10 KB | Gaming | 0 0
  1. ---
  2. ---Program to automate throwing away trash
  3. ---Exports listed items from drawers to chest (which should be over a chute over lava/cactus, etc)
  4. ---Runs with a long sleep at the end because trash isn't a high priority
  5. ---review IMPORTANT comments, if you don't you will trash something you didn't want to
  6. ---
  7.  
  8. --By: hornedcommando
  9.  
  10. -- Define the list of trash items IMPORTANT: Change this or risk having the wrong items thrown away
  11. local trashItems = {
  12.     ["minecraft:poisonous_potato"] = true,
  13.     ["forbidden_arcanus:golden_orchid_seeds"] = true,
  14. }
  15.  
  16. -- Define the peripheral names
  17. local voidChest = peripheral.wrap("minecraft:chest_4") -- IMPORTANT: Change this to the void chest
  18.  
  19. -- Function to dynamically find all connected storage drawers
  20. local function getConnectedDrawers()
  21.     local drawers = {}
  22.     for _, name in ipairs(peripheral.getNames()) do
  23.         if peripheral.getType(name):find("storagedrawers:standard_drawers_1") then
  24.             local drawer = peripheral.wrap(name)
  25.             table.insert(drawers, {name = name, drawer = drawer}) -- Store both name and wrapped drawer
  26.         end
  27.     end
  28.     return drawers
  29. end
  30.  
  31. -- Function to move trash items from drawers to the void chest
  32. local function moveTrashItemsToVoidChest(drawers)
  33.     for _, drawerInfo in ipairs(drawers) do
  34.         local drawerContents = drawerInfo.drawer.list()
  35.         for slot, item in pairs(drawerContents) do
  36.             if trashItems[item.name] then
  37.                 local success = drawerInfo.drawer.pushItems(peripheral.getName(voidChest), slot, item.count)
  38.                 if success == 0 then
  39.                     print("Failed to move trash item: " .. item.name)
  40.                 else
  41.                     print("Moved " .. item.count .. " of " .. item.name .. " to void chest.")
  42.                 end
  43.             end
  44.         end
  45.     end
  46. end
  47.  
  48. -- Main function
  49. local function main()
  50.     while true do
  51.         local drawers = getConnectedDrawers()
  52.         moveTrashItemsToVoidChest(drawers)
  53.         os.sleep(120) -- The Trash man comes every 2 minutes
  54.     end
  55. end
  56.  
  57. -- Start the main function
  58. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement