Jump to content

Recommended Posts

Posted

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?

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.