Jump to content

Recommended Posts

Posted

This snippet of code came from a 1.11 mod I'm trying to use to create a gui config.  I think maybe the code was changed between 1.11 and 1.12 as it's telling me it can't me resolved.

 

package com.fuzzybat23.csbr.config;

import java.util.Set;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.client.IModGuiFactory;

public class GuiFactory implements IModGuiFactory
{
    @Override
    public void initialize(Minecraft minecraftInstance)
    {   }

    @Override  <---- Error 1
    public Class<? extends GuiScreen> mainConfigGuiClass()
        {
        return GuiModConfig.class;
    }

    @Override <---- Error 2
    public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()  <---- Error 3
    {
        return null;
    }

    @Override
    public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element)
    {
        return null;
    }

    @Override
    public boolean hasConfigGui()
    {
        return true;
    }

    @Override
    public GuiScreen createConfigGui(GuiScreen parentScreen)
    {
        return new GuiModConfig(parentScreen);
    }

}

Error 1 and Error 2 say "Method does not override method from its superclass."

 

Error 3 is in reference to RuntimeOptionGuiHandler and says "Cannot resolve symbol 'RuntimeOptionGuiHandler'

 

Any one know if this has been changed?  This GuiFactory is a direct copy of another person's code that does compile, as far as I know, as his mod has been released with no errors.

 

mainConfigGuiClasss refers to net.minecraftforge.fml.client.config.GuiConfig.java which reads:

 

    public GuiConfig(GuiScreen parentScreen, String modID, boolean allRequireWorldRestart, boolean allRequireMcRestart, String title,
            Class<?>... configClasses)
    {
        this(parentScreen, collectConfigElements(configClasses), modID, null, allRequireWorldRestart, allRequireMcRestart, title, null);
    }

 

and the new GuiModConfig.java in my mod directory reads:

 

package com.fuzzybat23.csbr.config;

import com.fuzzybat23.csbr.CSBR;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.fml.client.config.GuiConfig;

public class GuiModConfig extends GuiConfig {
    public GuiModConfig(GuiScreen parent) {
        super(
                parent,
                new ConfigElement(CSBR.instance.config.file.getCategory("general")).getChildElements(),
                CSBR.MODID,
                false,
                false,
                GuiConfig.getAbridgedConfigPath(CSBR.instance.config.file.toString())
        );
    }
}

 

Posted
10 minutes ago, fuzzybat23 said:

Error 1 and Error 2 say "Method does not override method from its superclass."

 

Those particular methods have been deleted as they've been deprecated for a while now.

 

11 minutes ago, fuzzybat23 said:

Error 3 is in reference to RuntimeOptionGuiHandler and says "Cannot resolve symbol 'RuntimeOptionGuiHandler'

 

RuntimeOptionGuiHandler was deleted as, quoting the javadocs for RuntimeOptionGuiHandler from 1.11 code:

TODO remove in 1.11 - this was never fully implemented and will be removed

And it also was deprecated btw.

 

 

Posted

Actually, mainConfigGuiClass wasn't deleted, it was renamed.  It's still in IModGuiFactory, but as createConfigGui.

 

The old ->
public Class<? extends GuiScreen> mainConfigGuiClass();


    /**
     * Return a list of the "runtime" categories this mod wishes to populate with
     * GUI elements.
     *
     * Runtime categories are created on demand and organized in a 'lite' tree format.
     * The parent represents the parent node in the tree. There is one special parent
     * 'Help' that will always list first, and is generally meant to provide Help type
     * content for mods. The remaining parents will sort alphabetically, though
     * this may change if there is a lot of alphabetic abuse. "AAA" is probably never a valid
     * category parent.
     *
     * Runtime configuration itself falls into two flavours: in-game help, which is
     * generally non interactive except for the text it wishes to show, and client-only
     * affecting behaviours. This would include things like toggling minimaps, or cheat modes
     * or anything NOT affecting the behaviour of the server. Please don't abuse this to
     * change the state of the server in any way, this is intended to behave identically
     * when the server is local or remote.
     *
     * @return the set of options this mod wishes to have available, or empty if none
     */

The New ->
    public GuiScreen createConfigGui(GuiScreen parentScreen);

    /**
     * Return a list of the "runtime" categories this mod wishes to populate with
     * GUI elements.
     *
     * Runtime categories are created on demand and organized in a 'lite' tree format.
     * The parent represents the parent node in the tree. There is one special parent
     * 'Help' that will always list first, and is generally meant to provide Help type
     * content for mods. The remaining parents will sort alphabetically, though
     * this may change if there is a lot of alphabetic abuse. "AAA" is probably never a valid
     * category parent.
     *
     * Runtime configuration itself falls into two flavours: in-game help, which is
     * generally non interactive except for the text it wishes to show, and client-only
     * affecting behaviours. This would include things like toggling minimaps, or cheat modes
     * or anything NOT affecting the behaviour of the server. Please don't abuse this to
     * change the state of the server in any way, this is intended to behave identically
     * when the server is local or remote.
     *
     * @return the set of options this mod wishes to have available, or empty if none
     */

So get rid of the runtime handler completely, eh?  Well, as for the other one which was renamed, not deleted, I redid the code as:

    @Override
    public Class<? extends GuiScreen> createConfigGui()
    {
        return ConfigGui.class;
    }

It throws the same error though.  Should I just erase that line, as well, and delete the GuiModConfig.java file and add it directly into the GuiFactory?

 

package com.fuzzybat23.csbr.config;

import java.util.Set;

