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

Hey guys, so I'm at a point where I want to learn how to use a config file to allow/disallow certain things in my mod. However, I haven't been able to find anything about the proper way to use a config file, only how to create it and add things to it. If someone here could point me in the right direction that would be great.

when you add things to the config file you are actually reading it. you add the default or get the value set in the file. in other words, if that thing you're adding is already there and if it has another value, then it reads that value from the file. if what you're adding is not in the file, then it adds it:

 

@EventHandler
public static void preInit(FMLPreInitializationEvent event)
{
    //this line either creates the file if it doesn't exist or opens it if it already exists.
    Configuration config = new Configuration(event.getSuggestedConfigurationFile());
    config.load();//reads the contents of the file into the Configuration object.

    //use the config.get* methods to add/get values from the config as I explained above.

    //after you're done:
    config.save();//saves the Configuration content into the file.
}

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

  • Author

when you add things to the config file you are actually reading it. you add the default or get the value set in the file. in other words, if that thing you're adding is already there and if it has another value, then it reads that value from the file. if what you're adding is not in the file, then it adds it:

 

@EventHandler
public static void preInit(FMLPreInitializationEvent event)
{
    //this line either creates the file if it doesn't exist or opens it if it already exists.
    Configuration config = new Configuration(event.getSuggestedConfigurationFile());
    config.load();//reads the contents of the file into the Configuration object.

    //use the config.get* methods to add/get values from the config as I explained above.

    //after you're done:
    config.save();//saves the Configuration content into the file.
}

 

Okay, so if I were to use a boolean for a item, how would I do that? Isn't this code only for making the config file, with the default values. Could you maybe give me an example for an item if true is in the mod, if false isn't in the mod?

it creates the file or reads it if it already exists.

 

boolean shouldRegisterItem;

@EventHandler
public static void preInit(FMLPreInitializationEvent event)
{
    //this line either creates the file if it doesn't exist or opens it if it already exists.
    Configuration config = new Configuration(event.getSuggestedConfigurationFile());
    config.load();//reads the contents of the file into the Configuration object.

    boolean defaultValue = true;
    
    shouldRegisterItem = config.get(Configuration.CATEGORY_GENERAL, "should_register_item", defaultValue);

    //after you're done:
    config.save();//saves the Configuration content into the file.
}

@EventHandler
public static void init(FMLInitializationEvent event)
{
    if(shouldRegisterItem)
    {
        //invoke GameRegistry.registerItem() for your item.
    }
}

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

  • Author

it creates the file or reads it if it already exists.

 

boolean shouldRegisterItem;

@EventHandler
public static void preInit(FMLPreInitializationEvent event)
{
    //this line either creates the file if it doesn't exist or opens it if it already exists.
    Configuration config = new Configuration(event.getSuggestedConfigurationFile());
    config.load();//reads the contents of the file into the Configuration object.

    boolean defaultValue = true;
    
    shouldRegisterItem = config.get(Configuration.CATEGORY_GENERAL, "should_register_item", defaultValue);

    //after you're done:
    config.save();//saves the Configuration content into the file.
}

@EventHandler
public static void init(FMLInitializationEvent event)
{
    if(shouldRegisterItem)
    {
        //invoke GameRegistry.registerItem() for your item.
    }
}

I feel a bit studip now :D

Thanks for helping me :)

hey I just know that because someone taught me too. nobody's stupid :)

 

just notice the category can be any string you want, and if you want sub categories all you have to do is to name them them like this: "parentCategory.childCategory". You can use config.addCustomCategoryComment(categoryName, "categoryComment")

 

it's a lot easier than it seems at first.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

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.