Tom
Tom

Reputation: 3

PreInitialisation to initialisation error in Minecraft Forge

I was making a mod and tried to add crafting recipies.
When I tried to launch it, it crashed and left a report. Can someone please tell me what I need to do to fix this?

---- Minecraft Crash Report ---- // Quite honestly, I wouldn't worry myself about that.

Time: 19/04/16 20:25 Description: Initializing game

java.lang.StringIndexOutOfBoundsException: String index out of range: 5 at java.lang.String.charAt(Unknown Source) at net.minecraft.item.crafting.CraftingManager.addRecipe(CraftingManager.java:232) at cpw.mods.fml.common.registry.GameRegistry.addShapedRecipe(GameRegistry.java:250) at
cpw.mods.fml.common.registry.GameRegistry.addShapedRecipe(GameRegistry.java:250) at cpw.mods.fml.common.registry.GameRegistry.addRecipe(GameRegistry.java:245) at com.Abhijith.Main.CraftingManager.addCraftingRec(CraftingManager.java:18) at com.Abhijith.Main.CraftingManager.MainRegistry(CraftingManager.java:13) at com.Abhijith.Main.MainRegistry.Preload(MainRegistry.java:23) at A lot of unneeeded lines follow...

here is my crafting manager

public class CraftingManager {
    public static void MainRegistry(){
        addCraftingRec();
        addSmeltingRec();
    }
    public static void addCraftingRec(){
        //Shaped
        GameRegistry.addRecipe(new ItemStack(MBlocks.DiaSlab, 3), new Object[]{" "," ","XXX",'X', Blocks.diamond_block});
        GameRegistry.addRecipe(new ItemStack(MItems.oStick, 1), new Object[]{" X "," X ", 'X', Blocks.obsidian});
        //Shapeless
    }
    public static void addSmeltingRec(){
        GameRegistry.addSmelting(Blocks.coal_block, new ItemStack(Blocks.obsidian, 1), 20.0f);

    }
}

Upvotes: 0

Views: 122

Answers (1)

Tschallacka
Tschallacka

Reputation: 28742

java.lang.StringIndexOutOfBoundsException: 
String index out of range: 5 at java.lang.String.charAt(Unknown Source) at 
net.minecraft.item.crafting.CraftingManager.addRecipe(CraftingManager.java:232) at 

StringIndexOutOfBounds means: if you have a string that has a length of 4, and try to access position 5, it does not exist, and you get this problem.

"hello" > length 5 h 0 e 1 l 2 l 3 o 4

it has 5 elements. But if you try to access it at 5, "hello".charAt(5) you'll get an string index out of bounds, because index 5 does not exist.

You probaly defined your recipe wrong.

So check your recipe in CraftingManager.java:232<-- line number

and check your documentation.

Without code, I can't help you.

EDIT

From the comments:

DiaSlab, 3), new Object[]{" "," ","XXX" those strings before the XXX need to be >equal lenth. Make them 3 spaces.

Upvotes: 0

Related Questions