SHOW:
|
|
- or go back to the newest paste.
1 | - | -- delete inventory-i.lua |
1 | + | -- inventory-ii.lua |
2 | - | -- pastebin get wKqtBNmq inventory-i.lua |
2 | + | |
3 | - | -- Define a function to check a chest's inventory for cobblestone |
3 | + | -- Load the inventory library |
4 | - | local function checkChestForCobblestone(chest) |
4 | + | local inventory = require("inventory_lib") |
5 | - | if not chest then |
5 | + | |
6 | - | print("Error: Invalid chest peripheral!") |
6 | + | -- List of chests |
7 | - | return 0 |
7 | + | local cobblestone_chests = {"minecraft:chest_11", "minecraft:chest_10", "minecraft:chest_9"} |
8 | local utility_chests = {"minecraft:chest_0"} | |
9 | - | |
9 | + | local empty_chests = {"minecraft:chest_5", "minecraft:chest_6", "minecraft:chest_7"} |
10 | - | local cobblestoneCount = 0 |
10 | + | |
11 | - | for slot, item in pairs(chest.list()) do |
11 | + | local cobblestone_threshold = 64 |
12 | - | if item and item.name == "minecraft:cobblestone" then |
12 | + | |
13 | - | cobblestoneCount = cobblestoneCount + item.count |
13 | + | -- Function to manage cobblestone in chests |
14 | local function manageCobblestoneInChests() | |
15 | -- Move items from empty chests to other chests first | |
16 | - | return cobblestoneCount |
16 | + | inventory.emptyChestsToOther() |
17 | ||
18 | -- Now manage cobblestone in other chests | |
19 | - | -- Function to find all chests on the network and check for cobblestone |
19 | + | |
20 | - | local function reportCobblestoneOnNetwork() |
20 | + | |
21 | local peripheralType = peripheral.getType(name) | |
22 | if peripheralType == "minecraft:chest" or peripheralType == "expandedstorage:cursed-chest" then | |
23 | local chest = peripheral.wrap(name) | |
24 | - | if peripheralType == "minecraft:chest" then |
24 | + | local cobblestoneCount = inventory.checkChestForCobblestone(chest) |
25 | - | print("Found chest: " .. name) |
25 | + | |
26 | - | chest = peripheral.wrap(name) |
26 | + | |
27 | - | -- Checking if we successfully wrapped the chest |
27 | + | print("Chest " .. name .. " contains " .. cobblestoneCount .. " cobblestone.") |
28 | - | local cobblestoneCount = checkChestForCobblestone(chest) |
28 | + | else |
29 | print("Chest " .. name .. " contains no cobblestone.") | |
30 | - | print("Cobblestone in chest at " .. name .. ": " .. cobblestoneCount) |
30 | + | |
31 | ||
32 | -- If it's a cobblestone chest, empty it of non-cobblestone items | |
33 | - | print("Skipping " .. name .. " (not a chest)") |
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 | - | -- Run the report |
38 | + | -- If it's a utility chest, maintain the threshold amount of cobblestone |
39 | - | reportCobblestoneOnNetwork() |
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 |