Jump to content

Recommended Posts

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.

Posted

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.

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

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

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

Posted
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?

Posted

BTW:

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

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

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

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.