Page 1 of 1

How to do item with more the one fuel category?

Posted: Sat May 03, 2025 5:48 pm
by Hideki2D
I wanna create new furnace, it must use only coal and wood as fuel.
I created new fuel type - "light-fuel", and tried to add it for coal and wood...
But I ran into a problem fuel_category property of item it's a string, and it can't have more than one type of fuel
Do you have some solutions?

Re: How to do item with more the one fuel category?

Posted: Sat May 03, 2025 6:38 pm
by Silari
Generally you'll want to make those two items in your new category, then add your new category to the buildings that should be able to also burn those things.

Re: How to do item with more the one fuel category?

Posted: Mon May 05, 2025 8:21 am
by Hideki2D
If I understand you correctly, I should assign a new group to the items I need, and then go through all the existing entities, find those that use the group that these items were previously in and add a new group to them.
This suits me, then I have a custom furnace that only uses coal and wood, but at the same time other mechanisms that should use it do not break
Code in my data-updates.lua

Code: Select all

local function add_fuel_category_to_entity(entity, new_category)
    local energy = entity.burner or entity.energy_source
    if not energy then return end

    if energy.fuel_category == "chemical" then
        energy.fuel_categories = { "chemical", new_category }
        energy.fuel_category = nil
    elseif energy.fuel_categories then
        local found = false
        for _, cat in pairs(energy.fuel_categories) do
            if cat == new_category then
                found = true
                break
            end
        end
        if not found then
            for _, cat in pairs(energy.fuel_categories) do
                if cat == "chemical" then
                    table.insert(energy.fuel_categories, new_category)
                    break
                end
            end
        end
    end
end

for _, prototypes in pairs(data.raw) do
    for _, entity in pairs(prototypes) do
        add_fuel_category_to_entity(entity, "light-fuel")
    end
end