Jump to content

Recommended Posts

Posted

I'm trying to create a config file, i've written this:

 

Main class

 

package SackCastellon.craftablehorsearmor.common;

import java.util.Iterator;
import java.util.List;

import SackCastellon.craftablehorsearmor.common.core.*;
import SackCastellon.craftablehorsearmor.common.item.*;
import SackCastellon.craftablehorsearmor.common.tabs.*;
import SackCastellon.craftablehorsearmor.lib.*;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.*;
import net.minecraft.item.Item;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.*;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.network.*;
import cpw.mods.fml.common.registry.*;

@Mod(modid="SKC-CraftableHorseArmor", name="Craftable Horse Armor", version="1.0.2.1")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class CraftableHorseArmor {

public static String texturePath = "craftablehorsearmor:";

    @Instance("CraftableHorseArmor")
    public static CraftableHorseArmor instance;
    
    public static final CreativeTabs tabCraftableHorseArmor = new CreativeTabCraftableHorseArmor(CreativeTabs.getNextID(), "CraftableHorseArmor");
    
    public static Item Knot = new ItemKnot(ConfigHandler.KnotID);
   
    @SidedProxy(clientSide="SackCastellon.craftablehorsearmor.client.core.ClientProxy", serverSide="SackCastellon.craftablehorsearmor.common.core.CommonProxy")
    public static CommonProxy proxy;
   
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
    	
    	ConfigHandler.init(event);
    }
   
    @EventHandler
    public void load(FMLInitializationEvent event) {
    	proxy.registerRenderers();
            
	LanguageRegistry.addName(Knot, Names.Item_Knot_name);
    }
   
    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {
    }

}

 

 

ConfigHandler class

 

package SackCastellon.craftablehorsearmor.lib;

import java.io.File;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import SackCastellon.craftablehorsearmor.common.item.ItemKnot;

import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.Property;

public class ConfigHandler {

public static int KnotID;

public static Configuration config;

public static void init(FMLPreInitializationEvent event) {
	config = new Configuration(event.getSuggestedConfigurationFile());

	config.load();

	KnotID = config.getItem("Knot ID", 10001).getInt();

	config.save();

}

}

 

But when i run minecraft (on eclipse) the console shows this:

 

2013-07-31 10:57:24 [iNFO] [sTDOUT] CONFLICT @ 0 item slot already occupied by net.minecraft.item.ItemSpade@2afda72a while adding SackCastellon.craftablehorsearmor.common.item.ItemKnot@72e9cc72
2013-07-31 10:57:24 [iNFO] [fml.ItemTracker] The mod SKC-CraftableHorseArmor is overwriting existing item at 256 (net.minecraft.item.ItemSpade from Minecraft) with SackCastellon.craftablehorsearmor.common.item.ItemKnot

 

 

And the item has the ID #256 which corresponds to the iron shovel as you can see here:

 

sc89.png

Posted

The way you do this, instance of ItemKnot is created even before your mod is loaded properly. So that means that you try to read knotID value from configHandler before it is initialized.

 

Try creating instance of ItemKnot in public void load(FMLInitializationEvent event)

method. That should help.

 

Posted

Hmmm cant find the error. Here try my configfile out^^

I know that this works.

 


package SackCastellon.craftablehorsearmor.lib;

import java.io.File;
import java.util.logging.Level;

import net.minecraftforge.common.Configuration;
import cpw.mods.fml.common.FMLLog;
/**
* 
* @author Speiger
*
*/
public class ConfigHandler 
{
public static final String general = "general";
public static final String items = "items";
public static final String blocks = "blocks";
public static Configuration config;
public static Item test;

public static void loadConfig(File par1)
{
	config = new Configuration(par1);
	try
	{
		config.load();
		test = new Item(getItem(items, "Testing", 10001));

	}
	catch(Exception e)
	{
		FMLLog.log(Level.SEVERE, e, "[Craftable Horse Armor] Could not load the Config!");
	}
	finally
	{
		Save();
	}

}