import com.fuzzybat23.csbr.CSBR;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.client.IModGuiFactory;
import net.minecraftforge.fml.client.config.GuiConfig;

public class GuiFactory implements IModGuiFactory
{
    @Override
    public void initialize(Minecraft minecraftInstance)
    {   }

  //  @Override
  //  public Class<? extends GuiScreen> createConfigGui()
  //  {
  //      return ConfigGui.class;
  //  }

    @Override
    public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
    {
        return null;
    }

    @Override
    public boolean hasConfigGui()
    {
        return true;
    }

    @Override
    public GuiScreen createConfigGui(GuiScreen parentScreen)
    {
        return new ConfigGui(parentScreen);
    }

    public static class ConfigGui extends GuiConfig
    {
        public ConfigGui(GuiScreen parent)
        {
            super(parent, new ConfigElement(CSBR.instance.config.file.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
                    CSBR.MODID, false, false,
                    GuiConfig.getAbridgedConfigPath(CSBR.instance.config.file.toString()));
        }
    }
}

 

Posted
7 minutes ago, fuzzybat23 said:

Actually, mainConfigGuiClass wasn't deleted, it was renamed.  It's still in IModGuiFactory, but as createConfigGui.

No it was deleted, look at the signatures:

1.11:

public Class<? extends GuiScreen> mainConfigGuiClass();

 

1.12

public GuiScreen createConfigGui(GuiScreen parentScreen);

 

How is that renamed? The return type changed, a parameter had been introduced and the name is different. This does not look like a rename to me. Especially considering the fact that 1.11 has the createConfigGui method with the exact 1.12 signature.

 

9 minutes ago, fuzzybat23 said:

It throws the same error though.

Yes it does. There is no 

public Class<? extends GuiScreen> createConfigGui()

method for you to override or implement in the interface.

 

Your last code attachment looks fine to me.

Posted

Well, it compiles just fine.  I ran the other mod that has the original code and it's config screen opens just fine.  Mine doesn't crash when I click on the Config button,but it does throw this:

 

[19:35:13] [main/ERROR] [FML]: There was a critical issue trying to build the config GUI for csbr
java.lang.NullPointerException: null
	at com.fuzzybat23.csbr.config.GuiFactory$ConfigGui.<init>(GuiFactory.java:47) ~[GuiFactory$ConfigGui.class:?]
	at com.fuzzybat23.csbr.config.GuiFactory.createConfigGui(GuiFactory.java:40) ~[GuiFactory.class:?]
	at net.minecraftforge.fml.client.GuiModList.actionPerformed(GuiModList.java:301) [GuiModList.class:?]
	at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:494) [GuiScreen.class:?]
	at net.minecraftforge.fml.client.GuiModList.mouseClicked(GuiModList.java:205) [GuiModList.class:?]
	at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:611) [GuiScreen.class:?]
	at net.minecraftforge.fml.client.GuiModList.handleMouseInput(GuiModList.java:351) [GuiModList.class:?]
	at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:576) [GuiScreen.class:?]
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1861) [Minecraft.class:?]
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1171) [Minecraft.class:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:436) [Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:26) [start/:?]

 

Posted
3 minutes ago, fuzzybat23 said:

java.lang.NullPointerException: null at com.fuzzybat23.csbr.config.GuiFactory$ConfigGui.<init>(GuiFactory.java:47) ~[GuiFactory$ConfigGui.class:?]

Well, something in your ConfigGui constructor is null. Try setup a breakpoint to figure out what. The potential culprits are:

19 minutes ago, fuzzybat23 said:

CSBR.instance

19 minutes ago, fuzzybat23 said:

CSBR.instance.config

19 minutes ago, fuzzybat23 said:

CSBR.instance.config.file

 

 

Posted

My main class is:

package com.fuzzybat23.csbr;

import com.fuzzybat23.csbr.config.ConfigManager;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.io.File;

@net.minecraftforge.fml.common.Mod(modid = "csbr", version = "1.0", clientSideOnly = true, acceptedMinecraftVersions = "[1.12, 1.13)", guiFactory = "com.fuzzybat23.csbr.config.GuiFactory")
public class CSBR
{
    @net.minecraftforge.fml.common.Mod.Instance("CSBR")
    public static final String MODID = "csbr";

    public static CSBR instance;
    public ConfigManager config;

    public CSBR()
    {   }

    @Mod.EventHandler
    @SideOnly(Side.CLIENT)
    public void preInit(FMLPreInitializationEvent event)
    {
        config = new ConfigManager(event.getModConfigurationDirectory());
    }

    @Mod.EventHandler
    @SideOnly(Side.CLIENT)
    public void initialize(FMLInitializationEvent event)
    {
        MinecraftForge.EVENT_BUS.register(this);
        MinecraftForge.EVENT_BUS.register(config);

    }


    @Mod.EventHandler
    @SideOnly(Side.CLIENT)
    public void load(FMLInitializationEvent event)
    {

    }
}

I can't figure out where that null is coming from xD

Posted
9 hours ago, fuzzybat23 said:

public static CSBR instance;

This field is null and you never assign anything to it.

 

9 hours ago, fuzzybat23 said:

@net.minecraftforge.fml.common.Mod.Instance("CSBR")

public static final String MODID = "csbr";

An Instance annotation goes over a field you want an instance of your mod to be injected into, not over the field that contains your modid.

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

    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
    • Does it still crash if you remove holdmyitems? Looks like that mod doesn't work on a server as far as I can tell from the error.  
    • Crashes the server when trying to start. Error code -1. Log  
  • Topics

×
×
  • Create New...

Important Information

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