Jump to content

What is the purpose of the @ObjectHolder?


TheAwesomeGem

Recommended Posts

On the official doc, I see that @ObjectHolder injects values and that if the class has that annotation, all the public static final members do as well. But what does it mean? What if I have a "public static final Block test_block" variable. What will forge inject into it? Will it auto register that block?

Link to comment
Share on other sites

It doesn't auto-register the block. It actually does the opposite -- you register the block and it will go back and inject an instance to all the fields that match name.

 

Whether you use it depends on your coding style. I don't necessarily name my fields the same as the registry names so have to add the additional matching name, and so I don't find it really provides me a lot of convenience. But some people really like to use it.

  • Like 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

52 minutes ago, LexManos said:

Overrides.

 

4 hours ago, jabelar said:

It doesn't auto-register the block. It actually does the opposite -- you register the block and it will go back and inject an instance to all the fields that match name.

 

Whether you use it depends on your coding style. I don't necessarily name my fields the same as the registry names so have to add the additional matching name, and so I don't find it really provides me a lot of convenience. But some people really like to use it.

Which means if I were to have a public static final Item ItemName from another mod, whenever that mod loads, my variable will get injected it's data?

Link to comment
Share on other sites

11 hours ago, loordgek said:

So what exactly is a domain holder? Does it just hold the resourcelocation?

Link to comment
Share on other sites

17 hours ago, TheAwesomeGem said:

 

Which means if I were to have a public static final Item ItemName from another mod, whenever that mod loads, my variable will get injected it's data?

IYes. I believe that what happens is that each registry event happens across all mods, then all the objectholder annotations for that type of object are processed. So the injection does happen after all mods are registered. In fact if you look at the link the example shows exactly how to do this. You just need the modid in the domain of the annotation. Either the entire class annotation or the individual field annotation can specify the domain.

  • Like 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

16 minutes ago, jabelar said:

IYes. I believe that what happens is that each registry event happens across all mods, then all the objectholder annotations for that type of object are processed. So the injection does happen after all mods are registered. In fact if you look at the link the example shows exactly how to do this. You just need the modid in the domain of the annotation. Either the entire class annotation or the individual field annotation can specify the domain.

Wow that's actually pretty cool and very handy to modify aspects of other mod without an API. Thanks a lot!

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.

×
×
  • Create New...

Important Information

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