Jump to content

[1.16.5] NullPointerException: Registry Object not present


Myxtro

Recommended Posts

I'm making some tools and I'm using a Set of type Block to specify on what blocks the tools would work. This is all in my ItemInit class which I use to register items. See below.

private static Set<Block> EFFECTIVE_ON = Sets.newHashSet(Blocks.ANDESITE);

This works fine with minecraft blocks. Problems occur when I want to use mod blocks like this:

private static Set<Block> EFFECTIVE_ON = Sets.newHashSet(BlockInit.AMBER_BLOCK.get());

 

I get an error while loading the game, which is a NullPointerException. 

Exception message: java.lang.NullPointerException: Registry Object not present: extinctioncraft:amber_block

 

It seems my block can't be found by this set despite the block working fine in the game itself. 

 

I already tried the following without success:

- Checked if the BlockInit is registered in the main class. ( BlockInit.BLOCKS.register(bus); )

- Checked if the block is registered in the BlockInit class. 

Link to comment
Share on other sites

29 minutes ago, Luis_ST said:

where do you use the Set?
you need to use a Supplier when using RegistryObjects before they are initialized (or RegistryObjects)
create a Set of RegistryObjects and use RegistryObject#get when you want to use the Set

It is used when creating a ToolItem in the third argument. 

public static final RegistryObject<Item> IRON_GEO_HAMMER = ITEMS.register("iron_geo_hammer", 
			() -> new ToolItem(1, 1, ItemTier.IRON, EFFECTIVE_ON, new Item.Properties()));

Do I need to change anything here?

Edited by Myxtro
Link to comment
Share on other sites

2 minutes ago, Luis_ST said:

replace "EFFECTIVE_ON" with the Set

EFFECTIVE_ON is the name of the set. Here's the set for refference. 

private static Set<Block> EFFECTIVE_ON = Sets.newHashSet(BlockInit.AMBER_BLOCK.get());

I could ofcourse replace EFFECTIVE_ON with the set but I would then have to repeat this for each item it is applicable to.

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.