Jump to content

Configuration File is not generating


DealerJoe

Recommended Posts

Hi, it´s DealerJoe again!  ::)

 

Okay guys, got a new problem. I´ve been looking around in other mod´s source for about 2 hours now, but I couldn´t

figure out what I´m doing wrong.

Now my Problem : I want to generate a config file, so I created a method called loadConfiguration, put @PreInit above and added the event. Then I created the variables for the id´s of items and blocks.

 

Here my Source :

 

@PreInit
public void loadConfiguration(FMLPreInitializationEvent evt) {
	Configuration config = new Configuration(new File(evt.getModConfigurationDirectory(),  "FarmersFriends.cfg"));
	config.load();

	blockChopperID = config.getOrCreateIntProperty("blockChopperID", Configuration.CATEGORY_BLOCK, 250).getInt();
	blockToasterID = config.getOrCreateIntProperty("blockToasterID", Configuration.CATEGORY_BLOCK, 251).getInt();

	chopperID = config.getOrCreateIntProperty("itemChopperID", Configuration.CATEGORY_ITEM, 5000).getInt();
	sawmealID = config.getOrCreateIntProperty("sawmealID", Configuration.CATEGORY_ITEM, 5001).getInt();
	scytheID = config.getOrCreateIntProperty("scytheID", Configuration.CATEGORY_ITEM, 5002).getInt();
	scytheBloodyID = config.getOrCreateIntProperty("bloodyScytheID", Configuration.CATEGORY_ITEM, 5003).getInt();
	toasterID = config.getOrCreateIntProperty("itemToasterID", Configuration.CATEGORY_ITEM, 5004).getInt();

	config.save();
}

 

I don´t now whats wrong with it. If you guys miss some parts of the src, I´m gonna post it.

Hope you can help me.

 

DealerJoe

Link to comment
Share on other sites

Try using new File(Minecraft.getMinecraftDir(), "config/FarmersFriends.cfg")

Should work, byt don't use @preinit more than once in the mod class.

Read the EAQ before posting! OR ELSE!

 

This isn't building better software, its trying to grab a place in the commit list of a highly visible github project.

 

www.forgeessentials.com

 

Don't PM me, I don't check this account unless I have to.

Link to comment
Share on other sites

Try using new File(Minecraft.getMinecraftDir(), "config/FarmersFriends.cfg")

Should work, byt don't use @preinit more than once in the mod class.

 

I cant do that because Minecraft.getMinecraftDir() doesn´t work on servers and this is an SMP mod, so thats not working.

And what do you mean with

 

don't use @preinit more than once in the mod class.

 

This is the only method I´m using this Flag.

 

Any other Idea ?

Link to comment
Share on other sites

Step through it, see where it fails, it should attempt to create the file if it doesnt exist.

If it cant do that for some reason it'll exit earily, so, you should look into it.

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

Link to comment
Share on other sites

Step through it, see where it fails, it should attempt to create the file if it doesnt exist.

If it cant do that for some reason it'll exit earily, so, you should look into it.

 

Okay, I did so.

When I set the breakpoint to the beginning of the loadConfiguration-Method, I noticed, that it´s not even called.

Do you know why or how I can fix it ?

 

DealerJoe

Link to comment
Share on other sites

My mod Class

 

package farmersfriends.common;

import java.io.File;

import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid="FarmersFriends", name="FarmersFriends", version="1.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)

public class mod_farmersfriends {

/** IDS **/

public static int blockChopperID;
public static int blockToasterID;

public static int chopperID;
public static int sawmealID;
public static int scytheID;
public static int scytheBloodyID;
public static int toasterID;

/** BLOCKS AND ITEMS **/

public static final Block blockChopper = (new BlockChopper(blockChopperID, TileEntityChopper.class)).setHardness(0.5F).setBlockName("chopperBlock");
public static final Block blockToaster = (new BlockToaster(blockToasterID, TileEntityToaster.class)).setHardness(0.5F).setBlockName("toasterBlock");

public static final Item chopper = (new ItemChopper(chopperID, blockChopper).setItemName("chopper").setIconIndex(0));
public static final Item sawmeal = (new ItemSawmeal(sawmealID).setItemName("sawmeal").setIconIndex(1));
public static final Item farmersScythe = (new ItemScythe(scytheID).setItemName("farmersScythe").setIconIndex(2));
public static final Item farmersScytheBloody = (new ItemScythe(scytheBloodyID).setItemName("farmersScytheBloody").setIconIndex(3));
public static final Item toaster = (new ItemToaster(toasterID, blockToaster).setItemName("toaster").setIconIndex(4));


@SidedProxy(clientSide = "farmersfriends.client.ClientProxyFm", serverSide = "farmersfriends.common.CommonProxyFm")
public static CommonProxyFm proxy;	


@PreInit
public void loadConfiguration(FMLPreInitializationEvent evt) {
	Configuration config = new Configuration(new File(evt.getModConfigurationDirectory(),  "FarmersFriends.cfg"));
	config.load();

	blockChopperID = config.getOrCreateIntProperty("blockChopperID", Configuration.CATEGORY_BLOCK, 250).getInt();
	blockToasterID = config.getOrCreateIntProperty("blockToasterID", Configuration.CATEGORY_BLOCK, 251).getInt();

	chopperID = config.getOrCreateIntProperty("itemChopperID", Configuration.CATEGORY_ITEM, 5000).getInt();
	sawmealID = config.getOrCreateIntProperty("sawmealID", Configuration.CATEGORY_ITEM, 5001).getInt();
	scytheID = config.getOrCreateIntProperty("scytheID", Configuration.CATEGORY_ITEM, 5002).getInt();
	scytheBloodyID = config.getOrCreateIntProperty("bloodyScytheID", Configuration.CATEGORY_ITEM, 5003).getInt();
	toasterID = config.getOrCreateIntProperty("itemToasterID", Configuration.CATEGORY_ITEM, 5004).getInt();

	config.save();
}


@Init
public void load(FMLInitializationEvent e){
	GameRegistry.registerFuelHandler(new FuelHandler());

	LanguageRegistry.addName(chopper, "Chopper");
	LanguageRegistry.addName(sawmeal, "Sawmeal");
	LanguageRegistry.addName(farmersScythe, "Farmers Scythe");
	LanguageRegistry.addName(farmersScytheBloody, "Farmers Bloody Scythe");
	LanguageRegistry.addName(toaster, "Toaster");

	GameRegistry.addRecipe(new ItemStack(chopper, 1), new Object[]{
		"  S","IIW","ILR", 'S', Item.stick, 'I', Item.ingotIron, 'W', Block.wood, 'R', Item.redstone, 'L', Item.leather
	});

	proxy.registerRenderThings();
}

}

 

