June 7, 201510 yr Do you know that you can Configuration.class??? Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
June 7, 201510 yr Author Do you know that you can Configuration.class??? *Facepalm* Thanks for that tip.. I didn't realize that before. Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 7, 201510 yr Do you know that you can Configuration.class??? *Facepalm* Thanks for that tip.. I didn't realize that before. And also, i don't reccomend defining these as fields in class. Probably just in method... Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
June 7, 201510 yr Author I think that was the problem and question, eclipse is now saying about the field the category String in the method mismatching (cannot convert from Object to ModConfigCategory). How should I have the fields as to solve this? Here is my code package common.zeroquest.core.configuration; import java.io.File; import java.lang.reflect.Field; import java.util.Map; import java.util.TreeMap; import net.minecraftforge.common.config.Configuration; public class ModConfiguration extends Configuration { public ModConfiguration() {} /** * Create a configuration file for the file given in parameter. */ public ModConfiguration(File file) { super(file); } @Override public ModConfigCategory getCategory(String category) { Class c = Class.forName(Configuration.class.toString()); Field field1 = c.getDeclaredField("categories"); Field field2 = c.getDeclaredField("changed"); field1.setAccessible(true); field2.setAccessible(true); ModConfigCategory ret = field1.get(category); <<Error here if (ret == null) { if (category.contains(CATEGORY_SPLITTER)) { String[] hierarchy = category.split("\\" + CATEGORY_SPLITTER); ModConfigCategory parent = categories.get(hierarchy[0]); if (parent == null) { parent = new ModConfigCategory(hierarchy[0]); categories.put(parent.getQualifiedName(), parent); changed = true; } for (int i = 1; i < hierarchy.length; i++) { String name = ModConfigCategory.getQualifiedName(hierarchy[i], parent); ModConfigCategory child = categories.get(name); if (child == null) { child = new ModConfigCategory(hierarchy[i], parent); categories.put(name, child); changed = true; } ret = child; parent = child; } } else { ret = new ModConfigCategory(category); categories.put(category, ret); changed = true; } } return ret; } } Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 8, 201510 yr ... ModConfigCategory ret = field1.get(category); In this you are getting a field of ModConfigCategory from String! I think it should be field1.get(this). Also what that will give you is instance of ConfigCategory, not your own class 'ModConfigCategory'. + Why are you using reflection in this case? You can just make another class copying that, and change some behaviors you want there. Configuration class is not intended to be inherited, so in this case this way is better. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
June 8, 201510 yr Author I started on this but now I'm getting an error from all of the reflection methods. They say to put a try and catch method in package common.zeroquest.core.configuration; import java.io.File; import java.lang.reflect.Field; import java.util.Map; import java.util.TreeMap; import net.minecraftforge.common.config.Configuration; public class ModConfiguration extends Configuration { public ModConfiguration() {} /** * Create a configuration file for the file given in parameter. */ public ModConfiguration(File file) { super(file); } @Override public ModConfigCategory getCategory(String category) { Class c = Class.forName(Configuration.class.toString()); Field field1 = c.getDeclaredField("categories"); Field field2 = c.getDeclaredField("changed"); Object a = field1.get(this); Object b = field2.get(this); field1.setAccessible(true); field2.setAccessible(true); ModConfigCategory ret = (ModConfigCategory) field1.get(this); if (ret == null) { if (category.contains(CATEGORY_SPLITTER)) { String[] hierarchy = category.split("\\" + CATEGORY_SPLITTER); ModConfigCategory parent = (ModConfigCategory)field1.get(hierarchy[0]); if (parent == null) { parent = new ModConfigCategory(hierarchy[0]); field1.set(parent.getQualifiedName(), parent); field2.setBoolean(b, true); } for (int i = 1; i < hierarchy.length; i++) { String name = ModConfigCategory.getQualifiedName(hierarchy[i], parent); ModConfigCategory child = (ModConfigCategory) field1.get(name); if (child == null) { child = new ModConfigCategory(hierarchy[i], parent); field1.set(name, child); field2.setBoolean(b, true); } ret = child; parent = child; } } else { ret = new ModConfigCategory(category); field1.set(category, ret); field2.setBoolean(b, true); } } return ret; } } Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 8, 201510 yr That is natural, because reflection can sometimes throw exceptions like NoSuchFieldException. Besides, I think you should not use reflection in this case.. You can sort the order of properties using Configuration#setCategoryPropertyOrder. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
June 8, 201510 yr Author Oh? So do I not override getCategory? And does this mean I do not need the ModConfigCategory class? Also, I try to override setCategoryPropertyOrder, there's a boolean that is private. How do I get it? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 8, 201510 yr Oh? So do I not override getCategory? And does this mean I do not need the ModConfigCategory class? Also, I try to override setCategoryPropertyOrder, there's a boolean that is private. How do I get it? No, you can just use Configuration class. Your custom class is not needed. You call Configuration#setCategoryPropertyOrder when you want. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
June 8, 201510 yr Author Question, now that I have the method overriden, how do I arrange it to where it calls the methods like I want them called? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 8, 201510 yr Question, now that I have the method overriden, how do I arrange it to where it calls the methods like I want them called? No. In this way you should not make your own class. You should just use Configuration class. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
June 8, 201510 yr Author Then how am I suppose to change the sorting of the properties? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 8, 201510 yr Then how am I suppose to change the sorting of the properties? When did you need the sorting? It depends. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
June 8, 201510 yr Author When the configuration file is being created for the first time, like how the game does it Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 8, 201510 yr I think you can get the value of the properties. Sort it with the name of the properties. Then provide the List<String> of the sorted order of the name of the properties to the method. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
June 8, 201510 yr Author How do I do that if I'm not using a custom class? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 8, 201510 yr ... After you registers the properties you want to sort. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
June 8, 201510 yr Author I know, but how? There isn't exactly a method that allows to manually sort them Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 8, 201510 yr I know, but how? There isn't exactly a method that allows to manually sort them . Do it yourself. You should be able to write that logic. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
June 8, 201510 yr Author I don't know how.. thats why I'm asking. I've tried renaming and tried overriding the methods that would sort it and it didn't work Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 8, 201510 yr I don't know how.. thats why I'm asking. I've tried renaming and tried overriding the methods that would sort it and it didn't work I said, don't override the method, and just use Configuration class. I think you can get the properties as Collection. Then you can sort it with your custom comparator using Collections#sort(List, Comparator). The comparator should compare the properties with the value. From the sorted list, build another list of List<String> containing the name of properties. Then you can provide the list to the Configuration#setCategoryPropertyOrder(..) I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
June 8, 201510 yr Author Oh.. so basically, I get the names of the properties, then order then the way I want and set them as the propOrder? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 8, 201510 yr Author Yes! That worked! Thanks for the help! Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 8, 201510 yr Author Oh, one last question, is it possible for me put the mod's version and the config version inside the configuration file? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
June 8, 201510 yr Oh, one last question, is it possible for me put the mod's version and the config version inside the configuration file? Where would you put them? I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
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.