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

Place to get help with not working mods / modding interface.
Post Reply
User avatar
yaim904
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

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

Post 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
Last edited by yaim904 on Fri Nov 19, 2021 9:18 am, edited 3 times in total.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by google.
:D

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

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

Post by DaveMcW »

You need to set allow_decomposition on the ingredients.

Code: Select all

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

User avatar
yaim904
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

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

Post 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
Last edited by yaim904 on Thu Nov 18, 2021 2:37 am, edited 1 time in total.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by google.
:D

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

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

Post 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

User avatar
yaim904
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

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

Post by yaim904 »

I tried your solution, but it didn't work.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by google.
:D

Pi-C
Smart Inserter
Smart Inserter
Posts: 1651
Joined: Sun Oct 14, 2018 8:13 am
Contact:

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

Post 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.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
yaim904
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

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

Post 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.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by google.
:D

Pi-C
Smart Inserter
Smart Inserter
Posts: 1651
Joined: Sun Oct 14, 2018 8:13 am
Contact:

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

Post 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.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Pi-C
Smart Inserter
Smart Inserter
Posts: 1651
Joined: Sun Oct 14, 2018 8:13 am
Contact:

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

Post 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!
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
yaim904
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

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

Post 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)
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by google.
:D

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2534
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

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

Post 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.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
yaim904
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

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

Post 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.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by google.
:D

Post Reply

Return to “Modding help”