Jump to content

Recommended Posts

Posted

Hi,

 

I need help using configuration files for my mod. I tried the wiki article and it wasn't very detailed. I am a kind of person who learns by example. The wiki article has no examples of the finished project. I hope someone can give me an example on how to do it. Also, I tried looking at some other mods and it was no help.

 

If someone could please help me out, I would appreciate it!

Posted

A finished project is not needed though, the configuration file is literally just a couple of lines to set up and use...  What help are you needing?

 

If you really want a finished project then look at cpw's IronChests project on github.

Posted

Just check out how Universal Electricity does the getConfigID and how it sets up the config files. It's really easy to understand once you figure it out!

So, what would happen if I did push that shiny red button over there? ... Really? ... Can I try it? ... Damn.

Posted

Ok. So i looked at the iron chests code and i tryed to to that but without some of the stuff. But, It crashes with this error:

27 achievements

182 recipes

LWJGL Version: 2.8.3

Aug 08, 2012 10:55:56 AM cpw.mods.fml.common.FMLCommonHandler beginLoading

INFO: Attempting early MinecraftForge initialization

Aug 08, 2012 10:55:56 AM cpw.mods.fml.common.FMLCommonHandler beginLoading

INFO: Completed early MinecraftForge initialization

2012-08-08 10:55:56 [iNFO] Forge Mod Loader version 2.2.78.153 for Minecraft 1.2.5 loading

2012-08-08 10:55:56 [iNFO] Loading mods from C:\Users\*****\Desktop\Minecraft Stuff\mcp\jars\mods

2012-08-08 10:55:56 [iNFO] Forge Mod Loader has loaded 2 mods

WARNING: Found unknown Windows version: Windows 7

Attempting to use default windows plug-in.

Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin

java.lang.IllegalArgumentException: Illegal object for naming null

at cpw.mods.fml.client.FMLClientHandler.getObjectName(FMLClientHandler.java:783)

at cpw.mods.fml.common.FMLCommonHandler.addNameForObject(FMLCommonHandler.java:396)

at net.minecraft.src.ModLoader.addName(ModLoader.java:142)

at net.minecraft.src.ModLoader.addName(ModLoader.java:130)

at net.minecraft.src.mod_Capsules.load(mod_Capsules.java:24)

at cpw.mods.fml.common.modloader.ModLoaderModContainer.init(ModLoaderModContainer.java:351)

at cpw.mods.fml.common.Loader.modInit(Loader.java:263)

at cpw.mods.fml.common.Loader.initializeMods(Loader.java:604)

at cpw.mods.fml.client.FMLClientHandler.onLoadComplete(FMLClientHandler.java:203)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:426)

at net.minecraft.client.Minecraft.run(Minecraft.java:735)

at java.lang.Thread.run(Unknown Source)

2012-08-08 10:55:56 [sEVERE] A critical error has occurred.

java.lang.IllegalArgumentException: Illegal object for naming null

at cpw.mods.fml.client.FMLClientHandler.getObjectName(FMLClientHandler.java:783)

at cpw.mods.fml.common.FMLCommonHandler.addNameForObject(FMLCommonHandler.java:396)

at net.minecraft.src.ModLoader.addName(ModLoader.java:142)

at net.minecraft.src.ModLoader.addName(ModLoader.java:130)

at net.minecraft.src.mod_Capsules.load(mod_Capsules.java:24)

at cpw.mods.fml.common.modloader.ModLoaderModContainer.init(ModLoaderModContainer.java:351)

at cpw.mods.fml.common.Loader.modInit(Loader.java:263)

at cpw.mods.fml.common.Loader.initializeMods(Loader.java:604)

at cpw.mods.fml.client.FMLClientHandler.onLoadComplete(FMLClientHandler.java:203)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:426)

at net.minecraft.client.Minecraft.run(Minecraft.java:735)

at java.lang.Thread.run(Unknown Source)

2012-08-08 10:55:56 [sEVERE] 2 mods loaded

Minecraft Forge 3.3.8.152

FML v2.2.78.153

Forge Mod Loader version 2.2.78.153 for Minecraft 1.2.5

mod_Capsules : Pre-initialized (src)

mod_MinecraftForge : Pre-initialized (src)

 

 

can you look at my code and tell me whats wrong?

 

mod_File

 

package net.minecraft.src;

import net.minecraft.client.Minecraft;
import net.minecraft.src.forge.Configuration;
import net.minecraft.src.forge.Property;

import java.io.File;

