Jump to content

Loaded texture just white


Bedrock_Miner

Recommended Posts

Hello everyone!

 

I wanted to create a little Easter-Egg like feature for one of my mods where the background of the gui screens (The one which is normally dirt) is replaced with other textures based on some values of the player.

 

I now encountered the problem that sometimes the texture is not used. Instead, a white surface is shown. This does not depend on the image I want to load.

 

Here's my code:

 

@SubscribeEvent
public void onGuiOpen(GuiOpenEvent e) {
    RandomOptionsScreen.replaceImage();
}

((To test stuff I replaced the other calculation with a random one))

public static void replaceImage() {
    if (images.length == 0)
        return;

    int index = CommonUtils.random.nextInt(images.length);
    int firstindex = index;
    boolean accepted = false;
    boolean useDefault = false;
    Minecraft.getMinecraft().getTextureManager().deleteTexture(Gui.optionsBackground);

    do {
        ResourceLocation r = new ResourceLocation(images[index]);
        accepted = true; //Testing: accepts is always true
        if (!accepted) {
            index = (index + 1) % images.length;
            if (index == firstindex) {
                useDefault = true;
                break;
            }
            Minecraft.getMinecraft().getTextureManager().deleteTexture(r);
        }
    } while (!accepted);

    String s = useDefault ? "textures/gui/options_background.png" : RandomOptionsScreen.images[index];

    Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation(s));
    ModReflectionHelper.setField(Gui.class, null, ReflectionConstants.F_OPTIONS_BG, new ResourceLocation(s));
    Log.info_("Result:%s", s);
}

 

 

Any Ideas what I might have done wrong?

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

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