Is there a way to detect existance of texture files at load time?
- Skamiz Kazzarch
- Member
- Posts: 613
- Joined: Fri Mar 09, 2018 20:34
- GitHub: Skamiz
- In-game: Skamiz
- Location: la lojbaugag.
Is there a way to detect existance of texture files at load time?
What it says on the tin.
I would like to be able to detect if a specific texture exists, regardless if it's from my mod, another mod, or a texture pack.
That way I could use the dedicated texture if it's exists and if not use a fallback.
For example: I have several stone textures and I generate the brick texture by adding a simple overlay. This works decently in some cases and not so well in others.
Ideally I would be able to do something like if "bricktexutre.png" exists then use it else use "stonetexture.png^brickoverlay.png".
I would like to be able to detect if a specific texture exists, regardless if it's from my mod, another mod, or a texture pack.
That way I could use the dedicated texture if it's exists and if not use a fallback.
For example: I have several stone textures and I generate the brick texture by adding a simple overlay. This works decently in some cases and not so well in others.
Ideally I would be able to do something like if "bricktexutre.png" exists then use it else use "stonetexture.png^brickoverlay.png".
Re: Is there a way to detect existance of texture files at load time?
The easy way would be to detect the mod that uses said texture and have it add the nodes accordingly e.g.
if minetest.get_modpath("that_mod") then
-- do something with texture
end
if minetest.get_modpath("that_mod") then
-- do something with texture
end
- LMD
- Member
- Posts: 1386
- Joined: Sat Apr 08, 2017 08:16
- GitHub: appgurueu
- IRC: appguru[eu]
- In-game: LMD
- Location: Germany
- Contact:
Re: Is there a way to detect existance of texture files at load time?
modlib provides this functionality
Unfortunately modlib lacks docs. Usage: if modlib.minetest.media.paths[filename] then ... end. Most recently I used this in Spiraling Down for generating extrusion meshes.
Unfortunately modlib lacks docs. Usage: if modlib.minetest.media.paths[filename] then ... end. Most recently I used this in Spiraling Down for generating extrusion meshes.
- Skamiz Kazzarch
- Member
- Posts: 613
- Joined: Fri Mar 09, 2018 20:34
- GitHub: Skamiz
- In-game: Skamiz
- Location: la lojbaugag.
Re: Is there a way to detect existance of texture files at load time?
TenPlus1
You missed the point. I am not looking for a texture which already exists somewhere.
Rather I want to make my code compatible with a potential texture, which might be created at a future point in time, in such a way that all that is needed to use it is literary have the game load the file, without any need to touch any further code.
Also since the texture doesn't exist yet, I don't know where it will be coming form. And how would I even detect if a specific texture pack is used?
LMD
From a brief glance that seems promising. Thanks.
But I don't think it can handle texture packs? Any ideas about that?
You missed the point. I am not looking for a texture which already exists somewhere.
Rather I want to make my code compatible with a potential texture, which might be created at a future point in time, in such a way that all that is needed to use it is literary have the game load the file, without any need to touch any further code.
Also since the texture doesn't exist yet, I don't know where it will be coming form. And how would I even detect if a specific texture pack is used?
LMD
From a brief glance that seems promising. Thanks.
But I don't think it can handle texture packs? Any ideas about that?
-
- Member
- Posts: 1118
- Joined: Mon Dec 29, 2014 08:07
- Location: USA
Re: Is there a way to detect existance of texture files at load time?
Skamiz Kazzarch,
I think if you know what texture your looking for, then you know which node you are looking for. If the node is registered, then the texture should be available. If the node name includes the word brick or block, you can then search the texture string from registered_nodes for that node, to see if it is named the way you intend or not.
In short, run through minetest.registered_nodes, checking the texure / tile string for each registered node for which you are enabling this "brick" overlay. As far as I know, if the node or entity is registered, the texture is available in the registered tables.
Shad
I think if you know what texture your looking for, then you know which node you are looking for. If the node is registered, then the texture should be available. If the node name includes the word brick or block, you can then search the texture string from registered_nodes for that node, to see if it is named the way you intend or not.
In short, run through minetest.registered_nodes, checking the texure / tile string for each registered node for which you are enabling this "brick" overlay. As far as I know, if the node or entity is registered, the texture is available in the registered tables.
Shad
- Skamiz Kazzarch
- Member
- Posts: 613
- Joined: Fri Mar 09, 2018 20:34
- GitHub: Skamiz
- In-game: Skamiz
- Location: la lojbaugag.
Re: Is there a way to detect existance of texture files at load time?
Also missing the point.
I am not looking to reuse a texture which is already used somewhere else. Rather I want to activate a new texture based solely on the fact that it was made available to the game.
Let's try a different example. I have a formspec button. I want to write code which makes it so if a texture pack provides a 'button.png' it gets applied through the style element. On the other hand I don't want to get any missing texture errors when the texture pack doesn't provide a 'button.png'
I am not looking to reuse a texture which is already used somewhere else. Rather I want to activate a new texture based solely on the fact that it was made available to the game.
Let's try a different example. I have a formspec button. I want to write code which makes it so if a texture pack provides a 'button.png' it gets applied through the style element. On the other hand I don't want to get any missing texture errors when the texture pack doesn't provide a 'button.png'
- rubenwardy
- Moderator
- Posts: 6972
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: Bristol, United Kingdom
- Contact:
Re: Is there a way to detect existance of texture files at load time?
There's no way for the server to know what textures are in a texture pack that's installed on the client, it only exists on the client.
If there was a texture modifier that allowed a fallback then you could use that for the brick case, but I don't know of any due to dummy textures. Perhaps you could include a transparent image and blit that over your fallback. If the transparent image is replaced in the texture pack with an actual image, it'll overwrite the fallback. This won't work with partial transparency though or transparent pixels in different places
Relying on textures like this is a bit of a code smell, maybe better to find alternatives
If there was a texture modifier that allowed a fallback then you could use that for the brick case, but I don't know of any due to dummy textures. Perhaps you could include a transparent image and blit that over your fallback. If the transparent image is replaced in the texture pack with an actual image, it'll overwrite the fallback. This won't work with partial transparency though or transparent pixels in different places
Relying on textures like this is a bit of a code smell, maybe better to find alternatives
- Skamiz Kazzarch
- Member
- Posts: 613
- Joined: Fri Mar 09, 2018 20:34
- GitHub: Skamiz
- In-game: Skamiz
- Location: la lojbaugag.
Re: Is there a way to detect existance of texture files at load time?
But it should be possible, at least in principle, to know what textures are in the servers texture pack, no?rubenwardy wrote: ↑Mon Dec 05, 2022 07:28There's no way for the server to know what textures are in a texture pack that's installed on the client, it only exists on the client.
The alternative is (to the best of my knowledge) that texture packs are accompanied by an associated mod which overrides formspecs to use the packs textures. Which seems worse IMO.rubenwardy wrote: ↑Mon Dec 05, 2022 07:28Relying on textures like this is a bit of a code smell, maybe better to find alternatives
Anyway my hopes weren't high from the beginning. I am familiar with Minetests capabilities and limits. Just thought I would ask anyway, in case I overlooked something.
It seems to me like it shouldn't be very hard to implement "does_texture_exists('whatever.png')?" Or even better: "get_loaded_textures()" But admittedly I know little about the engine side.
For now at least, scanning for the files manually like modlib does will work for some of the use cases I was thinking of.
- LMD
- Member
- Posts: 1386
- Joined: Sat Apr 08, 2017 08:16
- GitHub: appgurueu
- IRC: appguru[eu]
- In-game: LMD
- Location: Germany
- Contact:
Re: Is there a way to detect existance of texture files at load time?
Possible yes, but it can't be implemented reliably: There is no function to give you the path of the server texture pack and mod security will most likely block access (if you determine the path through hacks, such as knowing where it resides relative to world- or modpaths).Skamiz Kazzarch wrote: ↑Mon Dec 05, 2022 09:21But it should be possible, at least in principle, to know what textures are in the servers texture pack, no?rubenwardy wrote: ↑Mon Dec 05, 2022 07:28There's no way for the server to know what textures are in a texture pack that's installed on the client, it only exists on the client.
- rubenwardy
- Moderator
- Posts: 6972
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: Bristol, United Kingdom
- Contact:
Re: Is there a way to detect existance of texture files at load time?
The texture pack would instead need to be a mod - you can distribute a texture pack as a mod perfectly fine, it would just need to be server side and depend on all the mods it customizes. A mod can override the textures of another mod like a texture pack by depending on it.Skamiz Kazzarch wrote: ↑Mon Dec 05, 2022 09:21The alternative is (to the best of my knowledge) that texture packs are accompanied by an associated mod which overrides formspecs to use the packs textures. Which seems worse IMO.
The way to do formspec theming currently is with a mod.
In the future, maybe texture packs could come with client-side Lua to have enhanced customisation. Currently, the best you have are texture overrides, which allow a texture pack to override node tiles, inventory images, and wield images.
The server doesn't know about the textures on the client. Clients don't even exist at load time. It could report the textures on a server, but you can already mostly do this with a mod. Given the dubious use case, it would struggle to be accepted into the engineSkamiz Kazzarch wrote: ↑Mon Dec 05, 2022 09:21It seems to me like it shouldn't be very hard to implement "does_texture_exists('whatever.png')?" Or even better: "get_loaded_textures()" But admittedly I know little about the engine side.
-----
An XY Problem is when someone wants to do X and thinks that Y is the solution, so asks how to do Y. This then results in people helping being confused and giving bad advice. Instead, you should ask how to do X.
In this case, Y is detecting existence of texture files. What do you actually want to do?
- Skamiz Kazzarch
- Member
- Posts: 613
- Joined: Fri Mar 09, 2018 20:34
- GitHub: Skamiz
- In-game: Skamiz
- Location: la lojbaugag.
Re: Is there a way to detect existance of texture files at load time?
I want to find out if Minetest can tell me if it has loaded 'whatever.png'.rubenwardy wrote: ↑Mon Dec 05, 2022 09:57An XY Problem is when someone wants to do X and thinks that Y is the solution, so asks how to do Y. This then results in people helping being confused and giving bad advice. Instead, you should ask how to do X.
In this case, Y is detecting existence of texture files. What do you actually want to do?
Yes. I want to know because I think it would be a suitable solution to a few issues I have.
Yes. I am aware that that isn't ideal coding practice and could result in some weird nonsense.
Yes. Some of the issues can be solved by workarounds or altogether different approaches.
But all that is irrelevant.
The purpose of this post was only to find out if Minetest has this one specific capability.
And the answer seems to be: No, but you can search for the files manually.
And that is a perfectly legitimate answer to my question.
All the confusion stems from people making assumptions about an X which doesn't exist. Meanwhile finding out if Y is possible is the entire point.
Some of this is my fault for providing concrete examples, which distracted people from the original question. A lesson for the future.
I do appreciate that you all are trying to help me, but sometimes answering the question as asked is all it takes.
Who is online
Users browsing this forum: No registered users and 5 guests