Jump to content

Trouble editing the main menu


pvwatermelon

Recommended Posts

I've made a class that extends MainMenuScreen, and I've set my gui to this class. I'm trying to override the init method in MainMenuScreen to change the logo and maybe some other things, but I'm unable to access all the private variables in MainMenuScreen. I'm not really sure what to do from here, any help is appreciated. I've looked around the forums and internet and couldn't really find much.

Edited by pvwatermelon
Link to comment
Share on other sites

  • pvwatermelon changed the title to Trouble editing the main menu
15 hours ago, diesieben07 said:

Reflection

I was able to get the private variables of MainMenuScreen using reflection, but inside of init() there were calls to some private methods. I can't override them and just copy the code of the original methods because they're private.  Am I supposed to obtain the private methods through reflection too and then run the private methods that way? I ran into issues trying to that earlier but if that's the right way I'll keep at it.

Edited by pvwatermelon
Link to comment
Share on other sites

20 hours ago, diesieben07 said:

Reflection can call private methods, yes.

I've reflected all the private methods used in init() from MainMenuScreen and made sure all the variables used in init() are reflected, but my Minecraft still crashes at the beginning of the code of my NewMainMenu class with a null pointer exception. In the java documentation it says that a null pointer exception is thrown when the object that the method invoking is null, but I don't know what else I would invoke the methods on besides this.



import net.minecraft.client.gui.AccessibilityScreen;
import net.minecraft.client.gui.screen.*;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.widget.button.ImageButton;
import net.minecraft.client.renderer.RenderSkybox;
import net.minecraft.realms.RealmsBridgeScreen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.lang.reflect.*;
import javax.annotation.Nullable;
import java.lang.reflect.*;
@OnlyIn(Dist.CLIENT)
public class NewMainMenu extends MainMenuScreen {
    @Nullable
    private String thesplash;
    private Button theresetDemoButton;
    private boolean therealmsNotificationsInitialized;
    private Screen therealmsNotificationsScreen;
    private int thecopyrightWidth;
    private int thecopyrightX;
    private long thefadeInStart;
    private static ResourceLocation theACCESSIBILITY_TEXTURE;
    private net.minecraftforge.client.gui.NotificationModUpdateScreen themodUpdateNotification;
    Method mycreateDemoMenuOptions;
    Method mycreateNormalMenuOptions;
    Method myrealmsNotificationsEnabled;
    boolean answer = false;

