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,

I was wondering what the current standard for implementing config files into mods. I am unable to find any tutorials or documentation on how to implement a config (.cfg) file.

If anyone is able to point me to a tutorial or documentation page that I overlooked it would be greatly appreciated.

Thank you for your time!

Edited by Cryoexn

I don't know if there is any documentation, but at least half the mods you play with are configurable - you find their source code and look at it.

there is really no way to explaining this other than dumping a bit of code:

public class OptionsHolder
{
	public static class Common
	{
		private static final int defaultInt1 = 37;
		private static final boolean defaultBool1 = true;

		public final ConfigValue<Integer> Int1;
		public final ConfigValue<Boolean> Bool1;


		public Common(ForgeConfigSpec.Builder builder)
		{
			builder.push("category1");
			this.Int1 = builder.comment("This is a nice description of your option. Make it a lot longer than this. Max is 60, default is 37. Enjoy...")
					.worldRestart()
					.defineInRange("Short but readable name", defaultInt1, 1, 60);
			this.Bool1 = builder.comment("asdasd as asd asd asd asdas aasd as asd asd. asd as asd asd. asdasdad asd.")
					.define("Short but readable name 2", defaultBool1);
			builder.pop();
		}
	}

	public static final Common COMMON;
	public static final ForgeConfigSpec COMMON_SPEC;

	static //constructor
	{
		Pair<Common, ForgeConfigSpec> commonSpecPair = new ForgeConfigSpec.Builder().configure(Common::new);
		COMMON = commonSpecPair.getLeft();
		COMMON_SPEC = commonSpecPair.getRight();
	}
}

then, in your main class constructor you say:

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, OptionsHolder.COMMON_SPEC); 

and that's it. the game will create the config file. players will edit it and you read values by saying OptionsHolder.COMMON.Bool1.get().

this creates a single config file in config folder. you can have separate server config (created in world save folder) and client config (in config folder) by creating two small static classes inside the big one (same file) and duplicating that one line in the main class constructor. or you can have just the server config or just the client config.

Edited by MFMods

  • Cryoexn changed the title to [1.16.5] Implementing Forge Config File [Solved]

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.