djmattyg007

ComputerCraft Fluid Extractor Automation

Mar 23rd, 2024 (edited)
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | Gaming | 0 0
  1. local peripheral_util = require("./lib/peripheral_util")
  2.  
  3. local logId = "minecraft:acacia_log"
  4. local strippedLogId = "minecraft:stripped_acacia_log"
  5.  
  6. local fluidExtractors = peripheral_util.find("industrialforegoing:fluid_extractor")
  7. print(string.format("Found %d fluid extractors", #fluidExtractors))
  8.  
  9. local routers = peripheral_util.find("modularrouters:modular_router")
  10. print(string.format("Found %d routers", #routers))
  11.  
  12. local storage = peripheral.find("rsBridge")
  13. local trash = peripheral.find("trashcans:item_trash_can_tile")
  14. local trashName = peripheral.getName(trash)
  15.  
  16. os.sleep(0.1)
  17.  
  18. while true do
  19.     local importedLatexAmountTotal = 0
  20.     for _, fluidExtractor in pairs(fluidExtractors) do
  21.         local importedLatexAmount = storage.importFluidFromPeripheral({name="industrialforegoing:latex"}, peripheral.getName(fluidExtractor))
  22.         importedLatexAmountTotal = importedLatexAmountTotal + importedLatexAmount
  23.     end
  24.     if importedLatexAmountTotal > 0 then
  25.         print(string.format("Stored %dmB of latex", importedLatexAmountTotal))
  26.     end
  27.     os.sleep(1)
  28.  
  29.     for _, router in pairs(routers) do
  30.         local routerItem = router.getItemDetail(1)
  31.         if routerItem ~= nil then
  32.             if routerItem["name"] == strippedLogId then
  33.                 print("Acacia log stripped, replacing it")
  34.                 router.pushItems(trashName, 1)
  35.                 os.sleep(0.05)
  36.                 storage.exportItemToPeripheral({name=logId, count=1}, peripheral.getName(router))
  37.                 print("Acacia log replaced")
  38.             end
  39.         end
  40.     end
  41.     os.sleep(5)
  42. end
Advertisement
Add Comment
Please, Sign In to add comment