Easy Obsidian [MOD]

Posts 31–33 of 33 · Page 3 of 3
Config file
Like this. You should catch expected exception, etc. There may be typos - haven't tried syntax checking nor compiling.

Code:
File configFile = new File(Minecraft.b(), "relative/Path/To/Ur/ConfigFile.txt");

if (configFile.exists()) return 4654; // return default value

reader = new BufferedReader(new FileReader(configFile));
String strValue = reader.readLine();
int value = Integer.parseInt(strValue);

reader.close();

return value;
Quote Originally Posted by tripirat View Post
Like this. You should catch expected exception, etc. There may be typos - haven't tried syntax checking nor compiling.

Code:
File configFile = new File(Minecraft.b(), "relative/Path/To/Ur/ConfigFile.txt");

if (configFile.exists()) return 4654; // return default value

reader = new BufferedReader(new FileReader(configFile));
String strValue = reader.readLine();
int value = Integer.parseInt(strValue);

reader.close();

return value;
Can you give us a simple example of this in use.
Config file
Quote Originally Posted by Cal View Post


Can you give us a simple example of this in use.
Seems self-explanatory to me... It's pretty simple.

Put the code from my post into a static method like this:
Code:
public class mod_MyMod extends BaseMod
{
  private static final int myConfiguredValue = getConfiguredValue();

  private static int getConfiguredValue() { /*the code*/ }

  // Now in your code you can work with myConfiguredValue as with
  // any other field... That's up to you.
}
For Tom's case, he would name myConfiguredValue as obsidianCount and use it when spawning items. You can also publish the value so you can read from external classes (using an accessor method).

Making it static will make ensure you only read the file once per application domain => it does not lower runtime performance for larger files. Also, it will get loaded either on start (when using mod loader) or on first use (when uninitialized).

It is of course a simple - one value config, you can read anything from the file. Like serializing a key-value pair collection, etc.

If you are still not sure how to do this, you should read some tutorials about java and modding. It should only take a couple of minutes to get started.
Posts 31–33 of 33 · Page 3 of 3
This thread is closed for replies.

Tags for this Thread

None

Talk with us