I am trying to generate a properties file for a mod I’m making for Minecraft.
The mod will rely a lot of this properties file. It should look something like this:
#Comment
#More Comment
#Even more comment explaining.
Button1=Button1 #The data after the equals they would change
Button1Command=/help
Button2=Button2
Button2Command=/rules
This would repeat for over 30 button. Here is a test code I used to generate 19 of these options in the config:
Properties p = new Properties();
try {
File configDir = new File(Minecraft.getMinecraftDir(), "/config/");
File config = new File(configDir, "FogHelperConfig.cfg");
// set the properties value
for(int c = 18;c >= 0;c--)
{
p.setProperty("Button"+c, "Button"+c);
}
// save properties minecraft config folder.
p.store(new FileOutputStream(config), null);
} catch (IOException ex) {
ex.printStackTrace();
}
}
The output for this
Button18=Button18
Button17=Button17
Button9=Button9
Button16=Button16
Button8=Button8
Button15=Button15
Button7=Button7
Button14=Button14
Button6=Button6
Button13=Button13
Button5=Button5
Button12=Button12
Button4=Button4
Button11=Button11
Button3=Button3
Button10=Button10
Button2=Button2
Button1=Button1
Button0=Button0
Of course this is a major problem when I’m dealing with something needs to be in a logical order because it has numbering. I can see this being okay if there were no numbers but in this case it MUST be in order.
I’m assuming there is something I can do or some kind of workaround to fix this issue that the Java Properties class has. I’m willing to have a properties file that I would handmake and package with the mod and just have it placed in a specific location, though I’d prefer to have it generated as it’s more user friendly.
Also another thing I would need to do is add comments to this prop file though I’m not quite sure how to.
Any different ways to do this are welcome! Whatever works!
Thanks in advance!
i used the code below to good effect. the natural sort order was good enough for me. you might have to name you buttons like “Button01”.