Jump to content

[1.6] Missing getServerData() from Minecraft.java


maxpowa

Recommended Posts

In previous versions, the Minecraft class had a method to getServerData(), which returned a variable which that class holds in memory.

 

    /**
     * Get the current ServerData instance.
     */
    public ServerData getServerData()
    {
        return this.currentServerData;
    }

 

I went back into my MCP 1.5.2 folder, and here is the exact code... currentServerData is a private variable and that's why I need the getter for it, the strangest thing about it is that the setter is there, but then the variable is never used.

Link to comment
Share on other sites

I need the serverdata simply to show servername and ip (hidden if hidden in the serverlist) above the playerlist gui.

 

I used reflection, but it causes issues because I'm not sure what the obfuscated name is... And I'm trying to stay away from becoming a coremod...

Link to comment
Share on other sites

There are a few places I needed to do something similar,

I first try for the obfuscated name and if that fails check for the "normal" name

 

I've been looking up the obfuscated names in these files.

 

/mcp/config/fields.csv

/mcp/config/methods.csv

 

In this case it looks like field_71422_O is currentServerData

 

you can also go to the mcp irc channel and by whispering the bot get the data,

that way is much easier when there is a few that are similar in name (and the csv lacks a description) as the bot provides more info.

Link to comment
Share on other sites

Thanks ShetiPhian, but I just ended up doing this:

    public static ServerData getServerData() {
      Minecraft mc = Minecraft.getMinecraft();
      ServerData serverData = null;
      for (Field field : Minecraft.class.getDeclaredFields()) {
        if (field.getType() == ServerData.class) {
          field.setAccessible(true);
          try {
            serverData = (ServerData)field.get(mc);
          } catch (Exception e) {
            System.out.println("[TukMC] Unable to find server information ("  e.getCause().toString()")");
          }
        }
      }

      return serverData;
    }

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.