public class mod_Capsules extends BaseMod{



public static ItemEmptyCap emptyCap;
public static ItemCapsuelEXP capEXP;
@Override
public String getVersion() {
	return "0.01 A";
}

@Override
public void load() {


	ModLoader.addName(capEXP, "EXP Capsuel");
	ModLoader.addName(emptyCap, "Empty Capsuel");
	ModLoader.addShapelessRecipe(new ItemStack(emptyCap, 64), new Object [] {Block.dirt});
	ModLoader.addShapelessRecipe(new ItemStack(capEXP, 1), new Object[] {Block.dirt, Block.dirt});

	File file = new File(Minecraft.getMinecraftDir(), "/config/Capsuels.cfg");
	Configuration cfg = new Configuration(file);
	cfg.load();
	int emptyID = cfg.getOrCreateBlockIdProperty("Empty Capsues", 500).getInt(500);
	int EXPID = cfg.getOrCreateBlockIdProperty("EXP Capsuels", 501).getInt(501); 
	emptyCap = new ItemEmptyCap(emptyID);
	capEXP = new ItemCapsuelEXP(EXPID);
	cfg.save();





	//Reg. Recipie
	ModLoader.addShapelessRecipe(new ItemStack(capEXP, 1), new Object[] {emptyCap, Item.appleGold});

}
/*
public static final Item depletedCap = (new ItemEmptyCap(emptyCapID)).setFull3D().setIconCoord(5, 15).setItemName("depletedCap");
public static final Item CapsuelEXP = (new ItemCapsuelEXP(capExpID)).setFull3D().setIconCoord(6, 15).setItemName("EXPCap");
 */

}

 

 

ItemCapsuelsEXP file

 

package net.minecraft.src;

public class ItemCapsuelEXP extends Item{

public ItemCapsuelEXP(int par1) {
	super(par1);
	this.setMaxStackSize(1);
	this.setItemName("ItemCapEXP");
}
    public ItemStack onFoodEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        --par1ItemStack.stackSize;

        if (!par2World.isRemote)
        {
            par3EntityPlayer.clearActivePotions();
            par3EntityPlayer.addExperience(15);
            par3EntityPlayer.addChatMessage("Your EXP has been incresed slightly");
        }

        return par1ItemStack;
    }
    public int getMaxItemUseDuration(ItemStack par1ItemStack)
    {
        return 32;
    }

    /**
     * returns the action that specifies what animation to play when the items is being used
     */
    public EnumAction getItemUseAction(ItemStack par1ItemStack)
    {
        return EnumAction.eat;
    }

    /**
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
     */
    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
        return par1ItemStack;
    }

}

 

 

ItemEmptyCap File

 

package net.minecraft.src;

public class ItemEmptyCap extends Item{

public ItemEmptyCap (int par1) {
	super(par1);
}

public ItemStack onFoodEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){

	--par1ItemStack.stackSize;
	if(!par2World.isRemote){
		par3EntityPlayer.inPortal= true;
	}
	return par1ItemStack;

}


}

 

Posted

Also, the empty capsuel naming is broken and when i try to craft an empty capsuel, i get an exp capsuel.

 

updated code:

 

package net.minecraft.src;

import net.minecraft.client.Minecraft;
import net.minecraft.src.forge.Configuration;
import net.minecraft.src.forge.Property;

import java.io.File;

public class mod_Capsules extends BaseMod{



public static ItemEmptyCap emptyCap;
public static ItemCapsuelEXP capEXP;
@Override
public String getVersion() {
	return "0.01 A";
}

@Override
public void load() {




	File file = new File(Minecraft.getMinecraftDir(), "/config/Capsuels.cfg");
	Configuration cfg = new Configuration(file);
	cfg.load();
	int emptyID = cfg.getOrCreateBlockIdProperty("Empty Capsues", 500).getInt(500);
	int EXPID = cfg.getOrCreateBlockIdProperty("EXP Capsuels", 501).getInt(501); 
	emptyCap = new ItemEmptyCap(emptyID);
	capEXP = new ItemCapsuelEXP(EXPID);
	cfg.save();

	ModLoader.addName(emptyCap, "Empty Capsuel");
	ModLoader.addName(capEXP, "EXP Capsuel");

	ModLoader.addShapelessRecipe(new ItemStack(emptyCap, 64), new Object [] {Block.dirt});
	ModLoader.addShapelessRecipe(new ItemStack(capEXP, 1), new Object[] {Block.dirt, Block.dirt});




	//Reg. Recipie
	ModLoader.addShapelessRecipe(new ItemStack(capEXP, 1), new Object[] {emptyCap, Item.appleGold});

}
/*
public static final Item depletedCap = (new ItemEmptyCap(emptyCapID)).setFull3D().setIconCoord(5, 15).setItemName("depletedCap");
public static final Item CapsuelEXP = (new ItemCapsuelEXP(capExpID)).setFull3D().setIconCoord(6, 15).setItemName("EXPCap");
 */

}

 

  • 3 months later...
Posted

I need to save and load STRING parameter to/from configuration file, but can't do it.

I use code:

 

 

@PreInit
public void preInit(FMLPreInitializationEvent event) {
	String t = "test string";
	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
	config.load();
	t = config.get("main", "texture", "bla bla text").toString();
	config.save();
}

 

 

My resulting "t" equals "net.minecraftforge.common.Property@1866d49" string.

why is it? and how to fix?

Posted

I need to save and load STRING parameter to/from configuration file, but can't do it.

I use code:

 

 

@PreInit
public void preInit(FMLPreInitializationEvent event) {
	String t = "test string";
	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
	config.load();
	t = config.get("main", "texture", "bla bla text").toString();
	config.save();
}

 

 

My resulting "t" equals "net.minecraftforge.common.Property@1866d49" string.

why is it? and how to fix?

 

Instead of

t = config.get("main", "texture", "bla bla text").toString();

 

You have to use

t = config.get("main", "texture", "bla bla text").value;

 

 

Took me 2 minutes of searching in the code.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.