Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- ---Desc: A program which keeps the fuel on stirling dynamos topped up
- ---this configuration uses sticks because if your treefarm is setup you should have more than enough
- ---but other fuels can easily be added if needed
- ---Looks through all storage drawers and all stirling generator so no configuration needed there
- ---
- --By: hornedcommando
- -- IMPORTANT: change this if you want to cook more than just sticks
- local fuelItem = "minecraft:stick"
- -- Function to dynamically find all connected storage drawers
- local function getConnectedDrawers()
- local drawers = {}
- for _, name in ipairs(peripheral.getNames()) do
- if peripheral.getType(name):find("storagedrawers:standard_drawers_1") then
- local drawer = peripheral.wrap(name)
- table.insert(drawers, {name = name, drawer = drawer}) -- Store both name and wrapped drawer
- end
- end
- return drawers
- end
- -- Function to dynamically find all connected Stirling Dynamos
- local function getConnectedDynamos()
- local dynamos = {}
- for _, name in ipairs(peripheral.getNames()) do
- if peripheral.getType(name):find("thermal:dynamo_stirling") then
- local dynamo = peripheral.wrap(name)
- table.insert(dynamos, {name = name, dynamo = dynamo}) -- Store both name and wrapped dynamo
- end
- end
- return dynamos
- end
- -- Function to count items in drawers
- local function countItems(drawers, itemName)
- local count = 0
- for _, drawerInfo in ipairs(drawers) do
- local drawerContents = drawerInfo.drawer.list()
- for _, item in pairs(drawerContents) do
- if item.name == itemName then
- count = count + item.count
- end
- end
- end
- return count
- end
- -- Function to push items from drawers to a specific peripheral
- local function pushItems(drawers, itemName, targetPeripheral, amount)
- for _, drawerInfo in ipairs(drawers) do
- local drawerContents = drawerInfo.drawer.list()
- for slot, item in pairs(drawerContents) do
- if item.name == itemName then
- local success = drawerInfo.drawer.pushItems(peripheral.getName(targetPeripheral), slot, amount)
- if success > 0 then
- amount = amount - success
- if amount <= 0 then
- return true -- Successfully pushed the required amount
- end
- else
- print("Failed to push item: " .. item.name)
- end
- end
- end
- end
- return false -- Failed to push the required amount
- end
- -- Main function
- local function main()
- while true do
- local drawers = getConnectedDrawers()
- local dynamos = getConnectedDynamos()
- local stickCount = countItems(drawers, fuelItem)
- if stickCount >= #dynamos * 64 then
- for _, dynamoInfo in ipairs(dynamos) do
- print("Topping up dynamo: " .. dynamoInfo.name)
- local success = pushItems(drawers, fuelItem, dynamoInfo.dynamo, 64)
- if not success then
- print("Failed to top up dynamo: " .. dynamoInfo.name)
- end
- end
- else
- print("Not enough sticks available to top up all dynamos.")
- end
- os.sleep(60) -- This is about how fast 1 dynamo can burn through 64 sticks at max output
- end
- end
- -- Start the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement