Jump to content

[1.8.9] Extending the Chat Character limit to 256


Hexadecimal

Recommended Posts

Recently I've found a need to extend the chat limit in 1.8.9, it is really useful being twice its normal size in 1.10 and above and I want it in 1.8.9. The server I want to use this mod on allows the increased chat limit across all versions and so it needs to actually be sent as a message.

 

I've accomplished this with MCP (you literally just need to change one variable pretty much) but I would like to know how to do it in forge.

 

I've done some research and most people seem to suggest class transformers, however these seem extremely complex and apparently need to be coded myself if they are to work - I have no clue where to start with this.

 

If anybody knew of any alternatives to class transformers, or could give me any pointers I would greatly appreciate it!

Link to comment
Share on other sites

Is it a variable?

Access it with reflection.

Is it a hard coded value? Tough luck, can't do it.

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.

Link to comment
Share on other sites

Is it a variable?

Access it with reflection.

Is it a hard coded value? Tough luck, can't do it.

 

I've done this:

 

public class ExtendedChatGui {
    private String defaultTextField = "";
    public static GuiChat gc = new GuiChat();

    public void printField() throws Exception {
        Class<?> objClass = gc.getClass();
        Field[] fields = objClass.getDeclaredFields();

        System.out.println("Printing fields: ");
        for (Field field : fields) {
            field.setAccessible(true);
            String name = field.getName();
            System.out.println(name);
        }
    }
}

 

This prints all the fields, including inputField, which is the variable I need.

 

This is the variable:

 

protected GuiTextField inputField;

 

The issue is, to set the max string length a method is called like so:

 

this.inputField.setMaxStringLength(255);

 

How would I go about calling this method from the array of fields I have?

 

 

 

 

 

 

 

Link to comment
Share on other sites

More reflection. Specifically

getValue

.

And if the method you need to invoke is also private, you'll have to use

invoke

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.

Link to comment
Share on other sites

More reflection. Specifically

getValue

.

And if the method you need to invoke is also private, you'll have to use

invoke

 

How though? fields[8] has no method .getValue...

 

I also tried this method I found online:

 

Object c = f.get(gc);

 

Printing c.toString() returns a null pointer exception.

Link to comment
Share on other sites

Sorry, it's called "get"

Alternatively you can use the ReflectionHelper class.  Although I do advise referencing things by name (which means you'll have to use MCPBot to get the SRG name as well) rather than by index.  The index might change unexpectedly.

 

For example:

DamageSource damage = ReflectionHelper.getPrivateValue(LootContext.class, context, "damageSource","field_186503_f");

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.

Link to comment
Share on other sites

Sorry, it's called "get"

Alternatively you can use the ReflectionHelper class.  Although I do advise referencing things by name (which means you'll have to use MCPBot to get the SRG name as well) rather than by index.  The index might change unexpectedly.

 

For example:

DamageSource damage = ReflectionHelper.getPrivateValue(LootContext.class, context, "damageSource","field_186503_f");

 

I'm still a little confused.

 

How does one invoke a method from a field?

 

 

Edit: I think I may have it:

 

My new code:

 

    Field f = fields[8];
        f.setAccessible(true);

        Object fieldValue = f.get(gc);
        Method method = fieldValue.getClass().getDeclaredMethod("setMaxStringLength");
        method.invoke(fieldValue, 256);

 

 

Edit:

 

Nope, got this error:

 

java.lang.NoSuchMethodException: java.lang.String.setMaxStringLength()

 

It's referencing java.lang.String, it's supposed to be GuiTextField...

Link to comment
Share on other sites

Oh jesus fucking christ.  I even GAVE you an example of how to use it.  It gives you back a typed object that has all the publicly accessible objects you'd want for an object of that type.  Stop casting it to Object.

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.

Link to comment
Share on other sites

Oh jesus fucking christ.  I even GAVE you an example of how to use it.  It gives you back a typed object that has all the publicly accessible objects you'd want for an object of that type.  Stop casting it to Object.

 

Getting a null pointer:

 

 GuiTextField gui = ReflectionHelper.getPrivateValue(GuiChat.class, gc, "inputField");

        gui.setMaxStringLength(256);

 

It's on the gui.setMaxStringLength

 

 

 

Please be patient, I know it's frustrating but I'm learning and I've never had to use reflection before...

Link to comment
Share on other sites

You are running this code client side only yes?

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.

Link to comment
Share on other sites

Well yes. Because that value is not static and a new GuiChat screen is created every time the chat is opened.

So you will have to wait for it to be open, then change it. You can't do it in the mod initialization phases.

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.

Link to comment
Share on other sites

Well yes. Because that value is not static and a new GuiChat screen is created every time the chat is opened.

So you will have to wait for it to be open, then change it. You can't do it in the mod initialization phases.

 

I don't suppose there is an event for Chat Opened in Forge?

Link to comment
Share on other sites

Well yes. Because that value is not static and a new GuiChat screen is created every time the chat is opened.

So you will have to wait for it to be open, then change it. You can't do it in the mod initialization phases.

 

I don't suppose there is an event for Chat Opened in Forge?

There is an OpenGui event look under the net.minecraftforge.events package

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

This will not work, this is not the only place that forces the string length. This is a network packet thing.

The server would receive a string that is to ling and kick you.

There is no way to do this with reflection or anything, and your 'mcp' fix doesn't actually work.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

This will not work, this is not the only place that forces the string length. This is a network packet thing.

The server would receive a string that is to ling and kick you.

There is no way to do this with reflection or anything, and your 'mcp' fix doesn't actually work.

 

My MCP fix does work as I have tested it thoroughly.

 

As I said in my main post the server has a plugin which SUPPORTS double the chat limit.

 

Link to comment
Share on other sites

Well yes. Because that value is not static and a new GuiChat screen is created every time the chat is opened.

So you will have to wait for it to be open, then change it. You can't do it in the mod initialization phases.

 

I don't suppose there is an event for Chat Opened in Forge?

There is an OpenGui event look under the net.minecraftforge.events package

 

I'm still getting a Null Pointer. The code is fired when I open the chat (managed to do that), but it's still null...

Link to comment
Share on other sites

I'm still getting a Null Pointer. The code is fired when I open the chat (managed to do that), but it's still null...

 

I don't know, then.

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.

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.