Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.