I'm working on adding it so you can specify an array of keys and defaults and it will return an array of those values. And if anyone wants another conversion part put in just tell me. I didn't add all of them just the ones i thought would be used. Any explanations needed just ask.
Just rewrote a few things in the OP about how the array-based parameters and methods work. I misunderstood the explanation a bit at first. They should be more accurate now.
Of course, I haven't tried them for myself, so I could still be wrong. :tongue.gif:
1. Try to make it a habit to use the argu capability. It was added to help prevent input errors, and is very useful for just that. 2. Multiple files can be created by one class, and multiple classes can use the same file. 3. This utility may seem like a lot of work to a beginner modder, but compared to manually running its capabilities into each mod can be tricky and complicated. PropertyReader is intended to make things standardized, and therefore simple and easy for the modder. Much of its usage involves copy and paste, and continued usage makes it second nature, much like utilizing ModLoader or ToolUtils. 4. Never be afraid to ask for help. The creator and I are both friendly and would be glad to answer any questions you have. Just post on the thread or pm either one of us and we'll get back to you as soon as possible. 5. PropertyReader is, although no longer listed as such, still largely a work in progress. We are constantly looking to find ways to improve it, and add extra functionality (most of the time, it's me, the constant user, telling him what it would need -- very rarely do I actually code anything for it myself :tongue.gif: ). Most of the time you shouldn't have to change anything you've already written, except for when optimizing or simplifying.
Because Block/Item IDs are simply ints, recalling them from a properties file via PropertyReader is very simple. There are two methods supplied that you can use in this situation:
public static int PReader.PropInt(String[] argu, String path, String key, String def)
public static int[] PReader.PropInt(String[] argu, String path, String key[], String def[]
You could stop with just those methods, but the reason I pulled the two int methods that use argu is because there are plenty of cases where a user input could be highly invalid, such as a negative or decimal number or a block ID (0-255) for an item. Because of this reason, it is always a good idea to establish an argument to prevent as many user errors as possible. To create the argument arrays I use for blocks and items (separately, as they have different ID ranges), I use the following code:
public static String[] ArgIDItem()
{
String[] SubArgIDItem = new String['È'];
try {
for (int i = 0; i < 25000; i++) {
int n = i + 256;
String f = Integer.toString(n);
SubArgIDItem[i] = f;
}
}
catch (Exception e) {
System.out.println(e);
}
return SubArgIDItem;
}
public static String[] ArgIDItem = ArgIDItem();
public static String[] ArgIDBlock()
{
String[] SubArgIDBlock = new String['È'];
try {
for (int i = 0; i < 256; i++) {
int n = i + 0;
String f = Integer.toString(n);
SubArgIDBlock[i] = f;
}
}
catch (Exception e) {
System.out.println(e);
}
return SubArgIDBlock;
}
public static String[] ArgIDBlock = ArgIDBlock();
As you can see, we establish that the int i must be less than our declared number (25000 or another very high number for items and 256 for blocks). Since i starts at 0, n, which is defined to be i + 0/256, starts at 0 for blocks and 256 for items. That leaves our range to be, created from the valid values of n, is from 0 to 255 for blocks and 256 to 25256 for items (25256 because n is i + 256 and the max for i is 25000). This outputs the range of values as an array of strings called ArgItem() or ArgBlock(), accordingly. Next, we simply added two lines of code that allow us to reference these strings with the variables ArgItem and ArgBlock without the parentheses.
This completes the first of four parameters for our method. The second one, path, is very simple, and is explained earlier to be the filename and path of the file where the values are to be retrieved from. See the example below if you're confused what this means.
That leaves the last two parameters, key and def. Use of arrays for these is optional, and arrays of IDs can only really serve as organizational methods. You can use arrays to split items from blocks, split parts of your mod (Shockah could use it to split each of his modules and assign them to their own array), or whatever else you think of. I typically call for arrays to split items and blocks when I have at least 5 to call.
To define your key and def, you can start by declaring arrays of strings first, or if you want to call for single strings, you can insert them directly into the method. In my example mod, I call for single strings, so I'll cover arrays here.
Of course, if you have more than one array, you'll want to change the names to that they weren't the same (such as Key1, KeyA, KeyItem, etc.).
Anyway, here we start by declaring Key() to retrieve the values of key, which we define as an array of 9 strings, then proceed to define each one by one. Then we add a line to allow Key() to be referenced with just Key. Then we do the same with Def()/def/Def, making sure to correspond the two correctly. Once we have those set, we can now use them when we later declare our objects:
public static final Block porkchopBlockRaw = (new Block(idBlock[0], index1, Material.cloth)).setHardness(0.75F).func_20012_a("Block of Raw Porkchops");
public static final Block porkchopBlockCooked = (new Block(idBlock[1], index2, Material.cloth)).setHardness(0.75F).func_20012_a("Block of Cooked Porkchops");
public static final Block fishBlockRaw = (new Block(idBlock[2], index3, Material.cloth)).setHardness(0.75F).func_20012_a("Block of Raw Fish");
public static final Block fishBlockCooked = (new Block(idBlock[3], index4, Material.cloth)).setHardness(0.75F).func_20012_a("Block of Cooked Fish");
public static final Block wheatBlock = (new Block(idBlock[4], index5, Material.cloth)).setHardness(0.75F).func_20012_a("Block of Wheat");
public static final Block breadBlock = (new Block(idBlock[5], index6, Material.cloth)).setHardness(0.75F).func_20012_a("Block of Bread");
public static final Block appleBlock = (new Block(idBlock[6], index7, Material.cloth)).setHardness(0.75F).func_20012_a("Block of Apples");
public static final Block appleBlockGolden = (new Block(idBlock[7], index8, Material.cloth)).setHardness(0.75F).func_20012_a("Block of Golden Apples");
public static final Block eggBlock = (new Block(idBlock[8], index9, Material.cloth)).setHardness(0.75F).func_20012_a("Block of Eggs");
Where you would typically tell it what ID to use, you instead tell it to find that item in the array. It will then check the specified property file for the value. If no property file exists, it will create one with your defined default values.
Congratulations. You are done.
Example
In case you got confused, here is a complete example in a ModLoader mod_ file. It is actually the source code for my LavaBoat mod.
package net.minecraft.src;
import java.util.Map;
public class mod_LavaBoat extends BaseMod
{
public static String[] ArgIDItem()
{
String[] SubArgIDItem = new String['È'];
try {
for (int i = 0; i < 25000; i++) {
int n = i + 256;
String f = Integer.toString(n);
SubArgIDItem[i] = f;
}
}
catch (Exception e) {
System.out.println(e);
}
return SubArgIDItem;
}
public static String[] ArgIDItem = ArgIDItem();
public static int idItem = PReader.PropInt(ArgIDItem, "/mods/Roundaround/Block_and_Item_IDs.properties", "LavaBoat_LavaBoat", "4078");
public static int idOffset = 256;
public static String[] ArgIDBlock()
{
String[] SubArgIDBlock = new String['È'];
try {
for (int i = 0; i < 256; i++) {
int n = i + 0;
String f = Integer.toString(n);
SubArgIDBlock[i] = f;
}
}
catch (Exception e) {
System.out.println(e);
}
return SubArgIDBlock;
}
public static String[] ArgIDBlock = ArgIDBlock();
public static int idBlock = PReader.PropInt(ArgIDBlock, "/mods/Roundaround/Block_and_Item_IDs.properties", "LavaBoat_DenseStone", "199");
public static int index1 = ModLoader.addOverride("/gui/items.png", "/Roundaround's Mods/lavaBoat.png");
public static int index2 = ModLoader.addOverride("/terrain.png", "/Roundaround's Mods/stoneDense.png");
public static Item lavaBoat = new ItemLavaBoat(idItem - idOffset).setIconIndex(index1).func_20011_a("Lava Boat");
public static Block stoneDense = new Block(idBlock, index2, Material.rock).setHardness(6F).setResistance(100F).setStepSound(Block.soundStoneFootstep).func_20012_a("stoneDense");
public mod_LavaBoat()
{
ModLoader.AddName(lavaBoat, "Lava Boat");
ModLoader.RegisterEntityID(EntityLavaBoat.class, "Lava Boat", ModLoader.getUniqueEntityId());
ModLoader.AddName(stoneDense, "Dense Stone");
ModLoader.RegisterBlock(stoneDense);
ToolUtils.registerBlocks(ToolUtils.Type.PICKAXE, new Block[] { stoneDense });
}
public String Version()
{
return "v2.10 for Beta 1.2_02";
}
public void AddRecipes(CraftingManager craftingmanager)
{
craftingmanager.addRecipe(new ItemStack(lavaBoat, 1), new Object[] {
"# #", "###", Character.valueOf('#'), stoneDense
});
ModLoader.AddSmelting(Block.stone.blockID, new ItemStack(stoneDense));
}
public void AddRenderer(Map map)
{
map.put(EntityLavaBoat.class, new RenderLavaBoat());
}
}
Its allows comments now. Use the same methods as before but just add an array of strings or just a string to the end and it will put the comment below the property. It will only put the comment if the property doesn't exist in the file though so existing ones won't be commented. If you have any questions or if you need examples just ask.
Its allows comments now. Use the same methods as before but just add an array of strings or just a string to the end and it will put the comment below the property. It will only put the comment if the property doesn't exist in the file though so existing ones won't be commented. If you have any questions or if you need examples just ask.
Source code is also provided in the download
Be reminded this is a pre release version. Its not been tested very much. If your getting alot of nullpointer exceptions try downloading again it should fix those. It also has a logger method in it.
To use the logger you first need to get an ID. Use
PReader.GetSessionID(String path)
It will return an int that will be your session id for all logs. To actually log use
Not all levels are added yet but will be shortly. If you want the default level use
PReader.logger(int session, String message)
If you have any questions with anything feel free to ask. And if you get any errors relating to this please tell me because i'm very sure i've missed some.
When I try to download it (from here or modcenter) it says 'decompression failed' and something about not being a valid download.
It it means anything, I'm using mac. Any ideas?
Thanks!
Rollback Post to RevisionRollBack
Quote from A wise man once »
Religion is like a penis. It's ok to have one, and it's ok to be proud of it. But don't go waving it around in public, and don't try to shove it down kids' throats.
Quote from He also »
Ambition is a poor excuse for not having enough sense to be lazy.
https://modrinth.com/user/Roundaround
-Titles
-Comments
-Formatting
-Obfuscation Converter (Perhaps as a separate piece.)
Examples and Tutorials
Notes and Tips for Using PropertyReader
Using PropertyReader to Establish Customizable Block/Item IDs
https://modrinth.com/user/Roundaround
I'll get you next time, Gadget! Next time!!!!!
Edit: And I was going to extend my manager to do most of the stuff you did. Oh well...
Edit 2: Oh and Nice job. :smile.gif:
https://modrinth.com/user/Roundaround
https://modrinth.com/user/Roundaround
Of course, I haven't tried them for myself, so I could still be wrong. :tongue.gif:
https://modrinth.com/user/Roundaround
2. Multiple files can be created by one class, and multiple classes can use the same file.
3. This utility may seem like a lot of work to a beginner modder, but compared to manually running its capabilities into each mod can be tricky and complicated. PropertyReader is intended to make things standardized, and therefore simple and easy for the modder. Much of its usage involves copy and paste, and continued usage makes it second nature, much like utilizing ModLoader or ToolUtils.
4. Never be afraid to ask for help. The creator and I are both friendly and would be glad to answer any questions you have. Just post on the thread or pm either one of us and we'll get back to you as soon as possible.
5. PropertyReader is, although no longer listed as such, still largely a work in progress. We are constantly looking to find ways to improve it, and add extra functionality (most of the time, it's me, the constant user, telling him what it would need -- very rarely do I actually code anything for it myself :tongue.gif: ). Most of the time you shouldn't have to change anything you've already written, except for when optimizing or simplifying.
https://modrinth.com/user/Roundaround
Especially since my implementation of this apparently didn't work, even though it theoretically should have.
You could stop with just those methods, but the reason I pulled the two int methods that use argu is because there are plenty of cases where a user input could be highly invalid, such as a negative or decimal number or a block ID (0-255) for an item. Because of this reason, it is always a good idea to establish an argument to prevent as many user errors as possible. To create the argument arrays I use for blocks and items (separately, as they have different ID ranges), I use the following code:
As you can see, we establish that the int i must be less than our declared number (25000 or another very high number for items and 256 for blocks). Since i starts at 0, n, which is defined to be i + 0/256, starts at 0 for blocks and 256 for items. That leaves our range to be, created from the valid values of n, is from 0 to 255 for blocks and 256 to 25256 for items (25256 because n is i + 256 and the max for i is 25000). This outputs the range of values as an array of strings called ArgItem() or ArgBlock(), accordingly. Next, we simply added two lines of code that allow us to reference these strings with the variables ArgItem and ArgBlock without the parentheses.
This completes the first of four parameters for our method. The second one, path, is very simple, and is explained earlier to be the filename and path of the file where the values are to be retrieved from. See the example below if you're confused what this means.
That leaves the last two parameters, key and def. Use of arrays for these is optional, and arrays of IDs can only really serve as organizational methods. You can use arrays to split items from blocks, split parts of your mod (Shockah could use it to split each of his modules and assign them to their own array), or whatever else you think of. I typically call for arrays to split items and blocks when I have at least 5 to call.
To define your key and def, you can start by declaring arrays of strings first, or if you want to call for single strings, you can insert them directly into the method. In my example mod, I call for single strings, so I'll cover arrays here.
From my FoodBlocks mod:
Of course, if you have more than one array, you'll want to change the names to that they weren't the same (such as Key1, KeyA, KeyItem, etc.).
Anyway, here we start by declaring Key() to retrieve the values of key, which we define as an array of 9 strings, then proceed to define each one by one. Then we add a line to allow Key() to be referenced with just Key. Then we do the same with Def()/def/Def, making sure to correspond the two correctly. Once we have those set, we can now use them when we later declare our objects:
Where you would typically tell it what ID to use, you instead tell it to find that item in the array. It will then check the specified property file for the value. If no property file exists, it will create one with your defined default values.
Congratulations. You are done.
Example
In case you got confused, here is a complete example in a ModLoader mod_ file. It is actually the source code for my LavaBoat mod.
https://modrinth.com/user/Roundaround
http://dl.dropbox.com/u/19977649/PReader.zip
Its allows comments now. Use the same methods as before but just add an array of strings or just a string to the end and it will put the comment below the property. It will only put the comment if the property doesn't exist in the file though so existing ones won't be commented. If you have any questions or if you need examples just ask.
Source code is also provided in the download
Be reminded this is a pre release version. Its not been tested very much. If your getting alot of nullpointer exceptions try downloading again it should fix those. It also has a logger method in it.
To use the logger you first need to get an ID. Use
PReader.GetSessionID(String path)
It will return an int that will be your session id for all logs. To actually log use
PReader.logger(int session, String level, String message)
Not all levels are added yet but will be shortly. If you want the default level use
PReader.logger(int session, String message)
If you have any questions with anything feel free to ask. And if you get any errors relating to this please tell me because i'm very sure i've missed some.
It it means anything, I'm using mac. Any ideas?
Thanks!
https://modrinth.com/user/Roundaround
Same place you install any other mod. In minecraft.jar