Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- ---Desc: A Furnace Manager program which automatically searches Occultism storage
- ---and moves fuel and cookable items to connected furnaces.
- ---Extracts cooked items back into Occultism storage.
- ---Uses inventory balancing to decide which fuel and cookable items to use.
- ---Due to furnaces being slow and holding a lot, everything is pulled back into inventory each loop
- ---to improve balancing accuracy
- ---
- --By: hornedcommando
- -- Define peripherals
- local occultism = peripheral.wrap("occultism:storage_controller_0") -- IMPORTANT: this has to match your id
- -- Check if the Occultism storage controller is wrapped correctly
- if not occultism then
- error("Occultism storage controller peripheral not found!")
- end
- -- List of fuel items in order of preference. IMPORTANT: change this if you have different fuel requirements
- local fuelWhitelist = {
- "minecraft:stick",
- "minecraft:charcoal",
- "thermal:charcoal_block",
- "minecraft:coal",
- "minecraft:coal_block",
- "minecraft:lava_bucket"
- }
- -- List of always cookable items IMPORTANT: these are items that have limited use beyond cooking, change as needed
- local alwaysCookableItems = {
- "farmersdelight:wheat_dough",
- "tconstruct:grout",
- "thermal:rubber",
- "forbidden_arcanus:tentacle",
- "occultism:iesnium_dust",
- "thermal:enderium_dust",
- "buddycards:deep_luminis_crystal",
- "buddycards:luminis_crystal",
- "improvedbackpacks:bound_leather",
- "architects_palatte:algal_blend"
- }
- -- List of inventory balanced items IMPORTANT: these items will not process if Ingredient < Output, change as needed
- local balancedItems = {
- ["aquaculture:fish_fillet_raw"] = "aquaculture:fish_fillet_cooked",
- ["minecraft:rabbit"] = "minecraft:cooked_rabbit",
- ["farmersdelight:minced_beef"] = "farmersdelight:beef_patty",
- ["farmersdelight:salmon_slice"] = "farmersdelight:cooked_salmon_slice",
- ["create:diorite_cobblestone"] = "minecraft:diorite",
- ["create:gabbro_cobblestone"] = "create:gabbro",
- ["minecraft:cod"] = "minecraft:cooked_cod",
- ["minecraft:porkchop"] = "minecraft:cooked_porkchop",
- ["minecraft:cobblestone"] = "minecraft:stone",
- ["minecraft:potato"] = "minecraft:baked_potato",
- ["minecraft:egg"] = "farmersdelight:fried_egg",
- ["minecraft:salmon"] = "minecraft:cooked_salmon",
- ["minecraft:mutton"] = "minecraft:cooked_mutton",
- ["tconstruct:nether_grout"] = "tconstruct:scorched_brick",
- ["create:andesite_cobblestone"] = "minecraft:andesite",
- ["minecraft:kelp"] = "minecraft:dried_kelp",
- ["occultism:otherstone"] = "occultism:burnt_otherstone",
- ["minecraft:beef"] = "minecraft:cooked_beef",
- ["minecraft:chicken"] = "minecraft:cooked_chicken",
- ["minecraft:sand"] = "minecraft:glass",
- ["biomesoplenty:white_sand"] = "minecraft:glass",
- ["biomesoplenty:orange_sand"] = "minecraft:glass",
- ["biomesoplenty:fir_log"] = "minecraft:charcoal"
- }
- -- Function to count specific items in the Occultism storage
- local function countItems(storage, itemName)
- local count = 0
- for slot, item in pairs(storage.list()) do
- if item.name == itemName then
- count = count + item.count
- end
- end
- return count
- end
- -- Function to find the best fuel item based on inventory balancing
- local function findBestFuel(storage)
- for i = 1, #fuelWhitelist - 1 do
- local currentFuel = fuelWhitelist[i]
- local nextFuel = fuelWhitelist[i + 1]
- if countItems(storage, currentFuel) < countItems(storage, nextFuel) then
- return nextFuel
- end
- end
- return fuelWhitelist[1] -- Default to the first fuel item if no better option is found
- end
- -- Function to find the best cookable item based on inventory balancing
- local function findBestCookable(storage)
- -- Check always cookable items first
- for _, cookable in ipairs(alwaysCookableItems) do
- if countItems(storage, cookable) > 0 then
- return cookable
- end
- end
- -- Check inventory balanced items
- for rawItem, cookedItem in pairs(balancedItems) do
- if countItems(storage, rawItem) > countItems(storage, cookedItem) then
- return rawItem
- end
- end
- return nil -- No cookable item found
- end
- -- Function to push items from Occultism storage to the furnace
- local function pushItemsToFurnace(storage, furnace, itemName, slot)
- for storageSlot, item in pairs(storage.list()) do
- if item.name == itemName then
- local success = storage.pushItems(peripheral.getName(furnace), storageSlot, item.count, slot)
- if success == 0 then
- print("Failed to push item: " .. item.name)
- return false -- Failed push, continue checking other items
- else
- print("Pushed " .. item.count .. " of " .. item.name .. " to furnace slot " .. slot)
- return true -- Successfully pushed the item
- end
- end
- end
- return false -- No item found to push
- end
- -- Function to move all items from the furnace to the Occultism storage
- local function moveAllItemsToStorage(storage, furnace)
- local furnaceItems = furnace.list()
- for slot, item in pairs(furnaceItems) do
- local success = furnace.pushItems(peripheral.getName(storage), slot, item.count)
- if success == 0 then
- print("Cannot push item from slot " .. slot .. " to storage! Check storage capacity.")
- return false -- Failed push, continue checking other items
- else
- print("Moved " .. item.count .. " of " .. item.name .. " from slot " .. slot .. " to storage.")
- end
- end
- return true -- Successfully processed all items
- end
- -- Function to clear all items from furnaces
- local function clearFurnaces(storage, furnaces)
- for _, furnace in ipairs(furnaces) do
- moveAllItemsToStorage(storage, furnace)
- end
- end
- -- Main loop function
- local function main()
- while true do
- -- Detect all connected furnaces
- local furnaces = {}
- for _, name in ipairs(peripheral.getNames()) do
- if peripheral.getType(name) == "minecraft:furnace" then
- table.insert(furnaces, peripheral.wrap(name))
- end
- end
- -- Clear all items from furnaces to get accurate counts
- clearFurnaces(occultism, furnaces)
- -- Process each furnace
- for _, furnace in ipairs(furnaces) do
- -- Find the best fuel and cookable item
- local bestFuel = findBestFuel(occultism)
- local bestCookable = findBestCookable(occultism)
- -- Push fuel to slot 2
- if bestFuel then
- pushItemsToFurnace(occultism, furnace, bestFuel, 2)
- end
- -- Push cookable item to slot 1
- if bestCookable then
- pushItemsToFurnace(occultism, furnace, bestCookable, 1)
- end
- end
- os.sleep(200) -- Wait 200 seconds before the next iteration
- end
- end
- -- Start the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement