Posted September 21, 201410 yr So in Minecraft 1.7.10, the Minecraft session field is private and final. I can change it to public with an access transformer (which is easy) but I can't actually modify the session id because it's final. Is there a way to edit this or would I have to code a fully custom client?
September 21, 201410 yr You can set it to be accessible using reflection. This StackoOverflow post shows you how to do it: http://stackoverflow.com/questions/3301635/change-private-static-final-field-using-java-reflection But be aware that reflection uses quite a lot of cpu power... PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.
September 22, 201410 yr Author So I used the same method as in the stackoverflow post but I get a field not found exception when I tell it to modify Minecraft.class.getField("session")
September 22, 201410 yr First of all, I suggest using either the ReflectionHelper or ObfuscationReflectionHelper classes - they make cleaner code, and change this: try { Field field = SomeClass.class.getDeclaredField("someFieldName"); field.setAccessible(true); Object object = field.get(SOMECLASS_INSTANCE); //do stuff } catch (Exception e) { try { Field field = SomeClass.class.getDeclaredField("field_SRG_NAME"); field.setAccessible(true); Object object = field.get(SOMECLASS_INSTANCE); //do stuff } catch(Exception e2) { //Log exception } } into Object object = ReflectionHelper.getPrivateValue(SomeClass.class, SOMECLASS_INSTANCE, "someFieldName", "field_SRG_NAME"); Much cleaner. Example code Field sessionField = ReflectionHelper.findField(Minecraft.class, "session", "field_71449_j"); ReflectionHelper.setPrivateValue(Field.class, sessionField, sessionField.getModifiers() & ~Modifier.FINAL, "modifiers"); ReflectionHelper.setPrivateValue(Minecraft.class, Minecraft.getMinecraft(), YOUR_SESSION_INSTANCE, "session", "field_71449_j"); BEFORE ASKING FOR HELP READ THE EAQ! I'll help if I can. Apologies if I do something obviously stupid. If you don't know basic Java yet, go and follow these tutorials.
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.