Jump to content

Reloading a single texture/resource (forge 1.20.1)


brickyboy

Recommended Posts

For my mod I want to reload a single texture from the assets. (So all resource packs and such). I've succeeded in forcing a client to reload all assets, basically forcing an F3+T, but now I want to know if its possible to reload a single texture or resource. While it would be good to be able to reload models as well (When I say resource I mean sounds, textures, models, those things), I would settle for just being able to reload a texture.

 

I've reloaded all assets using Minecraft.getInstance().reloadResourcePacks(); on the client side.

 

My client is receiving a custom packet that contains a string resource location. This string is turned into an actual ResourceLocation, before being sent to my ResourceReloader.reloadSingleTexture utility function.

What I've tried in my utility function:

Spoiler

Releasing the texture and re-binding using TextureManager

public static void reloadSingleTexture(String resourcePath) {

  TextureManager textureManager = Minecraft.getInstance().getTextureManager();

  ResourceLocation resourceLocation = new ResourceLocation(resourcePath);

  textureManager.release(resourceLocation);

  // Rebind the texture, forcing it to be re-loaded?
  textureManager.bindForSetup(resourceLocation);
}
Spoiler

Make a new texture object and add that using TextureManager

public static void reloadSingleTexture(String resourcePath) {

    TextureManager textureManager = Minecraft.getInstance().getTextureManager();
  
    ResourceLocation resourceLocation = new ResourceLocation(resourcePath);

  	// Just some unimportant error prevention
    AbstractTexture texture = textureManager.getTexture(resourceLocation);
    if (texture == null) {
      return;
    }

    textureManager.release(resourceLocation);

  	// Make a new texture object?
    SimpleTexture newTexture = new SimpleTexture(resourceLocation);
  
  	// Re-add the texture?
    textureManager.register(resourceLocation, newTexture);
}

 

Resources I've looked at:

 

Reloading all textures, and outdated (somewhere around 1.9-1.12)

 

Maybe a "new way" with forge to reload textures? Seems mostly for testing and not for use as a part of your mod:

https://gist.github.com/Gegy/148be244454fe667ade6c09cc6d5145e

 

Havent looked much at this one, but it seems to be reloading groups/namespaces of textures somehow? Also outdated - 1.12

https://www.curseforge.com/minecraft/mc-mods/resource-reloader


Isn't super helpful, since fabric, but also seems to just be mixin the keyboard so that F3+T works in GUI's, nothing very useful:

https://modrinth.com/mod/f3-t-everywhere

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.