Jump to content

Recommended Posts

Posted (edited)

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
  • pvwatermelon changed the title to Trouble editing the main menu
Posted (edited)
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
Posted
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);
        }

    }

}

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I see. I'm sure I tried again with a lower case word, a few times. I ended up doing the same thing as pixxy in the end. Is this beyond the scope of the admins to fix? Are they already aware of it, or should I use 'contact us' to post a ticket?
    • I’m working on a Manta Ray entity in MCreator using GeckoLib animations, and my goal is to have a looping (flip) animation that ends at −360°, then transitions seamlessly into a swim animation starting at 0°. However, every method I’ve tried—like quickly interpolating the angle, inserting a brief keyframe at 0°, or using a micro “bridge” animation—still causes a visible “flash” https://imgur.com/a/5ucjUb9 or "jump" when the rotation resets. I want a perfectly smooth motion from the flip’s final rotation to the swim’s initial rotation. If anyone has solved this in MCreator/GeckoLib, or found a better trick for handling the −360° →0° gap without a snap, I’d appreciate some advice ! P.S.- I cannot set swim to start at -360 because I would have the same issue but in reverse. Here's the custom LoopingAnimationGoal :   class LoopingAnimationGoal extends Goal { private final MantaRayEntity entity; private final int cooldownTime; private int animationTimer; private int cooldownTimer; // New boolean to prevent double calls private boolean isLoopingActive = false; public LoopingAnimationGoal(MantaRayEntity entity, int cooldownTime) { this.entity = entity; this.cooldownTime = cooldownTime; this.animationTimer = 0; this.cooldownTimer = 0; this.setFlags(EnumSet.of(Flag.MOVE, Flag.LOOK)); } @Override public boolean canUse() { System.out.println("[DEBUG] LoopingGoal canUse => cooldownTimer=" + cooldownTimer); if (cooldownTimer > 0) { cooldownTimer--; return false; } BlockPos entityPos = entity.blockPosition(); boolean canUse = entity.isWaterAbove(entityPos, 4); System.out.println("[DEBUG] LoopingGoal canUse => WATER " + (canUse ? "DETECTED" : "NOT DETECTED") + " at " + entityPos + ", returning " + canUse); return canUse; } @Override public void start() { entity.setAnimation("looping"); animationTimer = 63; isLoopingActive = true; System.out.println("[DEBUG] Looping animation STARTED. Timer=" + animationTimer + ", gameTime=" + entity.level().getGameTime()); } @Override public boolean canContinueToUse() { System.out.println("[DEBUG] LoopingGoal canContinueToUse => animationTimer=" + animationTimer); return animationTimer > 0; } @Override public void tick() { animationTimer--; System.out.println("[DEBUG] LoopingGoal TICK => animationTimer=" + animationTimer); // We stop ONLY if we are still looping if (animationTimer <= 0 && isLoopingActive) { System.out.println("[DEBUG] condition => animationTimer <= 0 && isLoopingActive"); stop(); } } @Override public void stop() { // Check if already stopped if (!isLoopingActive) { System.out.println("[DEBUG] stop() called again, but isLoopingActive = false. Doing nothing."); return; } System.out.println("[DEBUG] Looping STOP at tick=" + entity.level().getGameTime() + ", last known rotation=" + entity.getXRot() + "/" + entity.getYRot() + ", animationTimer=" + animationTimer); // Immediately switch to "swim" entity.setAnimation("swim"); // Reset cooldown cooldownTimer = cooldownTime; // Disable looping to prevent a second stop isLoopingActive = false; System.out.println("[DEBUG] Looping STOP => setAnimation('swim'), cooldownTimer=" + cooldownTimer); } }  
    • So is the intention of the crusher for ores meant to be used with a silk touch pickaxe or something? Cause that seems like too much effort just to profit off of the machine, when everything drops as raw materials now. Am I just missing something? 
  • Topics

×
×
  • Create New...

Important Information

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