Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

  • Author

Alright, then can you explain to me what calls GetRarity()? Cause everything you've said there I've already said above, but thanks for clarification on that part. Just need to know the missing piece of the puzzle, which is, what is calling these methods?

  • Author

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...

  • Author

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

  • Author

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

  • Author

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.

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.

  • Author

Oh, I understand now. Yeah. I thought Item extended ItemStack or viceversa, which is why I was expecting to find an @Override above one of the methods. Yeah, this makes perfect sense.

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.

  • Author
1 minute ago, Draco18s said:

That would never make sense. 

I'm still grasping what each of these things do. Give me a break. Thanks for the help though guys!

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.