Jump to content

[SOLVED] [1.7.10] ItemStack Item is null


Pancake

Recommended Posts

Greetings!

 

In my code I recently added some recipes for items (I was on creative the whole time, so I didn't need them) and my recipe-loader fails to work with blocks of my mod.

 

I've narrowed down where the issue is: the .getItem() method on an itemstack of a custom block returns null.

Does my block class need to extend ItemBlock? Then how do I give it a TileEntity? (it's currently extending BlockContainer)

 

I've read through the getItem method of ItemStack, and saw it checks if a delegate is null or not. It gets initialised when you construct an ItemStack with an Item, but I'm registering it with a Block... Which shouldn't be a problem right?

 

This is the relevant code for the block and recipe registry:

 

public static Block BlockItemStorageUnitTier1 = new BlockItemStorageUnitTier1();
public static Block BlockItemStorageUnitTier2 = new BlockItemStorageUnitTier2();
public static Item ItemMechanicalBindingComponent = new ItemMechanicalBindingComponent();

@EventHandler
public void preInit(FMLInitializationEvent event){
    	GameRegistry.registerBlock(BlockItemStorageUnitTier1,"BlockItemStorageUnitTier1");
    	GameRegistry.registerBlock(BlockItemStorageUnitTier2,"BlockItemStorageUnitTier2");
    	GameRegistry.registerTileEntity(TileEntityItemStorageUnitTier1.class,"TileEntityItemStorageUnitTier1");
    	GameRegistry.registerTileEntity(TileEntityItemStorageUnitTier2.class,"TileEntityItemStorageUnitTier2");
GameRegistry.registerItem(ItemMechanicalBindingComponent,"ItemMechanicalBindingComponent");
}

@EventHandler
public void init(FMLInitializationEvent event){
ItemStack stackSUT1 = new ItemStack(BlockItemStorageUnitTier1);
ItemStack stackSUT2 = new ItemStack(BlockItemStorageUnitTier2);
ItemStack stackMBC = new ItemStack(ItemMechanicalBindingComponent);
GameRegistry.addShapedRecipe(stackSUT2,"xxx","xyx","xxx",'x',stackSUT1,'y',stackMBC);
System.out.println(stackSUT1);
}
/code]

That crashes on the println, because the toString() method of an ItemStack asks item.getUnlocalizedName(), and item is null.

I have no idea what to do. I need the item object to not be null for my crafting system. How else can I get an object from an itemstack that's shared amongst multiple itemstacks of the same kind?

Thanks in advance,
Pancake

Link to comment
Share on other sites

@EventHandler
public void preInit(FMLInitializationEvent event){
    	...
}

@EventHandler
public void init(FMLInitializationEvent event){
...
}

Copy-Pasting...

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

@EventHandler
public void preInit(FMLInitializationEvent event){
    	...
}

@EventHandler
public void init(FMLInitializationEvent event){
...
}

Copy-Pasting...

 

I'm confused. is this supposed to help me? Don't I already have this part? I showed it in my original post.

Link to comment
Share on other sites

Look at the arguments from the methods...

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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.