Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

I've narrowed the problem further down, the Block.getIdFromBlock(my_block) returns -1.

It isn't properly registered, somehow. Yet I feel like I'm pretty sure It's registered... Am I supposed to do something extra? my mod worked fine untill now O.o

@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/

  • Author

@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.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.