Log / Exception:

 

2012-10-20 13:52:35 [iNFO] [ForgeModLoader] Forge Mod Loader version 3.1.35.394 for Minecraft client:1.3.2, server:1.3.2 loading
2012-10-20 13:52:37 [iNFO] [sTDOUT] 27 achievements
2012-10-20 13:52:37 [iNFO] [sTDOUT] 195 recipes
2012-10-20 13:52:37 [iNFO] [sTDOUT] Setting user: Player405, -
2012-10-20 13:52:37 [iNFO] [sTDERR] Client asked for parameter: server
2012-10-20 13:52:37 [iNFO] [sTDOUT] LWJGL Version: 2.4.2
2012-10-20 13:52:38 [iNFO] [ForgeModLoader] Attempting early MinecraftForge initialization
2012-10-20 13:52:38 [iNFO] [sTDOUT] MinecraftForge v4.2.5.303 Initialized
2012-10-20 13:52:38 [iNFO] [ForgeModLoader] MinecraftForge v4.2.5.303 Initialized
2012-10-20 13:52:38 [iNFO] [ForgeModLoader] Completed early MinecraftForge initialization
2012-10-20 13:52:38 [iNFO] [ForgeModLoader] Searching C:\Users\Toshiba\Desktop\Forge Modding\FarmersFriends\jars\mods for mods
2012-10-20 13:52:39 [iNFO] [ForgeModLoader] Attempting to reparse the mod container bin
2012-10-20 13:52:41 [iNFO] [ForgeModLoader] Forge Mod Loader has identified 3 mods to load
2012-10-20 13:52:41 [iNFO] [sTDERR] Exception in thread "Minecraft main thread" java.lang.ExceptionInInitializerError
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at java.lang.Class.forName0(Native Method)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at java.lang.Class.forName(Unknown Source)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at cpw.mods.fml.common.FMLModContainer.constructMod(FMLModContainer.java:407)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at java.lang.reflect.Method.invoke(Unknown Source)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at com.google.common.eventbus.EventBus.post(EventBus.java:268)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:124)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at java.lang.reflect.Method.invoke(Unknown Source)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at com.google.common.eventbus.EventBus.post(EventBus.java:268)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:81)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at cpw.mods.fml.common.Loader.loadMods(Loader.java:466)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:146)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.startGame(Minecraft.java:416)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.run(Minecraft.java:748)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at java.lang.Thread.run(Unknown Source)
2012-10-20 13:52:41 [iNFO] [sTDERR] Caused by: java.lang.IllegalArgumentException: Slot 0 is already occupied by farmersfriends.common.BlockChopper@4b261b80 when adding farmersfriends.common.BlockToaster@32d7970b
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at net.minecraft.src.Block.<init>(Block.java:280)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at net.minecraft.src.BlockContainer.<init>(BlockContainer.java:7)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at farmersfriends.common.BlockToaster.<init>(BlockToaster.java:15)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	at farmersfriends.common.mod_farmersfriends.<clinit>(mod_farmersfriends.java:38)
2012-10-20 13:52:41 [iNFO] [sTDERR] 	... 28 more
2012-10-20 13:52:43 [iNFO] [sTDERR] Someone is closing me!

 

 

Thanks for your help !

Link to comment
Share on other sites

Well no shit you're getting issues, this is a vary basic issue that you shouldn't of even came here asking about.

You're STATICALLY initalizing your blocks/items, which in of itself is stupid. But beyond that, happens BEFORE your config is loaded, so you can't use your config values -.-

there are different state events for a reason.

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

Link to comment
Share on other sites

Oh Shit, you´re right.

Sorry for waisting your time  :'(, but I just didn´t see that issue. I should have had looked into the code much better.

But there is one more question, why is it stupid to add a static-modifier when initializing the blocks or items ?  :-\

 

But thank you anyway.

 

DealerJoe

Link to comment
Share on other sites

statically declaring it isnt the issue, its the initalization in the static/constructor. Obviously it happens FIRST, which is bad because you can't do things before FIRST.

 

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

Link to comment
Share on other sites

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.