Advertisement
hornedcommando

Minecraft ComputerCraft Modem Washer v2.0 Above and Beyond

Nov 22nd, 2024 (edited)
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.36 KB | Gaming | 0 0
  1. ---
  2. ---Program to automate the washing of items using encased fan and depot
  3. ---Exports washable items from Occultism storage to depot
  4. ---Imports washed items from depot to Occultism storage
  5. ---washable and washed lists can be modified to include/exclude items
  6. ---review IMPORTANT comments, these are configurables that will likely change based on your setup
  7. ---
  8.  
  9. --By: hornedcommando
  10.  
  11. -- Define peripherals
  12. local depot = peripheral.wrap("create:depot_4") -- IMPORTANT: Change this to the depot where washed items are stored
  13. local occultism = peripheral.wrap("occultism:storage_controller_3") -- Occultism storage controller
  14.  
  15. -- List of washable items
  16. local washable = {
  17.     ["biomesoplenty:orange_sand"] = true,
  18.     ["biomesoplenty:white_sand"] = true,
  19.     ["minecraft:sand"] = true,
  20.     ["create:wheat_flour"] = true,
  21.     ["minecraft:red_sand"] = true,
  22.     ["minecraft:gravel"] = true,
  23.     ["minecraft:soul_sand"] = true,
  24. }
  25.  
  26. -- List of washed items
  27. local washedItems = {
  28.     ["minecraft:clay_ball"] = true,
  29.     ["minecraft:gold_nugget"] = true,
  30.     ["minecraft:iron_nugget"] = true,
  31.     ["minecraft:quartz"] = true,
  32.     ["minecraft:flint"] = true,
  33. }
  34.  
  35. -- Function to get the contents of the Occultism storage
  36. local function getStorageContents(storage)
  37.     local contents = {}
  38.     for slot, item in pairs(storage.list()) do
  39.         contents[item.name] = (contents[item.name] or 0) + item.count
  40.     end
  41.     return contents
  42. end
  43.  
  44. -- Function to count specific items in the Occultism storage
  45. local function countItems(storage, itemName)
  46.     local count = 0
  47.     for slot, item in pairs(storage.list()) do
  48.         if item.name == itemName then
  49.             count = count + item.count
  50.         end
  51.     end
  52.     return count
  53. end
  54.  
  55. -- Function to push items from Occultism storage to the depot
  56. local function pushItems(storage, itemName)
  57.     for slot, item in pairs(storage.list()) do
  58.         if item.name == itemName then
  59.             local success = storage.pushItems(peripheral.getName(depot), slot, item.count)
  60.             if success == 0 then
  61.                 print("Failed to push item: " .. item.name)
  62.                 return false -- Failed push, continue checking other items
  63.             else
  64.                 print("Pushed " .. item.count .. " of " .. item.name .. " to depot.")
  65.             end
  66.         end
  67.     end
  68.     return true -- Successfully processed all items in the storage
  69. end
  70.  
  71. -- Function to process sand
  72. local function processSand(storage)
  73.     print("Processing sand...")
  74.  
  75.     -- Count the items in the storage
  76.     local clayCount = countItems(storage, "minecraft:clay_ball")
  77.  
  78.     local sandTypes = {
  79.         "minecraft:sand",
  80.         "biomesoplenty:white_sand",
  81.         "biomesoplenty:orange_sand"
  82.     }
  83.  
  84.     local highestSandCount = 0
  85.     local suitableSandType = nil
  86.  
  87.     for _, sandType in ipairs(sandTypes) do
  88.         local sandCount = countItems(storage, sandType)
  89.         print("Clay count: " .. clayCount .. ", " .. sandType .. " count: " .. sandCount)
  90.         if sandCount > highestSandCount then
  91.             highestSandCount = sandCount
  92.             suitableSandType = sandType
  93.         end
  94.     end
  95.  
  96.     if highestSandCount > clayCount then
  97.         return pushItems(storage, suitableSandType)
  98.     else
  99.         print("Skipping sand processing as no suitable sand type is available.")
  100.         return true
  101.     end
  102. end
  103.  
  104. -- Function to process red sand
  105. local function processRedSand(storage)
  106.     print("Processing red sand...")
  107.     local goldNuggetCount = countItems(storage, "minecraft:gold_nugget")
  108.     local redSandCount = countItems(storage, "minecraft:red_sand")
  109.     print("Gold nugget count: " .. goldNuggetCount .. ", Red sand count: " .. redSandCount)
  110.     if goldNuggetCount > redSandCount then
  111.         print("Skipping red sand processing as gold nugget count is greater than red sand count.")
  112.         return true
  113.     end
  114.     return pushItems(storage, "minecraft:red_sand")
  115. end
  116.  
  117. -- Function to process gravel
  118. local function processGravel(storage)
  119.     print("Processing gravel...")
  120.     local ironNuggetCount = countItems(storage, "minecraft:iron_nugget")
  121.     local gravelCount = countItems(storage, "minecraft:gravel")
  122.     print("Iron nugget count: " .. ironNuggetCount .. ", Gravel count: " .. gravelCount)
  123.     if ironNuggetCount > gravelCount then
  124.         print("Skipping gravel processing as iron nugget count is greater than gravel count.")
  125.         return true
  126.     end
  127.     return pushItems(storage, "minecraft:gravel")
  128. end
  129.  
  130. -- Function to process soul sand
  131. local function processSoulSand(storage)
  132.     print("Processing soul sand...")
  133.     local quartzCount = countItems(storage, "minecraft:quartz")
  134.     local soulSandCount = countItems(storage, "minecraft:soul_sand")
  135.     print("Quartz count: " .. quartzCount .. ", Soul sand count: " .. soulSandCount)
  136.     if quartzCount > soulSandCount then
  137.         print("Skipping soul sand processing as quartz count is greater than soul sand count.")
  138.         return true
  139.     end
  140.     return pushItems(storage, "minecraft:soul_sand")
  141. end
  142.  
  143. -- Function to move washed items from the depot to the Occultism storage
  144. local function moveWashedItemsToStorage(storage)
  145.     local depotItems = depot.list()
  146.     for slot, item in pairs(depotItems) do
  147.         if washedItems[item.name] then
  148.             local success = depot.pushItems(peripheral.getName(storage), slot, item.count)
  149.             if success == 0 then
  150.                 print("Cannot push washed item to storage! Check storage capacity.")
  151.                 return false -- Failed push, continue checking other items
  152.             else
  153.                 print("Moved " .. item.count .. " of " .. item.name .. " to storage.")
  154.             end
  155.         else
  156.             print("Item " .. item.name .. " is not a washed item.")
  157.         end
  158.     end
  159.     return true -- Successfully processed all washed items
  160. end
  161.  
  162. -- Main loop function
  163. local function main()
  164.     while true do
  165.         -- Process each type of item separately
  166.         local sandSuccess = processSand(occultism)
  167.         local redSandSuccess = processRedSand(occultism)
  168.         local gravelSuccess = processGravel(occultism)
  169.         local soulSandSuccess = processSoulSand(occultism)
  170.  
  171.         os.sleep(3) -- Wait 3 seconds to allow washing to finish
  172.         print("Moving washed items to storage...")
  173.         moveWashedItemsToStorage(occultism)
  174.     end
  175. end
  176.  
  177. -- Start the main function
  178. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement