Changing item textures upon specific tech unlock?

Place to get help with not working mods / modding interface.
Post Reply
donoya
Fast Inserter
Fast Inserter
Posts: 119
Joined: Thu Dec 04, 2014 10:55 pm
Contact:

Changing item textures upon specific tech unlock?

Post by donoya »

Is it possible to do this? Or if not, could I migrate all items to identical ones with different textures upon the tech unlock? I want to be able to have items that look like the items being carried by humans and have them moving around on path 'conveyor belts', but I want the graphic to change to, for example, a truck upon researching a 'truck transports' tech. And to go with this, I'd appreciate knowing how to do something similar for entities like conveyor belts and inserters and assemblers.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Changing item textures upon specific tech unlock?

Post by bobingabout »

From my knowledge, there's no easy way to do this using base game mechanics.

you can however do it via scripts(Find entity, destroy it, create another of the new type), but due to the lack of an "Iterate through all entities" hook, the alternative is very time consuming (as in, when it happens your game will lock up while things process). You basically have to search the entire map tile by tile (There are scripts that do this already) to see if there's an entity you're interested in there.

There might be some entities where you can change it's state (I think people use a car, and change it's direction to point at a slightly different angle) to display different graphics, but if you're looking for something specific like a conveyer belt, it's not so easy.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

donoya
Fast Inserter
Fast Inserter
Posts: 119
Joined: Thu Dec 04, 2014 10:55 pm
Contact:

Re: Changing item textures upon specific tech unlock?

Post by donoya »

bobingabout wrote:From my knowledge, there's no easy way to do this using base game mechanics.

you can however do it via scripts(Find entity, destroy it, create another of the new type), but due to the lack of an "Iterate through all entities" hook, the alternative is very time consuming (as in, when it happens your game will lock up while things process). You basically have to search the entire map tile by tile (There are scripts that do this already) to see if there's an entity you're interested in there.

There might be some entities where you can change it's state (I think people use a car, and change it's direction to point at a slightly different angle) to display different graphics, but if you're looking for something specific like a conveyer belt, it's not so easy.
Thank you for the help. I'll look to see how difficult scripting is. Can this work on items in inventories, as well (including the player inventory)?

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Changing item textures upon specific tech unlock?

Post by bobingabout »

donoya wrote:Thank you for the help. I'll look to see how difficult scripting is. Can this work on items in inventories, as well (including the player inventory)?
Yes, but you'll need to scan all inventories. I'm not sure if the game will let you play with the inventory of a player who is offline though. As for chests (and cars and trains) you'll need to do the same scan as mentioned before.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Changing item textures upon specific tech unlock?

Post by eradicator »

bobingabout wrote:
donoya wrote:Thank you for the help. I'll look to see how difficult scripting is. Can this work on items in inventories, as well (including the player inventory)?
Yes, but you'll need to scan all inventories. I'm not sure if the game will let you play with the inventory of a player who is offline though. As for chests (and cars and trains) you'll need to do the same scan as mentioned before.
Hate to be the messenger with the bad news. You're forgetting that for items you can not distribute this replacement operation over several ticks because items are in constant movement (belts, inserters) and you would most certainly miss a few somewhere if you tried to distribute it. And in an undistributed form scanning through all possible inventories in a single tick would in any medium+ sized factory mean that the game freezes completely for realisticallly at least 20+ seconds. The only way to make this bearable for the player would be to present a "loading" bar on every such replacement similar to the "saving" bar the game presents when freezing the game for saving. One of the built-in scenarios has such a bar but i'd say to implement that in a custom mod requires at least extensive knowledge of the factorio scripting system and API. Replacing offline players inventory on the other hand isn't really that difficult. You just have to hook on_player_joined.

TL;DR:
No. It is impossible to change an items texture on runtime. Your only option is a very expensive replacement operation to fake the effect.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

donoya
Fast Inserter
Fast Inserter
Posts: 119
Joined: Thu Dec 04, 2014 10:55 pm
Contact:

Re: Changing item textures upon specific tech unlock?

Post by donoya »

I suppose I could make it a config option. At least until factorio has a better optimization for this. Thanks again for the help.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Changing item textures upon specific tech unlock?

Post by bobingabout »

Although I didn't mention it for items, I'm fairly sure I mentioned that doing it for entities would cause the game to lock up... I simply stated you'll need to do the whole thing again for items. The game locking up as a result would be insinuated.

Long story short, depending on size of the map... you do this, it will appear to the player that the game has crashed for... a whole minute, or longer. That's how much it's going to hurt if you suddenly research something to trigger your graphics change.

This is the reason Bob's mods doesn't add the "New" ores when you load an old game. it created the same effect, and even though it should be bearable when loading a savegame... I found it uncomfortably long.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Changing item textures upon specific tech unlock?

Post by eradicator »

bobingabout wrote:Although I didn't mention it for items, I'm fairly sure I mentioned that doing it for entities would cause the game to lock up... I simply stated you'll need to do the whole thing again for items. The game locking up as a result would be insinuated.

Long story short, depending on size of the map... you do this, it will appear to the player that the game has crashed for... a whole minute, or longer. That's how much it's going to hurt if you suddenly research something to trigger your graphics change.

This is the reason Bob's mods doesn't add the "New" ores when you load an old game. it created the same effect, and even though it should be bearable when loading a savegame... I found it uncomfortably long.
Just saying that replacing entities (or adding ores as per your example) can be distributed over (a large amount of) ticks if done right, thanks to on_built and on_mined type events. Ofc it would look a little weird when some entities have been replaced while others have not yet. Also not saying that writing the code to do that kind of full-scale replacement would be easy or pleasant, just that - contrary to items - it is at least theoretally possible.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”