Advertisement
msmouse

inventory_ii.lua

Dec 1st, 2024 (edited)
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- inventory-ii.lua
  2.  
  3. -- Load the inventory library
  4. local inventory = require("inventory_lib")
  5.  
  6. -- List of chests
  7. local cobblestone_chests = {"minecraft:chest_11", "minecraft:chest_10", "minecraft:chest_9"}
  8. local utility_chests = {"minecraft:chest_0"}
  9. local empty_chests = {"minecraft:chest_5", "minecraft:chest_6", "minecraft:chest_7"}
  10.  
  11. local cobblestone_threshold = 64
  12.  
  13. -- Function to manage cobblestone in chests
  14. local function manageCobblestoneInChests()
  15.     -- Move items from empty chests to other chests first
  16.     inventory.emptyChestsToOther()
  17.  
  18.     -- Now manage cobblestone in other chests
  19.     local peripheralNames = peripheral.getNames()
  20.     for _, name in ipairs(peripheralNames) do
  21.         local peripheralType = peripheral.getType(name)
  22.         if peripheralType == "minecraft:chest" or peripheralType == "expandedstorage:cursed-chest" then
  23.             local chest = peripheral.wrap(name)
  24.             local cobblestoneCount = inventory.checkChestForCobblestone(chest)
  25.  
  26.             if cobblestoneCount > 0 then
  27.                 print("Chest " .. name .. " contains " .. cobblestoneCount .. " cobblestone.")
  28.             else
  29.                 print("Chest " .. name .. " contains no cobblestone.")
  30.             end
  31.  
  32.             -- If it's a cobblestone chest, empty it of non-cobblestone items
  33.             if inventory.table_contains(cobblestone_chests, name) then
  34.                 print("Emptying " .. name .. " of non-cobblestone items.")
  35.                 inventory.emptyChestOfNonCobblestone(name)
  36.             end
  37.  
  38.             -- If it's a utility chest, maintain the threshold amount of cobblestone
  39.             if inventory.table_contains(utility_chests, name) then
  40.                 if cobblestoneCount > cobblestone_threshold then
  41.                     print("Utility chest " .. name .. " has more than " .. cobblestone_threshold .. " cobblestone, transferring excess.")
  42.                     inventory.transferCobblestone(name, cobblestone_chests[1])  -- Transfer excess to cobblestone chests
  43.                 elseif cobblestoneCount < cobblestone_threshold then
  44.                     print("Utility chest " .. name .. " has less than " .. cobblestone_threshold .. " cobblestone, transferring in.")
  45.                     inventory.transferCobblestoneToUtilityChest(name)  -- Transfer in to reach threshold
  46.                 else
  47.                     print("Utility chest " .. name .. " has " .. cobblestone_threshold .. " cobblestone, no action needed.")
  48.                 end
  49.             -- For non-utility chests, transfer all cobblestone to a cobblestone chest
  50.             else
  51.                 if cobblestoneCount > 0 then
  52.                     print("Transferring cobblestone from chest " .. name .. " to cobblestone chest.")
  53.                     inventory.transferCobblestone(name, cobblestone_chests[1])  -- Transfer to cobblestone chests
  54.                 end
  55.             end
  56.         else
  57.             print("Skipping " .. name .. " (not a chest or compatible storage)")
  58.         end
  59.     end
  60. end
  61.  
  62. -- Run the cobblestone management
  63. manageCobblestoneInChests()
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement