Trouble replacing specific uranium icons

Place to get help with not working mods / modding interface.
User avatar
KDhynamo
Manual Inserter
Manual Inserter
Posts: 3
Joined: Tue Jan 21, 2025 1:02 am
Contact:

Trouble replacing specific uranium icons

Post by KDhynamo »

Hello everyone. First post so apologies if anything is off. I could use some help in replacing some graphics and I'm a bit stuck.

I am creating a mod that replaces uranium graphics with blue variants, and so far I have successfully used realistic ores as a template for replacing most of the item icons, but for some reason I cannot seem to change the icons used when items are placed on the ground. You can see in the image below that even though the uranium fuel cell in my cursor is blue, the one on the floor is still green. The same applies for the ammunition, uranium-235, and nuclear fuel. All of these are blue in menus but appear green on the floor.

Image

My thought process was that these items have light masks that I could probably be specifying too, but that goes out the window when you consider uranium-235 doesn't have a light mask (that I have found). As an example , my code for replacing the fuel cell is as follows:

Code: Select all

local uraniumfuelcell = data.raw.item["uranium-fuel-cell"]
if uraniumfuelcell then
    uraniumfuelcell.icon = string.gsub(uraniumfuelcell.icon, "^__base__", modRoot)
    uraniumfuelcell.icon_size = 64
end
Where modRoot is my mod's name in the folder structure. I'm not sure specifying the size is needed here but I read somewhere that size should always be defined, however that might only be for new entities.

I've made sure to disable all other mods to ensure there were no collisions, so I'm wondering what I could be doing wrong. Any help would be appreciated!

I also have plans to change the glow of the centrifuge to blue, and I peeked at the realistic reactor glow mod to see how they handled it. Unfortunately it seems nuclear reactors and centrifuges don't share the same data structure, so if anyone could also point me in the right direction there I'd be most grateful!
User avatar
KDhynamo
Manual Inserter
Manual Inserter
Posts: 3
Joined: Tue Jan 21, 2025 1:02 am
Contact:

Re: Trouble replacing specific uranium icons

Post by KDhynamo »

Well I was able to figure out the centrifuge glow! Here is what I came up with

Code: Select all

local centrifugeEntity = data.raw["assembling-machine"]["centrifuge"]
if centrifugeEntity then
    local lights = centrifugeEntity["graphics_set"]["working_visualisations"][2].animation.layers
    for _, light in ipairs(lights) do
        light.filename = getNewTexturePath(light.filename)
    end
end
getNewTexturePath is shamelessly taken straight from realistic ores:

Code: Select all

local function getNewTexturePath(oldPath)
    local newPath = string.gsub(oldPath, "^__base__", modRoot)
    return newPath
end
Still working on the items on ground issue, but perhaps answering one of my own questions will help someone else!
User avatar
KDhynamo
Manual Inserter
Manual Inserter
Posts: 3
Joined: Tue Jan 21, 2025 1:02 am
Contact:

Re: Trouble replacing specific uranium icons

Post by KDhynamo »

Thanks to the wonderful folks on the Factorio Discord I learned the issue was that I needed to replace the pictures array as well as the icon in order for items with a subtle glow to appear correctly. Here's my final code:

Code: Select all

replacementPairs = {

    { "ammo",               "atomic-bomb" },
    { "ammo",               "explosive-uranium-cannon-shell" },
    { "ammo",               "uranium-cannon-shell" },
    { "ammo",               "uranium-rounds-magazine" },

    { "assembling-machine", "centrifuge" },

    { "item",               "centrifuge" },
    { "item",               "depleted-uranium-fuel-cell" },
    { "item",               "nuclear-fuel" },
    { "item",               "uranium-235" },
    { "item",               "uranium-238" },
    { "item",               "uranium-fuel-cell" },

    { "technology",         "atomic-bomb" },
    { "technology",         "kovarex-enrichment-process" },
    { "technology",         "nuclear-fuel-reprocessing" },
    { "technology",         "uranium-ammo" },
    { "technology",         "uranium-mining" },
    { "technology",         "uranium-processing" },


    { "recipe",             "kovarex-enrichment-process" },
    { "recipe",             "nuclear-fuel-reprocessing" },
    { "recipe",             "uranium-processing" },
}

-- Gets new textures by replacing the base root folder with the mod root folder
local function getNewTexturePath(oldPath)
    local newPath = string.gsub(oldPath, "^__base__", modRoot)
    return newPath
end

-- Takes a 2D array of structure {{typeName, internalName}, ...} and replaces textures and pictures w/ mod files
local function replacePrototypeTexture(prototypeType, internalName)
    local prototype = data.raw[prototypeType][internalName]
    if prototype then
        prototype.icon = getNewTexturePath(prototype.icon)
        if prototype.pictures and prototype.pictures.layers then
            for _, layer in ipairs(prototype.pictures.layers) do
                layer.filename = getNewTexturePath(layer.filename)
            end
        end
    end
end

-- Actually do it
for _, replacementPair in ipairs(replacementPairs) do
    replacePrototypeTexture(replacementPair[1], replacementPair[2])
end
This file was also an invaluable source for figuring out the items' data structures https://github.com/wube/factorio-data/b ... .lua#L2875
Post Reply

Return to “Modding help”