Page 1 of 1

[1.1][Solved] Why doesn't the allow_decomposition property work for me?

Posted: Thu Nov 18, 2021 12:17 am
by yaim904
Hi, I'm new to programming mods at Factorio.
I have learned a couple of things with the codes of others, but there is something that I still cannot understand and I need help.

I am creating a new solar panel, and in the recipes I see that:
1. The ingredients do not decomposes completely.
2. The recipe is not blocked by research, as the original does.

Original
Image

New
Image

Code: Select all

-- solar-panel.lua

local lib = require("lib")
if not lib.mods.solar_panel.Multiplier == 1 then return nil end

for _, Base in pairs( lib.mods.solar_panel.base ) do
    local Name       = lib.prefix .. Base
    local Multiplier = lib.mods.solar_panel.Multiplier
    
    local Entity                 = table.deepcopy( data.raw[ "solar-panel" ][ Base ] ) -- Copia la entidad
    Entity.localised_description = { "zzYaim-descriptions", { "entity-description." .. Base } }
    Entity.localised_name        = { "zzYaim-names", { "entity-name." .. Base }, Multiplier }
    Entity.minable.resul         = Name
    Entity.name                  = Name
    
    local Production  = { }
    Production.string = Entity.production
    Production.value  = lib.getNumber( Production.string )
    Production.unit   = lib.getUnit( Production.string )
    Production.value  = Production.value * Multiplier
    Production.string = lib.toString( Production.value )
    Production.string = Production.string .. Production.unit
    Entity.production = Production.string
    
    local Item        = table.deepcopy( data.raw[ "item" ][ Base ] ) -- Copia el objeto
    Item.place_result = Name
    Item.name         = Name
    
    local Recipe               = table.deepcopy( data.raw[ "recipe" ][ Base ] ) -- Copia la receta
    Recipe.energy_required     = Recipe.energy_required * Multiplier
    Recipe.allow_decomposition = true
    Recipe.ingredients         = { }
    Recipe.enabled             = true
    Recipe.result              = Name
    Recipe.name                = Name
    
    local Ingredients = { { item = Base }, { item = "processing-unit" }, { item = "raw-fish" } }
    for _, ingredient in pairs( Ingredients ) do
        for type, name in pairs( ingredient ) do
            local Ingredient  = { }
            Ingredient.name   = name
            Ingredient.type   = type
            Ingredient.amount = Multiplier

            table.insert( Recipe.ingredients, Ingredient )
        end
    end
    
    -- Ubico la tecnologĂ­a
    local t = data.raw[ "technology" ][ "solar-energy" ]
    table.insert( t.effects, { type = "unlock-recipe", recipe = Name } )

    data:extend( { Entity, Item, Recipe } )
end

Re: [1.1] Why doesn't the allow_decomposition property work for me?

Posted: Thu Nov 18, 2021 1:08 am
by DaveMcW
You need to set allow_decomposition on the ingredients.

Code: Select all

data.raw["solar-panel"][Base].allow_decomposition = true

Re: [1.1] Why doesn't the allow_decomposition property work for me?

Posted: Thu Nov 18, 2021 1:20 am
by yaim904
In your message it says in the ingredients, but your code says in the entity, you confuse me.
In the final part of the code, you can see what is added to the recipe.

Code: Select all

    local Recipe               = table.deepcopy( data.raw[ "recipe" ][ Base ] ) -- Copia la receta
    Recipe.energy_required     = Recipe.energy_required * Multiplier
    Recipe.allow_decomposition = true
    Recipe.ingredients         = { }
    Recipe.enabled             = true
    Recipe.result              = Name
    Recipe.name                = Name

Re: [1.1] Why doesn't the allow_decomposition property work for me?

Posted: Thu Nov 18, 2021 1:34 am
by DaveMcW
These must have allow_decompostion.

Code: Select all

local Ingredients = { { item = Base }, { item = "processing-unit" }, { item = "raw-fish" } }

This is how you do it.

Code: Select all

data.raw["solar-panel"][Base].allow_decomposition = true

Re: [1.1] Why doesn't the allow_decomposition property work for me?

Posted: Thu Nov 18, 2021 2:34 am
by yaim904
I tried your solution, but it didn't work.

Re: [1.1] Why doesn't the allow_decomposition property work for me?

Posted: Thu Nov 18, 2021 8:07 am
by Pi-C
yaim904 wrote: Thu Nov 18, 2021 12:17 am 2. The recipe is not blocked by research, as the original does.

