Posted April 22, 201411 yr 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!
April 22, 201411 yr 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.
April 22, 201411 yr Author Yes, but I can't access the item from other classes because it can't be public
April 22, 201411 yr Make it public static then. If i helped you, don't forget pressing "Thank You" button. Thanks for your time.
April 22, 201411 yr 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.