Jump to content

Recommended Posts

Posted (edited)

I don't know if I should file a bug, but given that I'm new I'll try to ask first if my methodology is just wrong.

 

When I check the documentation at: https://mcforge.readthedocs.io/en/latest/concepts/registries/ It says at the moment of writing this to use events for registering items

Quote

The recommended way to register things is through the RegistryEvents.

When I register my item through events, by subscribing to

RegistryEvent.Register[Item]

 

And adequately register the event, I get no items in the creative tab of my mod.

 

However, when I use the ways I find in tutorials, by calling GameRegistry.register at  preInit, I get my items in my mod creative tab. According to the documentation this is the old way while the recommended event way of registering happens before preInit. Is this intended? Or a bug? I tried calling both, but you can only register items once. If you do it both the game crashes specifically at preInit because the item was already registered in the event that happens before preInit.

Edited by ctbe
Posted

It depends on where you initialize your creative tab. The RegisterEvents are called before preInit, so if you initialize your creative tab in preInit, you will set the Item's creative tab to null at the point when you register your Items. You should initialize it at the same time you declare the creative tab variable.

  • Like 1

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/

Posted (edited)

Thanks. It was me then.

 

Before, I was setting the creative tab for my item at the constructor of my item. But because you need the item to exist before registering it and the register event got launched before the creative tab for the mod was even created, what you said was happening. It was setting the item's creative tab to null at creation.

 

I fixed it by creating a method in my item's class that sets the creative tab and manually calling said method at preInit, when I know for sure the creative tab for my mod will already exist.

Edited by ctbe
Posted
12 hours ago, ctbe said:

I fixed it by creating a method in my item's class that sets the creative tab and manually calling said method at preInit, when I know for sure the creative tab for my mod will already exist.

Why? There is already a method to set the creative tab, just call that in preInit

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.