Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- inventory-ii.lua
- -- Load the inventory library
- local inventory = require("inventory_lib")
- -- List of chests
- local cobblestone_chests = {"minecraft:chest_11", "minecraft:chest_10", "minecraft:chest_9"}
- local utility_chests = {"minecraft:chest_0"}
- local empty_chests = {"minecraft:chest_5", "minecraft:chest_6", "minecraft:chest_7"}
- local cobblestone_threshold = 64
- -- Function to manage cobblestone in chests
- local function manageCobblestoneInChests()
- -- Move items from empty chests to other chests first
- inventory.emptyChestsToOther()
- -- Now manage cobblestone in other chests
- local peripheralNames = peripheral.getNames()
- for _, name in ipairs(peripheralNames) do
- local peripheralType = peripheral.getType(name)
- if peripheralType == "minecraft:chest" or peripheralType == "expandedstorage:cursed-chest" then
- local chest = peripheral.wrap(name)
- local cobblestoneCount = inventory.checkChestForCobblestone(chest)
- if cobblestoneCount > 0 then
- print("Chest " .. name .. " contains " .. cobblestoneCount .. " cobblestone.")
- else
- print("Chest " .. name .. " contains no cobblestone.")
- end
- -- If it's a cobblestone chest, empty it of non-cobblestone items
- if inventory.table_contains(cobblestone_chests, name) then
- print("Emptying " .. name .. " of non-cobblestone items.")
- inventory.emptyChestOfNonCobblestone(name)
- end
- -- If it's a utility chest, maintain the threshold amount of cobblestone
- if inventory.table_contains(utility_chests, name) then
- if cobblestoneCount > cobblestone_threshold then
- print("Utility chest " .. name .. " has more than " .. cobblestone_threshold .. " cobblestone, transferring excess.")
- inventory.transferCobblestone(name, cobblestone_chests[1]) -- Transfer excess to cobblestone chests
- elseif cobblestoneCount < cobblestone_threshold then
- print("Utility chest " .. name .. " has less than " .. cobblestone_threshold .. " cobblestone, transferring in.")
- inventory.transferCobblestoneToUtilityChest(name) -- Transfer in to reach threshold
- else
- print("Utility chest " .. name .. " has " .. cobblestone_threshold .. " cobblestone, no action needed.")
- end
- -- For non-utility chests, transfer all cobblestone to a cobblestone chest
- else
- if cobblestoneCount > 0 then
- print("Transferring cobblestone from chest " .. name .. " to cobblestone chest.")
- inventory.transferCobblestone(name, cobblestone_chests[1]) -- Transfer to cobblestone chests
- end
- end
- else
- print("Skipping " .. name .. " (not a chest or compatible storage)")
- end
- end
- end
- -- Run the cobblestone management
- manageCobblestoneInChests()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement