Jump to content

Recommended Posts

Posted

Hello, I've used Helfull's tutorial on Properties files but my blocks always return a value of 0.

 

This is my PropertyManager class:

 

 

 


package cococraft.common;

import java.io.File;
import java.io.IOException;

import net.minecraft.client.Minecraft;
import net.minecraftforge.common.Configuration;

public class PropertyManager 
{

public static  Configuration config;

public static int CocoStoneID;
public static int MithrilOreID;
public static int SilverOreID;
public static int AmethystOreID;

public static int AmethystID;
public static int CocoIngotID;
public static int MithrilIngotID;
public static int SilverIngotID;

public static int CocoPickaxeID;
public static int CocoAxeID;
public static int CocoShovelID;
public static int CocoSwordID;
public static int CocoHoeID;

public static int MithrilPickaxeID;
public static int MithrilAxeID;
public static int MithrilShovelID;
public static int MithrilSwordID;
public static int MithrilHoeID;

public static int SilverPickaxeID;
public static int SilverAxeID;
public static int SilverShovelID;
public static int SilverSwordID;
public static int SilverHoeID;

public static int AmethystPickaxeID;
public static int AmethystAxeID;
public static int AmethystShovelID;
public static int AmethystSwordID;
public static int AmethystHoeID;


public static void initProps(String mod)
{
	File file = new File(Minecraft.getMinecraftDir() + "config/" + mod);
	file.mkdir();

	File newFile = new File(Minecraft.getMinecraftDir() + "/config" + mod + "/CocoCraft2.cfg");

	try
	{
		newFile.createNewFile();
		System.out.println("Created Properties File!");
	}
	catch(IOException exception)
	{
		System.out.println("Couldn't create properties file ");
		System.out.println(exception);
	}
	config =  new Configuration(newFile);

	config.load();

	CocoStoneID = config.getOrCreateBlockIdProperty("CocoStoneID", 180).getInt(180);
	MithrilOreID = config.getOrCreateBlockIdProperty("MithrilOreID", 181).getInt(181);
	SilverOreID = config.getOrCreateBlockIdProperty("SilverOreID", 182).getInt(182);
	AmethystOreID = config.getOrCreateBlockIdProperty("AmethystOreID", 183).getInt(183);

	CocoIngotID = config.getOrCreateIntProperty("CocoIngotID", "item", 15000).getInt(15000);
	MithrilIngotID = config.getOrCreateIntProperty("MithrilIngotID", "item", 15001).getInt(15001);
	SilverIngotID = config.getOrCreateIntProperty("SilverIngotID", "item", 15002).getInt(15002);
	AmethystID = config.getOrCreateIntProperty("AmethystGemID", "item", 15003).getInt(15003);

	CocoPickaxeID = config.getOrCreateIntProperty("CocoPickaxeID", "item", 15004).getInt(15004);
	CocoAxeID = config.getOrCreateIntProperty("CocoAxeID", "item", 15005).getInt(15005);
	CocoShovelID = config.getOrCreateIntProperty("CocoShovelID", "item", 15006).getInt(15006);
	CocoSwordID = config.getOrCreateIntProperty("CocoSwordID", "item", 15007).getInt(15007);
	CocoHoeID = config.getOrCreateIntProperty("CocoHoeID", "item", 15008).getInt(15008);

	MithrilPickaxeID = config.getOrCreateIntProperty("MithrilPickaxeID", "item", 15009).getInt(15009);
	MithrilAxeID = config.getOrCreateIntProperty("MithrilAxeID", "item", 15010).getInt(15010);
	MithrilShovelID = config.getOrCreateIntProperty("MithrilShovelID", "item", 15011).getInt(15011);
	MithrilSwordID = config.getOrCreateIntProperty("MithrilSwordID", "item", 15012).getInt(15012);
	MithrilHoeID = config.getOrCreateIntProperty("MithrilHoeID", "item", 15013).getInt(15013);

	SilverPickaxeID = config.getOrCreateIntProperty("SilverPickaxeID", "item", 15014).getInt(15014);
	SilverAxeID = config.getOrCreateIntProperty("SilverAxeID", "item", 15015).getInt(15015);
	SilverShovelID = config.getOrCreateIntProperty("SilverShovelID", "item", 15016).getInt(15016);
	SilverSwordID = config.getOrCreateIntProperty("SilverSwordID", "item", 15017).getInt(15017);
	SilverHoeID = config.getOrCreateIntProperty("SilverHoeID", "item", 15018).getInt(15018);

	AmethystPickaxeID = config.getOrCreateIntProperty("AmethystPickaxeID", "item", 15019).getInt(15019);
	AmethystAxeID = config.getOrCreateIntProperty("AmethystAxeID", "item", 15020).getInt(15020);
	AmethystShovelID = config.getOrCreateIntProperty("AmethystShovelID", "item", 15021).getInt(15021);
	AmethystSwordID = config.getOrCreateIntProperty("AmethystSwordID", "item", 15022).getInt(15022);
	AmethystHoeID = config.getOrCreateIntProperty("AmethystHoeID", "item", 15023).getInt(15023);

	config.save();
}
}

 

 

 

And this is my block declaration:

 

public static final Block CocoStone = (new ModBlockOre(pm.CocoStoneID, 0)).setBlockName("CocoStone").setResistance(2F).setHardness(2F);
public static final Block MithrilOre = (new ModBlockOre(pm.MithrilOreID, 1)).setBlockName("MithrilORe").setResistance(2F).setHardness(2F);
public static final Block SilverOre = (new ModBlockOre(pm.SilverOreID, 2)).setBlockName("SilverOre").setResistance(2F).setHardness(2F);
public static final Block AmethystOre = (new ModBlockOre(pm.AmethystOreID, 3)).setBlockName("Amethyst").setResistance(2F).setHardness(2F);

 

FYI pm is PropertyManager

 

Thanks in advance.

Posted

this is the way i do my configs

 

@PreInit
public void initConfig(FMLPreInitializationEvent evt) {
	evt.getModMetadata().version = Resources.version;
	Configuration cfg = new Configuration(new File(Loader.instance().getConfigDir() + "/Viper283/CvC/config.cfg"));
	try {
		cfg.load();
		debugText = cfg.getOrCreateBooleanProperty("Debug Text", cfg.CATEGORY_GENERAL, true).getBoolean(true);
	} catch(Exception e) {
		System.out.println(logger + "Failed to load config for reason: ");
		e.printStackTrace();
	} finally {
		cfg.save();
	}


}

 

FYI logger is "[CvC]: "

also this is in my mod file

Posted

So.. you're trying to use your config values BEFORE you load them?

You're a smart one....

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

Get the config files *then* use them.  How else?  ;)

 

I understood that part, but if this tries to use the config files before they're created, how does Helfull's configs work? This is the exact same way.

Posted

No offense to the author, but I wouldn't take a tutorial on writing a property file written by someone who can't write 'property' correct too serious ;).

 

Take a look at the advanced config tutorial on the wiki (http://www.minecraftforge.net/wiki/How_to_make_an_advanced_configuration_file). While it is 'technically' out of date, it still works fine for 1.3.2.

 

Thanks! But I also would like to have it in another class, so my mod file's smaller.

Posted

Call the property reading first (in your @PreInit method) and THEN initialise your blocks / items / other things using configurations (in your @Init method)

Have you tried that?

Posted

Thanks! But I also would like to have it in another class, so my mod file's smaller.

 

Sure go ahead and place it anywhere you like. The config system is nothing more than a File and a Configuration object, place them anywhere you like.

 

Note though that it is in no way needed though to keep a separate variable for each block/item id. In fact I personally find it very redundant to do so.

I personally like to just call config.getOrCreateBlockIdProperty directly when initialising the blocks. I also dislike personally setting the id for each entry. I just have one nextBlockID variable which I give a starting value and then just increment with each block call.

 

But again the only thing you have to do is initialize the File and Configuration objects, then create your objects and finally not forget to save the config to disc. How and where you do this is all up to personal preference :)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.