Jump to content

Recommended Posts

Posted

Hello,

 

How would you create a submenu in 1.12.2 using the config annotations?

 

I currently have
 

@Config(modid = ScreenshotMain.MODID)
@Config.LangKey("main.config.title")
public class ModConfig{


    @Config.Name("Override")
    @Config.Comment("Override the default screenshotkey, This will cause images to save and upload. ")
    public static boolean Override = false;

    @Config.Name("CopyToClipboard")
    @Config.Comment("Set to true if you want to copy the link to your clipboard")
    public static boolean SaveScreenshots = true;

    @Config.Name("Use Custom Server")
    @Config.Comment("Set to true if you wan to use your own webserver")
    public static boolean CustomServer = false;

    @Config.Name("Link")
    @Config.Comment("Set the link to your image server")
    public static String server = "";
}

 

Screenshot: http://prntscr.com/j0upq2

 

this all works, but how would i make a submenu under a button "settings" and place more options under that?
and additionally, make that button unclickable/disabled if "Use Custom Server" is set to false.

 

Also i noticed that Use Custom Server is always at the top even though its set last in the code? Any idea why that is?

Posted (edited)

 

To make a subsection in-game you'll need to make a subclass ModConfig.Category and annotate it with @Config(modid="<Your modid>", category="Category Name").

If you do this I would recommend adding [name="modid/category"] to all of your config classes. You can see how I did it here.

 

@Config in the Forge docs.

Additional note: I believe the order is based on the variables rather than their @Config.Name, as CustomServer starts with C and there is no A or B variables it is bumped to the top.

Edited by DaemonUmbra
Changed link to jump to where the applicable section starts.

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted

Okay so i managed to do that.

 

However, now i get 2 config files. Not really a big deal on its own. But to keep things clean it put them in a sub directory.

 

What would be the best way to get/load/edit those config files?

 

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event){
  File configDir = event.getModConfigurationDirectory();
  //What do i do now?
  
  
  //Do i still need this?
  ConfigManager.sync(MODID, Config.Type.INSTANCE);
}

 

Posted
@SubscribeEvent
    public static void OnConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
        if (event.getModID().equals(MOD_ID)) {
          ConfigManager.sync(MOD_ID, Config.Type.INSTANCE);
        }
}

is what you're looking for

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted
  On 4/4/2018 at 8:22 PM, DaemonUmbra said:
@SubscribeEvent
    public static void OnConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
        if (event.getModID().equals(MOD_ID)) {
          ConfigManager.sync(MOD_ID, Config.Type.INSTANCE);
        }
}

is what you're looking for

Expand  

It never seems to trigger(I just added it to my main class). Also my config files are located in

config/ScreenshotUploader

 

Are you sure this is how to do it?

Posted (edited)

Remember you'll need to register it to the event bus for it to fire.

 

 

aaaaand I'm dumb, that fires when the in-game config editor gets closed, you'll need to call sync in preInit as well, sorry. :P

Edited by DaemonUmbra
Added link
  • Like 1

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted
@Mod.EventHandler
    public void preInit(FMLPreInitializationEvent event){
        ConfigManager.sync(MODID, Config.Type.INSTANCE);
    }

@Mod.EventHandler
    public void init(FMLInitializationEvent event)
    {
        MinecraftForge.EVENT_BUS.register(new KeyPressEvent());
        MinecraftForge.EVENT_BUS.register(new CustomScreenshotEvent());
        MinecraftForge.EVENT_BUS.register(new ModConfig());
        MinecraftForge.EVENT_BUS.register(new ConfigChanged());

        keybinds.RegisterKeybinds();
    }
public class ConfigChanged{
    @SubscribeEvent
    public static void OnConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
        if (event.getModID().equals(ScreenshotMain.MODID)) {
            ConfigManager.sync(ScreenshotMain.MODID, Config.Type.INSTANCE);
            System.out.println("Triggered Configchange");
        }
    }
}

Thats what i'm doing right now.

 

However i noticed this not working before (used a workaround). Could this be somemthing with Forge?

Posted (edited)

Seems I was wrong about calling it in preInit, from forge inline docs: 

Note, that this method is being called by the {@link FMLModContaier}, so the mod needn't call it in init().

Oh well, live and learn

Edited by DaemonUmbra

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

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.