Jump to content

Recommended Posts

Posted

I am attempting to create throwable spawn eggs.

My Item Class:

 

  Reveal hidden contents

 

The item is registered like so:

GameRegistry.registerItem(new ItemThrowableEgg(), "thowableSpawnEggSpawn", MODID);

The item works fine until I try to create an EntityItem out of it:

 

  Reveal hidden contents

 

When I get a huge stack trace and a NullPointerException as it tries to render in the inventory:

 

  Reveal hidden contents

 

The entityitem I see on the ground before picking it up has a missing texture. When I get a throwableEgg from my creative inventory and drop it, the texture looks fine.

 

Why is this?

Posted

You should only be making a new ItemThrowableEgg ONCE, and then referencing that instance everywhere else (assuming you only have one ItemThrowableEgg - if you have more, make multiple instances).

 

That's why in every item-making tutorial, you always see stuff like this:

public static Item throwableEgg;

// preInit
throwableEgg = new ItemThrowableEgg();
GameRegistry.registerItem(throwableEgg, 'throwableEgg', modid);

ItemStack egg = new ItemStack(YourMod.throwableEgg);

throwableEgg is the reference that you can use everywhere, because the item only exists as a single object - if you made a new Item for every single item in the game, that would waste a lot of memory.

Posted

A nullpointerexception is when you are trying to access a variable that is null. This means if you don't initialize a variable before using it, you will get this exception.

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.