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,

I want to make a flag in the config like this:

 

flag1 = configFile.get("Misc", "if false: deactivats the item", true).getBoolean(flag1);

 

and then add the item like this:

 

    public void addItems() {

    	if(flag1) {
    		final Item MyItem = new MyItem().setUnlocalizedName("MyItem").setTextureName("");
            GameRegistry.registerItem(MyItem, "MyItem");
    	}
    }

But it can't be public and I can't reach it from other classes...

 

Thanks for help!

Where have you declared your flag? Try making it like that:

Configloader

public class YourConfig{
public YourConfig(){
}
public static void initConfig(File f){
	c = new Configuration(f);
	try{
		c.load();
		addItems = c.get("Misc", "Add items?", true).getBoolean(true);
		FMLCommonHandler.instance().getFMLLogger().log(Level.INFO, "[Yourmod] Done loading the config");
	}catch(final Exception e){
		FMLCommonHandler.instance().getFMLLogger().log(Level.ERROR, "[Yourmod] Error occured while loading the config");
	}finally{
		if(c.hasChanged()){
			c.save();
		}
	}
}
public static Configuration c;
public static boolean addItems;
}

Place where you register items:

final Item MyItem = new MyItem().setUnlocalizedName("MyItem").setTextureName("");
if(YourConfig.addItems){
   GameRegistry.registerItem(MyItem, "MyItem");
}

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Make it public static then.

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

I might misunderstand you, but your problem is that you are defining and initializing the variable MyItem in the function.

And than trying to access MyItem from some other mod related class but you can't because it doesn't see it?

 

If that is so, your mistake was putting definition of the MyItem inside function.

All that is inside function, stays inside.

You have to define the variable outside the function boundary to make it visible to other classes.

 

If you are afraid that if flag1 is false and item dosen't get created, and other classes that utilize it fail to find it and error crash on you.

Just init it with null first and than when time comes just check

 if (AwesomeMod.MyItem != null) {/*item exists.*/}

~I was here~

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.