How do I apply tint to sprites?

Place to get help with not working mods / modding interface.
Post Reply
Doctor_Willis
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Sep 26, 2023 11:45 am
Contact:

How do I apply tint to sprites?

Post by Doctor_Willis »

Hi everyone,

I'm just dipping my toes into modding for the first time, and I've got stuck on applying tints to sprites.

I'm working on a electric pole with maximum supply distance, and I'd like it to be a different colour.
I've figured out how to tint the icon, but not the sprite.
This is what I've got so far:

Code: Select all

local maxDistanceElectricPole = table.deepcopy(data.raw["electric-pole"]["big-electric-pole"])

maxDistanceElectricPole.name = "max-distance-electric-pole"
maxDistanceElectricPole.localised_description = {"item-description.max-distance-electric-pole"}
maxDistanceElectricPole.supply_area_distance = 64
maxDistanceElectricPole.maximum_wire_distance = 64
maxDistanceElectricPole.subgroup = "energy-pipe-distribution"
maxDistanceElectricPole.icons = {
    {
        icon = maxDistanceElectricPole.icon,
        tint = {r= 1.0, g = 0.5, b = 0.5, a = 1}
    }
}

data:extend{maxDistanceElectricPole}
Side note: I'm not sure if I should start a new topic for this, but I can't figure out subgroup order either. It's currently sitting at the end of the logistics group, but I'm not sure how to get it to sit up with its buds in the electric poles and pipes.

Bilka
Factorio Staff
Factorio Staff
Posts: 3140
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How do I apply tint to sprites?

Post by Bilka »

To tint the sprite of the electric pole, you need to apply the tint into its pictures property. By looking at the prototype of the big-electric-pole in the base game files, you can see that it uses layers so the tint needs to be inside the layers. So this code applies the tint to the first layer, but not the shadow, just add it to the rest of your entity code:

Code: Select all

maxDistanceElectricPole.pictures.layers[1].tint = {r= 1.0, g = 0.5, b = 0.5, a = 1}
maxDistanceElectricPole.pictures.layers[1].hr_version.tint = {r= 1.0, g = 0.5, b = 0.5, a = 1}
The other entities are ordered by the subgroup of the items that place them. I would make an item that places the pole (you might already have this, but it's not in your post) and remove the subgroup from the entity itself.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Doctor_Willis
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Sep 26, 2023 11:45 am
Contact:

Re: How do I apply tint to sprites?

Post by Doctor_Willis »

Thank you for your help: I didn't have an item for it, so I added one and that did the trick.

I've come up on a new problem though: If one the Max Distance Power poles is placed in world and a player tears it down, they get back the Big Power pole, not the max distance one. I had a look through the wiki, but nothing stood out to me.

Code: Select all

local maxDistanceElectricPoleEntity = table.deepcopy(data.raw["electric-pole"]["big-electric-pole"])

maxDistanceElectricPoleEntity.name = "max-distance-electric-pole-entity"
maxDistanceElectricPoleEntity.localised_description = {"item-description.max-distance-electric-pole-description"}
maxDistanceElectricPoleEntity.supply_area_distance = 64
maxDistanceElectricPoleEntity.maximum_wire_distance = 64
maxDistanceElectricPoleEntity.subgroup = "energy-pipe-distribution"
maxDistanceElectricPoleEntity.icons = {
    {
        icon = maxDistanceElectricPoleEntity.icon,
        tint = {r= 1.0, g = 0.5, b = 0.5, a = 1}
    }
}
maxDistanceElectricPoleEntity.pictures.layers[1].tint = {r= 1.0, g = 0.5, b = 0.5, a = 1}
maxDistanceElectricPoleEntity.pictures.layers[1].hr_version.tint = {r= 1.0, g = 0.5, b = 0.5, a = 1}


local maxDistanceElectricPoleItem = table.deepcopy(data.raw["item"]["big-electric-pole"])

maxDistanceElectricPoleItem.name = "max-distance-electric-pole-item"
maxDistanceElectricPoleItem.subgroup = "energy-pipe-distribution"
maxDistanceElectricPoleItem.order = "a[max-distance-electric-pole-entity]"
maxDistanceElectricPoleItem.place_result = "max-distance-electric-pole-entity"
maxDistanceElectricPoleItem.icons = maxDistanceElectricPoleEntity.icons


data:extend{maxDistanceElectricPoleEntity, maxDistanceElectricPoleItem}

Bilka
Factorio Staff
Factorio Staff
Posts: 3140
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How do I apply tint to sprites?

Post by Bilka »

The item that is returned when the pole is mined is specified by EntityPrototype::minable. So that needs to be changed to the new item.

The code for that
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Doctor_Willis
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Sep 26, 2023 11:45 am
Contact:

Re: How do I apply tint to sprites?

Post by Doctor_Willis »

That works. Thanks again!

Post Reply

Return to “Modding help”