Jump to content

Recommended Posts

Posted

Hey guys, I recently tried out a shaped crafting recipe and I get a crash

 

  Reveal hidden contents

 

 

Here's my Main mod class:

 

  Reveal hidden contents

 

Any help appreciated, thanks in advance,

~TehHaloTree

Posted

What I also suggest is to outsource your blocks and items into a seperate class, so that your @Mod class is not so crammed

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

  Quote

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.

Posted

You have done the register wrong, for example

 

GameRegistry.registerShapedRecipe(new ItemStack(MyModClass.coalOnAStick, 1), "XOX", "OXO", "XOX", 'X', new ItemStack(Items.coal, 1), 'O', new ItemStack(Items.stick, 1));

 

Where 'X' represents X in "XOX" and "OXO" and 'O' represents O in "XOX" and "OXO", and adding more items just do the identifier first then then itemstack like I show eg:

 

'A', new ItemStack(Items.apple, 1)

 

Would look like

GameRegistry.registerShapedRecipe(new ItemStack(MyModClass.coalOnAStick, 1), "XOX", "OXO", "XOX", 'X', new ItemStack(Items.coal, 1), 'O', new ItemStack(Items.stick, 1), 'A', new ItemStack(Items.apple, 1));

Posted

First of all, I get an error on "RegisterShapedRecipe". This is the line of code I'm using when it errors.

 

  Reveal hidden contents

 

Second, the items being used in the original recipe are not from my mod and are being called from other sources (ie. Ic2 API and OreDict). Thus, whenever I type them in as "new ItemStack(<insert Item name>) it errors as I do not know if I should call them separately in the mod file or call them right within that recipe. Thanks,

~TehHaloTree

Posted
  On 7/18/2014 at 11:18 PM, TheGreyGhost said:

Hi

 

Looks to me like you are initialising your crafting handler before you have initialised all the items that it uses.  You should initialise your blocks, items, and register them in preInit.  The recipes should be in load.

 

This link might help explain it further (see Event Handling section)

http://greyminecraftcoder.blogspot.com.au/2013/11/how-forge-starts-up-your-code.html

 

-TGG

 

I put all of my block initialization and registry into preinit and no errors in eclipse. When I startup I get the same crash. Looking at the console when it crashes, it seems to be happening at line 315:

 

  Reveal hidden contents

 

 

Here's the redone class.

 

  Reveal hidden contents

 

Sorry if I'm not understanding something, this is the first time I am using a recipe that uses items from separate mods. Thanks again,

~TehHaloTree

Posted

Hi

 

I'm having trouble following the formatting in your mod class so I'm not sure whether your initialisation is happening in a static initialiser.  But anyway it shouldn't.

 

This is not right, it should be FMLPreInitializationEvent for the preinit.

   @EventHandler
   public void prinit(FMLInitializationEvent event) {

 

You need to split your initialisation up into

 

FMLPreInitializationEvent:

Register all your blocks

 

FMLInitializationEvent:

Register your recipes

 

Currently your code doesn't do that, which I think is why it doesn't work.  I reckon the crash is almost certainly caused by your halotech.AdvancedPlateBender not being initialised before you add the Recipe.

 

-TGG

 

 

Posted

I changed the preinit to FMLPreInitializationEvent and it still crashes with the same crash. I examined it a little more, and I think the things throwing the NullPointerExceptio are the items being called from the other mods. I do not know if I called them correctly, if they need to be moved to a different section of code, or if they aren't being place into the recipe code correctly. Thanks,

~TehHaloTree

 

EDIT: Moved recipes into the CraftHandler.java class, no difference. Here's the class:

 

  Reveal hidden contents

 

Posted

Hi

 

Try splitting this line into several so you can see exactly which one is null

 

     GameRegistry.addRecipe(new ItemStack(halotech.AdvancedPlateBender, 1), "zaz","yxy","zbz", 'y', Items.getItem("iridiumPlate"), 'z', OreDictionary.getOres("gearElectrum"), 'x', OreDictionary.getOres("bender"), 'a', Items.getItem("lapotronCrystal"), 'b', OreDictionary.getOres("circuitElite"));

eg

ItemStack apb = new ItemStack(halotech.AdvancedPlateBender, 1);
System.out.println("apb:" + apb);
Item iridiumPlate = Items.getItem("iridiumPlate");
// ..etc..

 

You might find that one of them is null, for example if you have misspelled the name.

 

-TGG

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.