Jump to content

[1.7.2] addRecipe


Pardeep

Recommended Posts

I've checked the .getItem and .getBlock strings are exactly current, and yet I keep getting the same error (which also causes the game to close on startup).

Bear in mind the FPItems class has other recipes in it that work perfectly fine.

Thanks in advance.

 

Error log:


java.lang.NullPointerException: Initializing game
at net.minecraft.item.crafting.CraftingManager.addRecipe(CraftingManager.java:242)
at cpw.mods.fml.common.registry.GameRegistry.addShapedRecipe(GameRegistry.java:214)
at cpw.mods.fml.common.registry.GameRegistry.addRecipe(GameRegistry.java:209)
at freshpower.FPItems.recipes(FPItems.java:65)
at freshpower.FPItems.init(FPItems.java:16)
at freshpower.FreshPower.preinit(FreshPower.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:536)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
at com.google.common.eventbus.EventBus.post(EventBus.java:267)
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:209)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
at com.google.common.eventbus.EventBus.post(EventBus.java:267)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
at cpw.mods.fml.common.Loader.loadMods(Loader.java:498)
at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:194)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:561)
at net.minecraft.client.Minecraft.run(Minecraft.java:931)
at net.minecraft.client.main.Main.main(Main.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

Line of code it points to:

GameRegistry.addRecipe(new ItemStack(FreshPower.getItem("fp_ingotFreshSteel"), 9), new Object[]{"A", 'A',FreshPower.getBlock("fp_storageFreshSteel")});

 

Link to comment
Share on other sites

I don't mean put "","","" as in the recipe.

 

What do you want your recipe to be?

 

For instance a diamond pickaxe is:

 

"AAA"

" B "

" B "

 

Where A is diamond, and B is sticks.

 

The reason yours is putting an infinite amount of your items is because you put the recipe as blank.

Show me your code, also please just in case it's actually not your fault lol

Link to comment
Share on other sites

"A"?

Seriously?

 

Are you trying to make the item be craftable wherever you want to place it in?

Kind of like iron block to 9 ingots (i suppose that is what you are trying to do)?

 

Yeah, you need to get more familiar to MinecraftForge methods / Minecraft methods :P

 

If you are you need to change the method you are using to this.

GameRegistry.addShapelessRecipe(new ItemStack(FreshPower.getItem("fp_ingotFreshSteel"), 9), new Object[]
{FreshPower.getBlock("fp_storageFreshSteel")});

Link to comment
Share on other sites

"A"?

Seriously?

 

Are you trying to make the item be craftable wherever you want to place it in?

Kind of like iron block to 9 ingots (i suppose that is what you are trying to do)?

 

Yeah, you need to get more familiar to MinecraftForge methods / Minecraft methods :P

 

If you are you need to change the method you are using to this.

GameRegistry.addShapelessRecipe(new ItemStack(FreshPower.getItem("fp_ingotFreshSteel"), 9), new Object[]
{FreshPower.getBlock("fp_storageFreshSteel")});

 

When I use the shapeless recipe method (which, I should mention, I tried before consulting the forums) returned this error:

java.lang.RuntimeException: Invalid shapeless recipy!
at net.minecraft.item.crafting.CraftingManager.addShapelessRecipe(CraftingManager.java:277)
at cpw.mods.fml.common.registry.GameRegistry.addShapelessRecipe(GameRegistry.java:219)
at freshpower.FPItems.recipes(FPItems.java:66)
at freshpower.FPItems.init(FPItems.java:17)
at freshpower.FreshPower.preinit(FreshPower.java:44)

 

I tried the recipe with a different vanilla block and it worked. It may be something to do with my block but I doubt it. If it is, here's the code anyway:

This is in the init section of base class

registerBlock(new BlockGeneric(Material.iron).setBlockName("fp_storageFreshSteel").setHardness(5.0F).setResistance(10.0F).setBlockTextureName("freshpower:storagefreshsteel"));

BlockGeneric

public class BlockGeneric extends Block
{
public BlockGeneric(Material par1)
{
	super(par1);
	this.setCreativeTab(FreshPower.creativetab);
}
}

This is the method I use to get my block

public static Block getBlock(String a)
    {
    	return GameRegistry.findBlock(FreshPower.MODID, a);
    }

THe recipe:

GameRegistry.addShapelessRecipe(new ItemStack(FreshPower.getItem("fp_ingotFreshSteel"), 9), new Object[]{ FreshPower.getBlock("fp_storageFreshSteel") });

Link to comment
Share on other sites

Show me these:

 

at freshpower.FPItems.recipes(FPItems.java:66) : Line 66
at freshpower.FPItems.init(FPItems.java:17) : Line 17
at freshpower.FreshPower.preinit(FreshPower.java:44) : Line 44

 

This error code is a little outdated now but the thing it flags as an error is the same. The ones about init and preinit were just my way of organising files (they work for other things and so shouldn't really be the issue). The .recipes one is the line with my shapelessrecipe on.

 

So i've got it to work now. I put the code directly in the init constructor of my base class. Now I need to work out how to get it to work when I put it in a different class.

i.e. this is my setup:

My secondary class:

public static void init()
{
	craftingRecipes();
}
public static void craftingRecipes()
{
	GameRegistry.addShapelessRecipe(new ItemStack(FreshPower.getItem("fp_ingotFreshSteel"), 9), new Object[]{ FreshPower.getBlock("fp_storageFreshSteel") });
}

 

Base class:

@EventHandler
    public void preinit(FMLPreInitializationEvent event)
    {
    	SecondaryClass.init();
    }

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.