Advertisement
hornedcommando

Minecraft ComputerCraft Modem Composter v2.0 Above and Beyond

Nov 22nd, 2024
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.99 KB | Gaming | 0 0
  1. ---
  2. ---Desc: A Composter program which automatically searches Occultism storage
  3. ---and moves compostable items to a destination hopper for composting.
  4. ---Extracts bonemeal output back into Occultism storage.
  5. ---Does not run if bonemeal count > fir_sapling (limiter helps balance inventory).
  6. ---This is an upgrade from the first iteration because it interacts with the higher tier Occultism storage
  7. ---Review IMPORTANT comments, these are configurables that will likely change based on your setup.
  8. ---
  9.  
  10. --By: hornedcommando
  11.  
  12. -- Define peripherals
  13. local compostHopper = peripheral.wrap("minecraft:hopper_4") -- IMPORTANT: Change this to the hopper on top of the composter
  14. local outputHopper = peripheral.wrap("minecraft:hopper_5") -- IMPORTANT: Change this to the hopper where bonemeal is output
  15. local occultism = peripheral.wrap("occultism:storage_controller_3") -- Occultism storage controller
  16.  
  17. -- Check if peripherals are wrapped correctly
  18. if not compostHopper then
  19.     error("Compost hopper peripheral not found!")
  20. end
  21.  
  22. if not outputHopper then
  23.     error("Output hopper peripheral not found!")
  24. end
  25.  
  26. if not occultism then
  27.     error("Occultism storage controller peripheral not found!")
  28. end
  29.  
  30. -- List of specific items to find
  31. local specificItems = {
  32.     ["minecraft:wheat_seeds"] = true,
  33.     ["minecraft:beetroot_seeds"] = true,
  34.     ["farmersdelight:cabbage_seeds"] = true,
  35.     ["supplementaries:flax_seed"] = true,
  36.     ["minecraft:tomato_seeds"] = true,
  37.     ["biomesoplenty:fir_sapling"] = true
  38. }
  39.  
  40. -- Function to count specific items in the Occultism storage
  41. local function countItems(storage, itemName)
  42.     local count = 0
  43.     for slot, item in pairs(storage.list()) do
  44.         if item.name == itemName then
  45.             count = count + item.count
  46.         end
  47.     end
  48.     return count
  49. end
  50.  
  51. -- Function to push items from Occultism storage to the composter hopper
  52. local function pushItemsFromStorage(storage)
  53.     local boneMealCount = countItems(storage, "minecraft:bone_meal") -- IMPORTANT: Change this to adjust the limiter for different farms
  54.     local firSaplingCount = countItems(storage, "biomesoplenty:fir_sapling") -- IMPORTANT: Change this to the ingredient you get the most of for the specific farm
  55.  
  56.     if boneMealCount > firSaplingCount then
  57.         print("More bone meal than fir saplings. Skipping composting for 10 seconds.")
  58.         return true -- Skip composting
  59.     end
  60.  
  61.     for slot, item in pairs(storage.list()) do
  62.         if specificItems[item.name] then
  63.             local success = storage.pushItems(peripheral.getName(compostHopper), slot, item.count)
  64.             if success == 0 then
  65.                 print("Failed to push item: " .. item.name)
  66.                 return false -- Failed push, continue checking other items
  67.             else
  68.                 print("Pushed " .. item.count .. " of " .. item.name .. " to composter hopper.")
  69.             end
  70.         end
  71.     end
  72.     return true -- Successfully processed all items in the storage
  73. end
  74.  
  75. -- Function to move bonemeal from the output hopper to the Occultism storage
  76. local function moveBoneMealToStorage(storage)
  77.     local outputItems = outputHopper.list()
  78.     for slot, item in pairs(outputItems) do
  79.         if item.name == "minecraft:bone_meal" then
  80.             local success = outputHopper.pushItems(peripheral.getName(storage), slot, item.count)
  81.             if success == 0 then
  82.                 print("Cannot push bonemeal to storage! Check storage capacity.")
  83.                 return false -- Failed push, continue checking other items
  84.             else
  85.                 print("Moved " .. item.count .. " of bonemeal to storage.")
  86.             end
  87.         end
  88.     end
  89.     return true -- Successfully processed all bonemeal items
  90. end
  91.  
  92. -- Main loop function
  93. local function main()
  94.     while true do
  95.         local success = pushItemsFromStorage(occultism)
  96.  
  97.         os.sleep(30) -- Wait 30 seconds to allow composting to finish
  98.         moveBoneMealToStorage(occultism)
  99.     end
  100. end
  101.  
  102. -- Start the main function
  103. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement