Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5] Implementing Forge Config File [Solved]


Recommended Posts

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
Link to post
Share on other sites

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
  • Thanks 1
Link to post
Share on other sites
  • 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.

Guest
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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.