Code: Select all

    local Recipe               = table.deepcopy( data.raw[ "recipe" ][ Base ] ) -- Copia la receta
    Recipe.energy_required     = Recipe.energy_required * Multiplier
    Recipe.allow_decomposition = true
    Recipe.ingredients         = { }
    Recipe.enabled             = true
    Recipe.result              = Name
    Recipe.name                = Name
If Recipe.enabled is set to true, the recipe will be available right from the start, without any research.

Re: [1.1] Why doesn't the allow_decomposition property work for me?

Posted: Thu Nov 18, 2021 9:58 am
by yaim904
Pi-C wrote: Thu Nov 18, 2021 8:07 am If Recipe.enabled is set to true, the recipe will be available right from the start, without any research.

I deleted the property you indicated, but it didn't work.

Regarding problem 1.

And if the problem is Factorio and not the properties of the new object?

I see that other mods have that problem.

Regarding problem 2.

I noticed that a mod was block your recipe with a research. I will study your code to see if I understand what I am doing wrong.

Re: [1.1] Why doesn't the allow_decomposition property work for me?

Posted: Thu Nov 18, 2021 11:19 am
by Pi-C
yaim904 wrote: Thu Nov 18, 2021 9:58 am
Pi-C wrote: Thu Nov 18, 2021 8:07 am If Recipe.enabled is set to true, the recipe will be available right from the start, without any research.
I deleted the property you indicated, but it didn't work.
That's as expected. Recipe.enabled is an optional property. If you don't set an optional property, the game will set it to the default value when all mods are finished with data-final-fixes. The default value for Recipe.enabled is true, so deleting the property doesn't unset it. You must explicitely use

Code: Select all

Recipe.enabled = false
if you want to disable it.

Re: [1.1] Why doesn't the allow_decomposition property work for me?

Posted: Thu Nov 18, 2021 11:32 am
by Pi-C
Just in case you don't know this yet: Factorio has an in-game prototype browser where you can check the final properties of a prototype. Open the crafting menu, hover the cursor over your recipe, and use CTRL+SHIFT+F (default) to open the browser. This will also work for entities on the ground etc. If the shortcut doesn't work, check Main menu --> Settings --> Controls --> Debug --> Open prototype explorer GUI. CTRL+SHIFT+E (default) will open the prototypes GUI which will give you a list of all prototypes known in the current game. You definitely should use these tools if your mod creates or changes prototypes!

Re: [1.1] Why doesn't the allow_decomposition property work for me?

Posted: Thu Nov 18, 2021 3:57 pm
by yaim904
Pi-C wrote: Thu Nov 18, 2021 11:19 am
You're right, the default is true, deleting it won't fix it.
I already tried changing the value to false and it didn't fix it either.

Pi-C wrote: Thu Nov 18, 2021 11:32 am
Thanks for the key combination. But I don't see anything different in the prototypes.

Recipe Solar panel
Image

Item Solar panel
Image


I am sure that the solution is a function or process and not a property.

Random comment: They knew that the generation of energy can reach the Yoda (J / W)

Re: [1.1] Why doesn't the allow_decomposition property work for me?

Posted: Thu Nov 18, 2021 4:12 pm
by FuryoftheStars
yaim904 wrote: Thu Nov 18, 2021 3:57 pm
Pi-C wrote: Thu Nov 18, 2021 11:19 am
You're right, the default is true, deleting it won't fix it.
I already tried changing the value to false and it didn't fix it either.
If you're loading this into an existing game, you'd need to include some kind of migration or on_configuration_changed event to relock it. To me, it's best to start a new game each time until you get the expected behavior, then deal with the behavior of bringing it into an existing game later.

Re: [1.1] Why doesn't the allow_decomposition property work for me?

Posted: Fri Nov 19, 2021 1:31 am
by yaim904
FuryoftheStars wrote: Thu Nov 18, 2021 4:12 pm
I have started a new game and everything is fine.

Now I will concentrate on something else.


I found some code that works well in migration. I had a hard time understanding it, but I already did.

Code: Select all

for _, force in pairs( game.forces ) do
    force.reset_technologies( )
    for _, technology in pairs( force.technologies ) do
        if technology.researched then
            for _, effect in pairs( technology.effects ) do
                if effect.type == "unlock-recipe" then
                    force.recipes[ effect.recipe ].enabled = true
                end
            end
        end
    end
end
Thank you.