Jump to content

SOLVED A simple question about method names in derived classes; why are they called "getBlahBlah()"


MSpace-Dev

Recommended Posts

Hey everyone,

 

So.. I have always wondered why, when you want to set something like, say, an item's rarity. You'd use the method getRarity() to SET the rarity of that item. Why are these methods named like this? Is it because when the code compiles, the code that puts it all together looks through everything and GETS the values from these methods, and that's why you override these GET methods? Just been a little curious about this.

I did also notice a little inconsistency though. Like when you want to set a block's light level, the method you override is called setLightLevel()...  are there any rules to know when to use the GET method to set something and the SET method to set something?

Edited by MSpace-Dev
Link to comment
Share on other sites

I have tried to look, but I just get into a loop of going back and forth. I cannot find any other classes that use the method getRarity so, I cannot figure out what calls these methods, hence why I came here to ask the question. "Use your IDE." isn't super helpful. But I understand that you're trying to get people to figure things out for themselves, just... in this case, I never found what I was looking for. I also did find something called IForgeRegistryEntry so yeah...

Link to comment
Share on other sites

First off, I manage to find the super method

public EnumRarity getRarity(ItemStack stack)
    {
        return stack.isItemEnchanted() ? EnumRarity.RARE : EnumRarity.COMMON;
    }

Where do I go from there? (I'm ctrl+clicking things, btw) and I use IntelliJ IDE

When I ctrl+click getRarity, it just takes me back to where I've overridden it, and not to where it gets called elsewhere, cause there is no 'elsewhere'

Look at this picture: uPYc5VZ.png

Link to comment
Share on other sites

Look at the picture, that's exactly what I did. I clicked on Find Usages (Pressing Alt+F7) and that picture shows the results. A result of it only being used in my class. And when I say that I've found the super method, that method is the super method from MY derived class. What I'm saying is that I managed to get to the class where getRarity is declared.

This takes me to the Item class where it's declared. YXsO9hl.png

Link to comment
Share on other sites

Never realized I was in Project Files.

Anyways, I have found it being decalred in ItemStack, and other classes. Except these aren't overriding anything, they're declaring new methods of it? I can't find what actually "calls" it. Perhaps if you tell me the answer, I'll be able to understand what's happening here better.

Link to comment
Share on other sites

29 minutes ago, MSpace-Dev said:

Never realized I was in Project Files.

Anyways, I have found it being decalred in ItemStack, and other classes. Except these aren't overriding anything, they're declaring new methods of it? I can't find what actually "calls" it. Perhaps if you tell me the answer, I'll be able to understand what's happening here better.

Sounds like you searched for references writing the hierarchy, rather than everywhere. 

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.

Link to comment
Share on other sites

30 minutes ago, MSpace-Dev said:

Oh, I understand now. Yeah. I thought Item extended ItemStack or viceversa,

That would never make sense. 

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.

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.

Announcements



×
×
  • Create New...

Important Information

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