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.

Featured Replies

Posted

Hi, I'm trying to receive the data from the tablist, most notably the footer and header.

 

Here is the method I am using to obtain the private fields. I try to check for both the forge name and vanilla: 

private String getPrivateStringFieldFromObject(Object object, String forgeFieldName, String vanillaFieldName)
            throws NoSuchFieldException, SecurityException, IllegalArgumentException,
            IllegalAccessException {
        Field targetField = null;
        try {
            targetField = object.getClass().getDeclaredField(forgeFieldName);
        } catch (NoSuchFieldException e) {
            targetField = object.getClass().getDeclaredField(vanillaFieldName);
        }
        if (targetField != null) {
            targetField.setAccessible(true);
            return String.valueOf(targetField.get(object).toString()).toString();
        } else {
            return "";
        }
    }

Here is the call that I use: 

getPrivateStringFieldFromObject(minecraft.ingameGUI.getTabList().getClass(), "footer", "field_175255_h") 

however I get java.lang.NoSuchFieldException after catching the first one. I don't see how I'm not getting the footer.

Odds are you have the wrong SRG name (not vanilla name, btw, the vanilla name would be something like aaa1).  Looking at the MCPBot exports there are two fields with the MCP name "footer." You're using the first one.  The other one has the SRG name "field_179702_b"

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
24 minutes ago, Draco18s said:

Odds are you have the wrong SRG name (not vanilla name, btw, the vanilla name would be something like aaa1).  Looking at the MCPBot exports there are two fields with the MCP name "footer." You're using the first one.  The other one has the SRG name "field_179702_b"

The SRG name you provided does the same error.

4 hours ago, diesieben07 said:

There is one entry for GuiPlayerTabOverlay.footer and it is field_175255_h.

Notice how I can literally not tell what class a field belongs to in the CSV:

srg.png.fc4f668b73db43c81d51e37653dfb548.png

Yes, I know there's an IRC interface that makes things non-ambiguous, but that's rather a bit cumbersome.

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.

7 minutes ago, diesieben07 said:

Well, it gives you correct results though...

Yes, using the right field name definitely does.  But having the wrong one throws a NoSuchFieldException which is what the OP was getting.

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
11 hours ago, diesieben07 said:

Doing it this way is kinda a bad idea. You should look up the Field object once and store it in a static final field. The Field lookup (getDeclaredField) is the slow part about reflection.

Also always directly specify the class-name when using getDeclaredField, you don't know what the exact class of the object will be.

 

The problem why it doesn't work is because you pass in the GuiPlayerTabOverlay.class object into getPrivateStringFieldFromObject. But the method getPrivateStringFieldFromObject assumes the object passed in is the object to access the field from.

 

I suggest just doing something like this:


private static final Field myField = ReflectionHelper.findField(GuiPlayerTabOverlay.class, "field_175255_h", "footer");

// later
myField.get(object);

 

What object do I have to pass in to access the field from in this instance?

BTW:

String.valueOf(targetField.get(object).toString()).toString()

How many times do you really need to convert to a string?

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

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.