    public  void main(String[] args) {
        try {
            Field val = this.getClass().getSuperclass().getDeclaredField("splash");
            val.setAccessible(true);
            thesplash = (String) val.get(this);
            val = this.getClass().getSuperclass().getDeclaredField("copyrightWidth");
            thecopyrightWidth = (int) val.get(this);
            val = this.getClass().getSuperclass().getDeclaredField("ACCESSIBILITY_TEXTURE");
            theACCESSIBILITY_TEXTURE = (ResourceLocation) val.get(this);
            val = this.getClass().getSuperclass().getDeclaredField("copyrightX");
            thecopyrightX= (int) val.get(this);
            val = this.getClass().getSuperclass().getDeclaredField("realmsNotificationsInitialized");
            therealmsNotificationsInitialized = (boolean) val.get(this);
            val = this.getClass().getSuperclass().getDeclaredField("realmsNotificationsScreen");
            therealmsNotificationsScreen = (Screen) val.get(this);
            val = this.getClass().getSuperclass().getDeclaredField("theresetDemoButton");
            theresetDemoButton = (Button) val.get(this);
            val = this.getClass().getSuperclass().getDeclaredField("fadeInStart");
            thefadeInStart = (long) val.get(this);
            val = this.getClass().getSuperclass().getDeclaredField("modUpdateNotification");
            themodUpdateNotification = (net.minecraftforge.client.gui.NotificationModUpdateScreen) val.get(this);
            //Functions
            mycreateDemoMenuOptions= this.getClass().getSuperclass().getDeclaredMethod("createDemoMenuOptions", int.class, int.class);
            mycreateNormalMenuOptions= this.getClass().getSuperclass().getDeclaredMethod("createNormalMenuOptions", int.class, int.class);
            myrealmsNotificationsEnabled = this.getClass().getSuperclass().getDeclaredMethod("realmsNotificationsEnabled");
            myrealmsNotificationsEnabled.setAccessible(true);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    @Override
    protected void init() {

        if (this.thesplash == null) {
            this.thesplash = this.minecraft.getSplashManager().getSplash();
        }

        this.thecopyrightWidth = this.font.width("Copyright Mojang AB. Do not distribute!");
        this.thecopyrightX = this.width - this.thecopyrightWidth - 2;
        int i = 24;
        int j = this.height / 4 + 48;
        Button modButton = null;
        if (this.minecraft.isDemo()) {
            //this.createDemoMenuOptions(j, 24);
            mycreateDemoMenuOptions.setAccessible(true);
            try {
                mycreateDemoMenuOptions.invoke(this, j, 24);
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        } else {
            //this.createNormalMenuOptions(j, 24);
            mycreateNormalMenuOptions.setAccessible(true);
            try {
                mycreateNormalMenuOptions.invoke(this, j, 24);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            modButton = this.addButton(new Button(this.width / 2 - 100, j + 24 * 2, 98, 20, new TranslationTextComponent("fml.menu.mods"), button -> {
                this.minecraft.setScreen(new net.minecraftforge.fml.client.gui.screen.ModListScreen(this));
            }));
        }
        themodUpdateNotification = net.minecraftforge.client.gui.NotificationModUpdateScreen.init(this, modButton);

        this.addButton(new ImageButton(this.width / 2 - 124, j + 72 + 12, 20, 20, 0, 106, 20, Button.WIDGETS_LOCATION, 256, 256, (p_213090_1_) -> {
            this.minecraft.setScreen(new LanguageScreen(this, this.minecraft.options, this.minecraft.getLanguageManager()));
        }, new TranslationTextComponent("narrator.button.language")));
        this.addButton(new Button(this.width / 2 - 100, j + 72 + 12, 98, 20, new TranslationTextComponent("menu.options"), (p_213096_1_) -> {
            this.minecraft.setScreen(new OptionsScreen(this, this.minecraft.options));
        }));
        this.addButton(new Button(this.width / 2 + 2, j + 72 + 12, 98, 20, new TranslationTextComponent("menu.quit"), (p_213094_1_) -> {
            this.minecraft.stop();
        }));
        this.addButton(new ImageButton(this.width / 2 + 104, j + 72 + 12, 20, 20, 0, 0, 20, theACCESSIBILITY_TEXTURE, 32, 64, (p_213088_1_) -> {
            this.minecraft.setScreen(new AccessibilityScreen(this, this.minecraft.options));
        }, new TranslationTextComponent("narrator.button.accessibility")));
        this.minecraft.setConnectedToRealms(false);
        if (this.minecraft.options.realmsNotifications && !this.therealmsNotificationsInitialized) {
            RealmsBridgeScreen realmsbridgescreen = new RealmsBridgeScreen();
            this.therealmsNotificationsScreen = realmsbridgescreen.getNotificationScreen(this);
            this.therealmsNotificationsInitialized = true;
        }

        //if (this.realmsNotificationsEnabled()) {

        try {
            answer = (boolean) myrealmsNotificationsEnabled.invoke(this);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        if (answer) {
            this.therealmsNotificationsScreen.init(this.minecraft, this.width, this.height);
        }

    }

}

 

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I set the value you mentioned to me and after a few hours of testing the server has worked correctly. Thank you very much for your help
    • 6:26:58 PM: Executing 'wrapper'... Download http://files.minecraftforge.net/maven/net/minecraftforge/gradle/ForgeGradle/2.1-SNAPSHOT/maven-metadata.xml, took 3 s 928 ms Download http://files.minecraftforge.net/maven/net/minecraftforge/fernflower/2.0-SNAPSHOT/maven-metadata.xml, took 2 s 332 ms FAILURE: Build failed with an exception. * Where: Build file 'C:\Users\Slacker201\Desktop\MinecraftMacro\build.gradle' line: 16 * What went wrong: A problem occurred evaluating root project 'MinecraftMacro'. > Failed to apply plugin 'net.minecraftforge.gradle.forge'.    > Configuration with name 'compile' not found. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. BUILD FAILED in 56s Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation. 6:27:54 PM: Execution finished 'wrapper'.
    • Against the Odds: How I Recovered $86,000 from a Binary Options Fraud unmasking the scam. I never thought I’d see my money again. After months of frustration, I had lost hope of recovering the $86,000 I invested in a binary options trading platform. But today, I want to share my journey and prove that recovery is possible. Living in Colombia, I first encountered the platform through a flashy online advertisement. It promised quick returns through binary options trading, a concept I didn’t fully grasp but found alluring. Initially, I invested $2,000, encouraged by what appeared to be substantial gains. As my balance grew, I became more confident and ended up investing an additional $84,000. For a while, everything seemed to be going well. The platform displayed impressive profits, claiming I had made $175,000. However, when I tried to withdraw a significant portion of my earnings, I faced an onslaught of obstacles. My requests were met with delays and vague excuses. Each time I was prompted to pay withdrawal fees, I complied, only to find more fees waiting for me: taxes, processing charges, and even unexpected compliance fees. I realized too late that I was trapped in a scam, having lost another $26,000 in fees alone. The experience was not only financially devastating but also emotionally draining. I felt embarrassed for trusting a platform I barely understood. Yet, despite the discouragement, I was determined to fight for my money. After extensive research, I discovered Rapid Digital Recovery and their promising testimonials. Skeptical but desperate, I decided to reach out, WHAT SAPP: + 1 41 4 80 7 14 85.... To my surprise, Rapid Digital Recovery managed to recover 100% of my investment. The relief I felt was indescribable. Although I still grapple with regret over my initial decisions, I’m incredibly thankful for the support I received. They restored not just my funds but also my confidence in the recovery process. If you’re into scam, don’t lose hope. Reach out to Rapid Digital Recovery You don’t have to go through this alone, and there is a way to reclaim what you’ve lost. Web site: https: // ra pi ddigit alrecove ry .o rg
    • Replace it with other/older builds: https://www.curseforge.com/minecraft/mc-mods/farmers-delight/files/all?page=1&pageSize=20&version=1.20.1
    • idk how to show a screenshot with a url, but i have the forge file on desktop, and its just a paper folded in the corner and not the forge logo and i cant open it and go to the installer
  • Topics

×
×
  • Create New...

Important Information

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