Jump to content

java.lang.NullPointerException: Can't use a null-name for the registry, object null.


Recommended Posts

Posted

I'm getting this error when starting minecraft with my mod on:

java.lang.NullPointerException: Can't use a null-name for the registry, object null.

Full log:

  Reveal hidden contents

https://github.com/MatthyPlayz/usefulemeralds/ is my repo

i have no idea what to put here, so i'll just say you can edit your signature at https://www.minecraftforge.net/forum/settings/signature/

Posted

us is a terrible modid, you have 64 characters available to you, don't use just two since it could lead to name collision.

 

How did you upload your repository and why did you delete the .gitignore file? Your repository contains a ton of not needed stuff like the run directory.

 

I doubt you own matthyfamily.com. Use a different package name.

 

BlockBasic(or BlockBase really) is an antipattern. Do not abuse inheritance. Especially if thay may harm your project later.

 

Don't use static initializers. Instantinate your stuff in the appropriate registry event. This is the cause of your error.

Well, technically the cause of your issue is the fact that you never call the init method, but if you were doing things the conventional way you wouldn't need this method anyway.

Posted
  On 4/9/2019 at 7:42 PM, matthyplayz said:

1. Good idea

2. It isnt in my folder for some reason

3. I do.

4. Okay

5. What would the event be?

6. okay thanks

Expand  

If you want to make a block, just make a class extending block, set the registryname and unlocalizedname in there.

Then make a class for registering them.

add @EventBusSubscriber over the line saying class (classname)

Then add this method:

@SubscribeEvent
public static void onBlockRegister(RegistryEvent.Register<Block> event) {
    event.getRegistry().registerAll(new YourBlock(), new YourOtherBlock());
}

Then add this too to register the itemblocks (items you hold):

@SubscribeEvent
public static void onItemRegister(RegistryEvent.Register<Item> event) {
	for (Block block : ForgeRegistries.BLOCKS.getValues()) {
    	if (block.getRegistryName().getResourceDomain().equals(MOD_ID)) {
      		event.getRegistry().register(new ItemBlock(block).setRegistryName(block.getRegistryName());
    }
}

 

If you want to get them just do /give @p modid:blockname.

(Substitute MOD_ID and modid with your modid, blockname with the block name)

Posted
  On 4/9/2019 at 10:25 PM, diesieben07 said:

I mean, it's great that you're trying to help and all, but... just copy-pasting what I tell other people to do is not really helpful unless you understand what's even going on.

In this case it works, yes. But please, if you want to help people help them using your knowledge.

Expand  

I understand what is going on, you iterate through all registered blocks, check if the modid is equal to yours, and if so create a new itemblock using it and set the registry name. I saw the code from another response of your and started using it cause it's a good idea (might be slow with a lot of mods though). Also, didn't check and see that there was an updated version of getValues() and that it was only there for legacy support.

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.