Jump to content

Chat lagging


Wuble

Recommended Posts

Hello!

 

I am currently developing a mod which will translate chat that is received to the chosen language (currently hard-coded to English). I am doing this with Microsoft translate. I've come across the issue that, upon receiving a chat message, the game will temporarily lag. If I'm correct, this is due to waiting to get the detect result for every message (Detect.execute). Would there be a way to fix this so that it doesn't lag the game?

 

VIDEO:

https://www.youtube.com/watch?v=vleaJqNftCE

(Though it's short, it's visible that every received chat message lags the game.)

 

 

[spoiler=Code]

package com.wuble.chattranslate.handler;

 

import com.memetix.mst.translate.Translate;

import com.memetix.mst.detect.Detect;

import com.memetix.mst.language.Language;

import net.minecraft.util.*;

import net.minecraftforge.client.event.ClientChatReceivedEvent;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

 

public class ChatHandler {

 

    public static String receivedMessage, sentMessage;

    public static Language from;

 

    @SubscribeEvent

    public void onClientChatReceived(ClientChatReceivedEvent event){

        receivedMessage = event.message.getUnformattedText();

        try {from = Detect.execute(receivedMessage); } catch (Exception e) { }

        if (from == Language.ENGLISH) { }

        else {

            try {

                sentMessage = Translate.execute(receivedMessage, from, Language.ENGLISH)  + " §7§o[From: " + from.getName(Language.ENGLISH) + "§7§o]";

                event.message = new ChatComponentText(sentMessage);

            } catch (Exception e) {

            }

 

      }

    }

}

 

 

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.