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

In the mod I am creating, I am attempting to register a block. However, the game seems to crash now that I have attempted to do so. I have my code and an error message that seems to be useful to display.

 

Here they are:

 

 

 

The blocks are registered under preInit() in FirstMod.java and the class that makes the blocks (BlockMaker.java) and the class with the Block registering methods (MyBlocks.java) are in the init package.

 

 

What can I do to fix the crashing and be able to spawn in the block?

 

 

If you need any more information, I would be more than happy to share it.

 

[move]Thank you![/move]

"I'm not afraid of computers taking over the world. They're just sitting there. I can hit them with a two by four." - Thom Yorke

  • Author

In the mod I am creating, I am attempting to register a block. However, the game seems to crash now that I have attempted to do so. I have my code and an error message that seems to be useful to display.

 

Here they are:

 

 

 

The blocks are registered under preInit() in FirstMod.java and the class that makes the blocks (BlockMaker.java) and the class with the Block registering methods (MyBlocks.java) are in the init package.

 

 

What can I do to fix the crashing and be able to spawn in the block?

 

 

If you need any more information, I would be more than happy to share it.

 

[move]Thank you![/move]

"I'm not afraid of computers taking over the world. They're just sitting there. I can hit them with a two by four." - Thom Yorke

Item item = Item.getItemFromBlock(block);

is returning null because you didn't register an ItemBlock for your block.  That no longer happens automatically.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Item item = Item.getItemFromBlock(block);

is returning null because you didn't register an ItemBlock for your block.  That no longer happens automatically.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Item item = Item.getItemFromBlock(block);

is returning null because you didn't register an ItemBlock for your block.  That no longer happens automatically.

 

I'm kinda confused here. I am not sure what an ItemBlock is or how it works. Does it have to do with a block .json? Could I get a small example?

 

My apologies  :-[

"I'm not afraid of computers taking over the world. They're just sitting there. I can hit them with a two by four." - Thom Yorke

  • Author

Item item = Item.getItemFromBlock(block);

is returning null because you didn't register an ItemBlock for your block.  That no longer happens automatically.

 

I'm kinda confused here. I am not sure what an ItemBlock is or how it works. Does it have to do with a block .json? Could I get a small example?

 

My apologies  :-[

"I'm not afraid of computers taking over the world. They're just sitting there. I can hit them with a two by four." - Thom Yorke

The class Block relates to blocks taking up space in the world. When a block breaks and drops something, the floater is an item (actually an ItemStack). If the item dropped  is the "block itself", then it is the ItemBlock derived from the block. The ItemBlock is also what appears in your hand and in inventory.

 

Almost every block has a related ItemBlock. Exceptions are things like flowing water and lava source blocks. If your block is something that can drop and be picked up, then it needs a related ItemBlock.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

The class Block relates to blocks taking up space in the world. When a block breaks and drops something, the floater is an item (actually an ItemStack). If the item dropped  is the "block itself", then it is the ItemBlock derived from the block. The ItemBlock is also what appears in your hand and in inventory.

 

Almost every block has a related ItemBlock. Exceptions are things like flowing water and lava source blocks. If your block is something that can drop and be picked up, then it needs a related ItemBlock.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

In Minecraft, blocks only exist in the world. In your inventory, everything is a

ItemStack

which contains an

Item

. When you register your block, you also need to register an

ItemBlock

, which is the in-inventory representation of your block, for your block. When you call

GameRegister.register

it only registers the block. To register an

ItemBlock

you'll need to use something like this:

 

GameRegistry.register(new ItemBlock(cheese_block).setRegistryName(cheese_block.getRegistryName()));

 

Also, you're registering

cheese_blockName

which is created in the

register

method but your using

MyBlocks.cheese_block

everywhere else.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

In Minecraft, blocks only exist in the world. In your inventory, everything is a

ItemStack

which contains an

Item

. When you register your block, you also need to register an

ItemBlock

, which is the in-inventory representation of your block, for your block. When you call

GameRegister.register

it only registers the block. To register an

ItemBlock

you'll need to use something like this:

 

GameRegistry.register(new ItemBlock(cheese_block).setRegistryName(cheese_block.getRegistryName()));

 

Also, you're registering

cheese_blockName

which is created in the

register

method but your using

MyBlocks.cheese_block

everywhere else.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

The class Block relates to blocks taking up space in the world. When a block breaks and drops something, the floater is an item (actually an ItemStack).

 

Actually an ItemEntity containing an ItemStack.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

The class Block relates to blocks taking up space in the world. When a block breaks and drops something, the floater is an item (actually an ItemStack).

 

Actually an ItemEntity containing an ItemStack.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.