Posted July 4, 201312 yr 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.
July 6, 201312 yr Author 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...
July 6, 201312 yr 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.
July 6, 201312 yr Author 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; }
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.