Posted November 8, 20195 yr I'm enjoying the ObjectHolder feature that was added to Forge, but it's been giving me a bit of a stylistic headache. I'm using IntelliJ IDEA and since ObjectHolder fields have to final, and therefore initialized as null before injection, it's complaining that ObjectHolder fields always return null. Checking to see if an ObjectHolder field is null before using it is still a good idea, but since it's a final initialized as null my IDE thinks I'm being silly. Also, I'm using the class-level ObjectHolder that infers the registry names from the field names, since I don't want to type my object registry names more than once in case I need to change them, and adding a separate set of fields just to hold the registry names feels like overkill, which is why I'd prefer not to do that. But if someone has a solution that requires me to annotate each field directly, I think that's a fine compromise. Edited November 8, 20195 yr by imacatlolol I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
November 8, 20195 yr Author Well, nevermind, found an adequate solution. Rather than initializing the fields inline, initializing them in a static constructor seems to solve the problem, funnily enough. However, I'm still open to other solutions for the sake of variety, if anyone has them. I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
November 9, 20195 yr One way is to use a method that always returns null but suppresses IDEA's warnings, like this: method, usage The newer way is to use the DeferredRegister system that was introduced relatively recently. I've started updating to this, but it doesn't look like I've pushed any of my changes to GitHub. Edited November 9, 20195 yr by Choonster Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
November 9, 20195 yr Author 33 minutes ago, Choonster said: One way is to use a method that always returns null but suppresses IDEA's warnings, like this: method, usage The newer way is to use the DeferredRegister system that was introduced relatively recently. I've started updating to this, but it doesn't look like I've pushed any of my changes to GitHub. Woah... The DeferredRegister system is really cool! That's even better than anything I was expecting, thanks for bringing it to my attention! I'm assuming it won't interfere with ObjectHolder, right? From the looks of it, I simply need to initialize ObjectHolder objects with DeferredRegister#register instead of null and ObjectHolder will still take over any replacements by other mods. Edited November 9, 20195 yr by imacatlolol I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
November 9, 20195 yr 11 minutes ago, imacatlolol said: Woah... The DeferredRegister system is really cool! That's even better than anything I was expecting, thanks for bringing it to my attention! I'm assuming it won't interfere with ObjectHolder, right? From the looks of it, I simply need to initialize ObjectHolder objects with DeferredRegister#register instead of null and ObjectHolder will still take over any replacements by other mods. If you're using DeferredRegister, you don't need to use @ObjectHolder at all; the returned RegistryObject is internally registered as an ObjectHolder and as such is automatically updated with overrides. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
November 9, 20195 yr Author Just now, Choonster said: If you're using DeferredRegister, you don't need to use @ObjectHolder at all; the returned RegistryObject is internally registered as an ObjectHolder and as such is automatically updated with overrides. Oh, that makes more sense. It even says that right there in the docs for RegistryObject. Whoops, thanks again! I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
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.