Also, i asked chatgpt to modify a function which fill machines with resources, to not do so, if output inventory of it is not empty, to don't clutter the output of resorces. Prety useful, when you want to debug your production performance.
here is It's answer:
To interrupt the harvest_feed_entity function if the inventory is not empty after processing the recipe.products loop, you can add a condition to check whether the output inventory is empty. If it's not empty, you can exit the function early. Here's the modified code:
lua
Copy code
function harvest_feed_entity(player, e)
local entity = e.entity
--print_inventory(entity)
do_ssp(player, entity)
if do_chest(player, entity) then
return
end
if do_lab(player, entity) then
return
end
if do_furnace(player, e) then
return
end
do_fuel(player, entity)
if false == is_machine(entity) then
return
end
local recipe = entity.get_recipe()
if recipe == nil then
return
end
for k, v in ipairs(recipe.products) do
try_get_from_entity(player, entity, v.name, 9999, entity.get_output_inventory())
end
-- Check if the output inventory is not empty, and if so, exit the function
if not is_inventory_empty(entity.get_output_inventory()) then
return
end
for k, v in ipairs(recipe.ingredients) do
local inv = entity.get_inventory(defines.inventory.furnace_source)
local n = read_entity(entity, v.name)
local m = v.amount / (recipe.energy / entity.crafting_speed) * 2
--game.print(v.name.." "..v.amount.." "..recipe.energy.." "..n.." "..m)
if m < v.amount then
m = v.amount * 2
end
if n < m then
try_put_to_entity(player, entity, v.name, m - n, inv)
end
end
end
-- Helper function to check if an inventory is empty
function is_inventory_empty(inv)
for _, stack in pairs(inv.get_contents()) do
if stack > 0 then
return false
end
end
return true
end
I added a check using the is_inventory_empty helper function after the loop processing recipe.products. If the output inventory is not empty, the function will return early. Adjust the condition inside is_inventory_empty as needed based on your inventory structure.