Item Categories and SubCategories Help

Place to get help with not working mods / modding interface.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 430
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Item Categories and SubCategories Help

Post by BraveCaperCat »

I am making a mod and it adds an Item Category and Item SubCategory and they don't show up ingame, even though the mod adds items/recipes to those SubCategories.

Code (which adds the Categories/SubCategories):

Code: Select all

local RocketItemCategory = table.deepcopy(data.raw['item-group']['production'])
RocketItemCategory.name = 'mrw:rocket-construction'
RocketItemCategory.icon = '__base__/graphics/icons/rocket-part.png'
RocketItemCategory.icon_size = 64
RocketItemCategory.icon_mipmaps = 4
RocketItemCategory.order = 'e'
data:extend({RocketItemCategory})
local RocketPartSubCategory = table.deepcopy(data.raw['item-subgroup']['space-related'])
RocketPartSubCategory.name = 'mrw:rocket-parts'
RocketPartSubCategory.group = 'mrw:rocket-construction'
RocketPartSubCategory.order = 'a'
data:extend({RocketPartSubCategory})
The game loads as normal, with no immediate errors in the script.
This is the code which makes some recipes and then adds it to the above SubCategory (It also makes items):

Code: Select all

function DefineRocketPart(name, ingredients, failure_chance)
    name = 'mrw:' .. name
    if data.raw['technology']['mrw:rocket-part-assembly'] == nil then
        CreateTechnologies('RPA')
    end
    local Item = table.deepcopy(data.raw['item']['rocket-part'])
    Item.name = name
    data:extend({Item})
    local Recipe = table.deepcopy(data.raw['recipe']['rocket-part'])
    Recipe.name = name
    Recipe.ingredients = ingredients
    Recipe.result = nil
    Recipe.result_count = nil
    Recipe.normal = nil
    Recipe.expensive = nil
    Recipe.results = {{type = 'item', name = name, amount = 1, probability = 1 - failure_chance}}
    for i, ingredient in pairs(ingredients) do
        ingredient.probability = failure_chance
        table.insert(Recipe.results, ingredient)
    end
    Recipe.main_product = name
    Recipe.subgroup = 'mrw:rocket-parts'
    data:extend({Recipe})
end
Please help!
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
Bilka
Factorio Staff
Factorio Staff
Posts: 3372
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Item Categories and SubCategories Help

Post by Bilka »

How are you checking that the subgroup exists? When I use your code and search for it in the prototype explorer (opened with CTRL + SHIFT + E by default) it's there as expected.

Are you maybe looking at the subgroup of the item you create? The code you pasted doesn't set it on the item, so it will have the subgroup of the item your copied the prototype of.

Sidenote: You don't need to copy another prototype for something when you're basically overriding everything after the deepcopy. The following code gives the same result as yours for the subgroup:

Code: Select all

data:extend{{
  type = 'item-subgroup',
  name = 'mrw:rocket-parts',
  group = 'mrw:rocket-construction',
  order = 'a'
}}
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 430
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Item Categories and SubCategories Help

Post by BraveCaperCat »

Bilka wrote: Sun Feb 11, 2024 10:54 am How are you checking that the subgroup exists? When I use your code and search for it in the prototype explorer (opened with CTRL + SHIFT + E by default) it's there as expected.

Are you maybe looking at the subgroup of the item you create? The code you pasted doesn't set it on the item, so it will have the subgroup of the item your copied the prototype of.

Sidenote: You don't need to copy another prototype for something when you're basically overriding everything after the deepcopy. The following code gives the same result as yours for the subgroup:

Code: Select all

data:extend{{
  type = 'item-subgroup',
  name = 'mrw:rocket-parts',
  group = 'mrw:rocket-construction',
  order = 'a'
}}
It isn't in the crafting menu (handcrafting or assembler recipe selection)
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
Bilka
Factorio Staff
Factorio Staff
Posts: 3372
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Item Categories and SubCategories Help

Post by Bilka »

BraveCaperCat wrote: Fri Mar 08, 2024 12:56 pm It isn't in the crafting menu (handcrafting or assembler recipe selection)
The rocket-part recipe you're copying is hidden and not handcraftable. If you want to check how it shows up in in-game machine GUIs, you'd have to unhide it and make a machine that can craft the "rocket-building" crafting category and doesn't have a fixed recipe.

Or you could check what values are set in the prototype explorer, or create the recipe from scratch, see my first reply.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 430
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Item Categories and SubCategories Help

Post by BraveCaperCat »

Bilka wrote: Fri Mar 08, 2024 1:56 pm
BraveCaperCat wrote: Fri Mar 08, 2024 12:56 pm It isn't in the crafting menu (handcrafting or assembler recipe selection)
The rocket-part recipe you're copying is hidden and not handcraftable. If you want to check how it shows up in in-game machine GUIs, you'd have to unhide it and make a machine that can craft the "rocket-building" crafting category and doesn't have a fixed recipe.

Or you could check what values are set in the prototype explorer, or create the recipe from scratch, see my first reply.
Ah! That was what i was missing. I forgot to change the rocket part recipes to use the assembler crafting recipe category. Or did I? I think so. It was awhile since that first post.
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
Post Reply

Return to “Modding help”