    public static int getItem(String var0, String var1, int var2)
    {
        return config.getItem(var0, var1, var2).getInt();
    }

    public static boolean getBoolean(String var0, String var1, boolean var2)
    {
        return Boolean.getBoolean(config.get(var0, var1, var2).getString());
    }

    public static int getBlock(String var0, String var1, int var2)
    {
        return config.getBlock(var0, var1, var2).getInt();
    }

public static void Save()
{
	config.save();
}



}

 

And this comes into your preInt.

 

	ConfigHandler.loadConfig(new File(par1.getModConfigurationDirectory(), "CraftableHorseArmor.cfg"));

 

i hope that helps^^

Posted

Hmmm cant find the error. Here try my configfile out^^

I know that this works.

 


package SackCastellon.craftablehorsearmor.lib;

import java.io.File;
import java.util.logging.Level;

import net.minecraftforge.common.Configuration;
import cpw.mods.fml.common.FMLLog;
/**
* 
* @author Speiger
*
*/
public class ConfigHandler 
{
public static final String general = "general";
public static final String items = "items";
public static final String blocks = "blocks";
public static Configuration config;
public static Item test;

public static void loadConfig(File par1)
{
	config = new Configuration(par1);
	try
	{
		config.load();
		test = new Item(getItem(items, "Testing", 10001));

	}
	catch(Exception e)
	{
		FMLLog.log(Level.SEVERE, e, "[Craftable Horse Armor] Could not load the Config!");
	}
	finally
	{
		Save();
	}

}

    public static int getItem(String var0, String var1, int var2)
    {
        return config.getItem(var0, var1, var2).getInt();
    }

    public static boolean getBoolean(String var0, String var1, boolean var2)
    {
        return Boolean.getBoolean(config.get(var0, var1, var2).getString());
    }

    public static int getBlock(String var0, String var1, int var2)
    {
        return config.getBlock(var0, var1, var2).getInt();
    }

public static void Save()
{
	config.save();
}



}

 

And this comes into your preInt.

 

	ConfigHandler.loadConfig(new File(par1.getModConfigurationDirectory(), "CraftableHorseArmor.cfg"));

 

i hope that helps^^

 

 

The ConfigHandler.class is ok, no errors, but when i place this code

	ConfigHandler.loadConfig(new File(par1.getModConfigurationDirectory(), "CraftableHorseArmor.cfg"));

in the PreInt the par1 is errored, how can i fix it?

 


 

EDIT: fixed i replaced par1 by event

 

In you configuration you declare the items in the config class, but i've my items declarated in another class:

 

package SackCastellon.craftablehorsearmor.lib.loader;

import cpw.mods.fml.common.registry.LanguageRegistry;
import SackCastellon.craftablehorsearmor.common.item.SKCItem;
import SackCastellon.craftablehorsearmor.common.CraftableHorseArmor;
import SackCastellon.craftablehorsearmor.lib.handler.ConfigHandler;
import net.minecraft.item.*;

public class ItemLoader {

public static Item Knot;

public static void init() {

	Knot = new SKCItem(ConfigHandler.KnotID, NameLoader.Item_Knot_unlocalizedName);

}

public static void addNames() {

        	LanguageRegistry.addName(Knot, NameLoader.Item_Knot_Name);

}

}

 

And i want to create a KnotID field to vincule the ConfigHandler.class that sets the ID and the ItemLoader.class where the items are declarated, i hope you understand me.

Posted

I do not declare the items in my config!

My classes are like this:

 

Modfile: Loads Config: (ConfigCore)

ConfigCore: Loads Items/Blocks: TinyBlocksConfig, TinyItemsConfig

TinyItems: LoadItems: TinyItems, TinyIDs

TinyBlocks: LoadBlocks: TinyBlocks, TinyIDs

xD

I and that is only the config^^"

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.