Jump to content

Recommended Posts

Posted (edited)

I have a simple question that honestly might generic enough for SO, but I think it fits.

Would it be a bad idea to make my "ModItems", "ModBlocks", etc. classes just be inner-classes of my main mod class? (I.e. Mod$Items, Mod$Blocks)

An alternative would be to rename the classes "(Mod ID)Items", "(Mod ID)Blocks" etc. but it feels just as sloppy, especially for longer mod ids.

Using the word "Mod" is just asking for class name collisions, and I'm not a fan of having to use fully qualified classpaths in my code. (Edit: Object holders kind of fix this issue, but I think it's still worth talking about)

Using inner-classes feels logical, as my mods items are a direct aspect of my mod, therefore it seems like it's not too far fetched to use inner classes for this. But, I'm not confident.

 

It feels like a pretty basic Java styling principal that I'm just ignorant of, so I'd like to get some input from people who are more experienced than me.

Edited by imacatlolol

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

Posted
  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
16 minutes ago, Draco18s said:

Nice, yeah that's exactly what I was thinking.

 

I can see that having hundreds of items might cause a bit of trouble, and my IDE doesn't always play nicely with inner-classes when I try searching for them or auto-completing, but aside from that I still think it's a worthwhile idea.

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

Posted

That does look quite tidy. Can't think of any reason not to do that.

 

The only thing to be aware of is that most of the registry methods rely heavily on java reflection, so you just have to avoid having totally isolated classes, or the class loader won't load them.  Eg, a class that doesn't have some import chain back to your main class. That is why you have to declare your objects somewhere else, and couldn't just put a sort of "@RegisterObject" on your class definition. 

Posted
3 hours ago, OnlyJoe said:

That does look quite tidy. Can't think of any reason not to do that.

 

The only thing to be aware of is that most of the registry methods rely heavily on java reflection, so you just have to avoid having totally isolated classes, or the class loader won't load them.  Eg, a class that doesn't have some import chain back to your main class. That is why you have to declare your objects somewhere else, and couldn't just put a sort of "@RegisterObject" on your class definition. 

That's still true of a class in its own file.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.