Class ChatPreviewer

java.lang.Object
net.minecraft.client.network.ChatPreviewer

@Environment(CLIENT) public class ChatPreviewer extends Object
Chat previewer manages the chat preview. Chat previewer is created per ChatScreen, so closing the chat screen and reopening it would create a new chat previewer.

A query is a request to the server to send the chat message preview. The previewer only sends the query if there is no query that is waiting for the response, or if the last query took more than 1000L milliseconds to respond. A query can be sent at most every 100L milliseconds.

The response to the query can be "consumed" by calling tryConsumeResponse(java.lang.String). If the response is still valid (i.e. the input has not changed since the query was sent), consuming the response will return the response and clear it. Note that to prevent race condition between the player sending the chat message and the response's arrival, responses can only be consumed after the cooldown (by default, 200L milliseconds) has passed. It is also possible to get the response text without consuming by calling getPreviewText().

Mappings:
Namespace Name
official efo
intermediary net/minecraft/class_7479
named net/minecraft/client/network/ChatPreviewer
  • Field Details

    • EARLIEST_NEXT_QUERY_DELAY

      private static final long EARLIEST_NEXT_QUERY_DELAY
      How long the previewer should wait at a minimum before sending the next query in milliseconds. Is 100L.
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official a Lefo;a:J
      intermediary field_39326 Lnet/minecraft/class_7479;field_39326:J
      named EARLIEST_NEXT_QUERY_DELAY Lnet/minecraft/client/network/ChatPreviewer;EARLIEST_NEXT_QUERY_DELAY:J
    • LATEST_NEXT_QUERY_DELAY

      private static final long LATEST_NEXT_QUERY_DELAY
      How long the previewer can wait for the response at most before sending the next query in milliseconds. Is 1000L.
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official b Lefo;b:J
      intermediary field_39327 Lnet/minecraft/class_7479;field_39327:J
      named LATEST_NEXT_QUERY_DELAY Lnet/minecraft/client/network/ChatPreviewer;LATEST_NEXT_QUERY_DELAY:J
    • CONSUME_COOLDOWN

      private static final long CONSUME_COOLDOWN
      How long the previewer should wait before consuming the response since the response arrived at the client in milliseconds. Is 200L.
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official c Lefo;c:J
      intermediary field_39328 Lnet/minecraft/class_7479;field_39328:J
      named CONSUME_COOLDOWN Lnet/minecraft/client/network/ChatPreviewer;CONSUME_COOLDOWN:J
    • client

      private final MinecraftClient client
      Mappings:
      Namespace Name Mixin selector
      official d Lefo;d:Leed;
      intermediary field_39329 Lnet/minecraft/class_7479;field_39329:Lnet/minecraft/class_310;
      named client Lnet/minecraft/client/network/ChatPreviewer;client:Lnet/minecraft/client/MinecraftClient;
    • idIncrementor

      private final ChatPreviewer.IdIncrementor idIncrementor
      Mappings:
      Namespace Name Mixin selector
      official e Lefo;e:Lefo$c;
      intermediary field_39330 Lnet/minecraft/class_7479;field_39330:Lnet/minecraft/class_7479$class_7482;
      named idIncrementor Lnet/minecraft/client/network/ChatPreviewer;idIncrementor:Lnet/minecraft/client/network/ChatPreviewer$IdIncrementor;
    • pendingRequestQuery

      @Nullable private @Nullable ChatPreviewer.Query pendingRequestQuery
      The query that is waiting for the previewer to request (i.e. the next query to be sent). Can be null if there is no such query.
      Mappings:
      Namespace Name Mixin selector
      official f Lefo;f:Lefo$a;
      intermediary field_39331 Lnet/minecraft/class_7479;field_39331:Lnet/minecraft/class_7479$class_7480;
      named pendingRequestQuery Lnet/minecraft/client/network/ChatPreviewer;pendingRequestQuery:Lnet/minecraft/client/network/ChatPreviewer$Query;
    • pendingResponseQuery

      @Nullable private @Nullable ChatPreviewer.Query pendingResponseQuery
      The query that is waiting for the server to respond (i.e. the last query). Can be null if there is no such query.
      Mappings:
      Namespace Name Mixin selector
      official g Lefo;g:Lefo$a;
      intermediary field_39332 Lnet/minecraft/class_7479;field_39332:Lnet/minecraft/class_7479$class_7480;
      named pendingResponseQuery Lnet/minecraft/client/network/ChatPreviewer;pendingResponseQuery:Lnet/minecraft/client/network/ChatPreviewer$Query;
    • queryTime

      private long queryTime
      The last time a query was sent.

      The next query will be sent after 100L to 1000L milliseconds; the actual delay depends on when the server responds to the query.

      Mappings:
      Namespace Name Mixin selector
      official h Lefo;h:J
      intermediary field_39333 Lnet/minecraft/class_7479;field_39333:J
      named queryTime Lnet/minecraft/client/network/ChatPreviewer;queryTime:J
    • lastResponse

      Mappings:
      Namespace Name Mixin selector
      official i Lefo;i:Lefo$b;
      intermediary field_39334 Lnet/minecraft/class_7479;field_39334:Lnet/minecraft/class_7479$class_7481;
      named lastResponse Lnet/minecraft/client/network/ChatPreviewer;lastResponse:Lnet/minecraft/client/network/ChatPreviewer$Response;
  • Constructor Details

    • ChatPreviewer

      public ChatPreviewer(MinecraftClient client)
      Mappings:
      Namespace Name Mixin selector
      official <init> Lefo;<init>(Leed;)V
      intermediary <init> Lnet/minecraft/class_7479;<init>(Lnet/minecraft/class_310;)V
      named <init> Lnet/minecraft/client/network/ChatPreviewer;<init>(Lnet/minecraft/client/MinecraftClient;)V
  • Method Details

    • tryQuery

      public void tryQuery()
      Sends the pending query, if it exists and the delay has passed.
      Mappings:
      Namespace Name Mixin selector
      official a Lefo;a()V
      intermediary method_44031 Lnet/minecraft/class_7479;method_44031()V
      named tryQuery Lnet/minecraft/client/network/ChatPreviewer;tryQuery()V
    • query

      private void query(ChatPreviewer.Query query, long currentTime)
      Sends query to the server.
      Mappings:
      Namespace Name Mixin selector
      official a Lefo;a(Lefo$a;J)V
      intermediary method_44034 Lnet/minecraft/class_7479;method_44034(Lnet/minecraft/class_7479$class_7480;J)V
      named query Lnet/minecraft/client/network/ChatPreviewer;query(Lnet/minecraft/client/network/ChatPreviewer$Query;J)V
    • shouldQuery

      private boolean shouldQuery(long currentTime)
      Returns whether the delay for querying has passed.

      The previewer only sends the query if there is no query that is waiting for the response, or if the last query took more than 1000L milliseconds to respond. A query can be sent at most every 100L milliseconds.

      Returns:
      whether the delay for querying has passed
      Mappings:
      Namespace Name Mixin selector
      official a Lefo;a(J)Z
      intermediary method_44033 Lnet/minecraft/class_7479;method_44033(J)Z
      named shouldQuery Lnet/minecraft/client/network/ChatPreviewer;shouldQuery(J)Z
    • getEarliestNextQueryTime

      private long getEarliestNextQueryTime()
      Returns the earliest time the next query can be sent.
      Returns:
      the earliest time the next query can be sent
      Implementation Note:
      This is 100L milliseconds after the last query.
      Mappings:
      Namespace Name Mixin selector
      official e Lefo;e()J
      intermediary method_44041 Lnet/minecraft/class_7479;method_44041()J
      named getEarliestNextQueryTime Lnet/minecraft/client/network/ChatPreviewer;getEarliestNextQueryTime()J
    • getLatestNextQueryTime

      private long getLatestNextQueryTime()
      Returns the latest time the next query should be sent.
      Returns:
      the latest time the next query should be sent
      Implementation Note:
      This is 1000L milliseconds after the last query.
      Mappings:
      Namespace Name Mixin selector
      official f Lefo;f()J
      intermediary method_44042 Lnet/minecraft/class_7479;method_44042()J
      named getLatestNextQueryTime Lnet/minecraft/client/network/ChatPreviewer;getLatestNextQueryTime()J
    • clear

      public void clear()
      Clears the last response and the queries (but not the query time).
      Mappings:
      Namespace Name Mixin selector
      official b Lefo;b()V
      intermediary method_44036 Lnet/minecraft/class_7479;method_44036()V
      named clear Lnet/minecraft/client/network/ChatPreviewer;clear()V
    • onInput

      public void onInput(String query)
      Called when query was input into the chat screen.
      Implementation Note:
      If the normalized query is empty, the queries are cleared and the empty response is set by the client; otherwise it sets the pending query.
      Mappings:
      Namespace Name Mixin selector
      official a Lefo;a(Ljava/lang/String;)V
      intermediary method_44035 Lnet/minecraft/class_7479;method_44035(Ljava/lang/String;)V
      named onInput Lnet/minecraft/client/network/ChatPreviewer;onInput(Ljava/lang/String;)V
    • onResponse

      public void onResponse(int id, @Nullable @Nullable Text response)
      Called when the preview response was received.
      Implementation Note:
      This sets the last response and clears pendingResponseQuery if the pending query ID equals id
      Mappings:
      Namespace Name Mixin selector
      official a Lefo;a(ILrl;)V
      intermediary method_44032 Lnet/minecraft/class_7479;method_44032(ILnet/minecraft/class_2561;)V
      named onResponse Lnet/minecraft/client/network/ChatPreviewer;onResponse(ILnet/minecraft/text/Text;)V
    • getPreviewText

      @Nullable public @Nullable Text getPreviewText()
      Returns the preview text (also known as the last response text), or null if the server responded as such.

      This does not consume the response.

      Returns:
      the preview text (also known as the last response text), or null if the server responded as such
      Mappings:
      Namespace Name Mixin selector
      official c Lefo;c()Lrl;
      intermediary method_44038 Lnet/minecraft/class_7479;method_44038()Lnet/minecraft/class_2561;
      named getPreviewText Lnet/minecraft/client/network/ChatPreviewer;getPreviewText()Lnet/minecraft/text/Text;
    • tryConsumeResponse

      @Nullable public @Nullable Text tryConsumeResponse(String message)
      Returns the consumed response text, or null if the server responded as such, or if the response could not be consumed.

      If the response is still valid (i.e. the input has not changed since the query was sent), consuming the response will return the response and clear it. Note that to prevent race condition between the player sending the chat message and the response's arrival, responses can only be consumed after the cooldown (by default, 200L milliseconds) has passed. It is also possible to get the response text without consuming by calling getPreviewText().

      Returns:
      the consumed response text, or null if the server responded as such, or if the response could not be consumed
      Mappings:
      Namespace Name Mixin selector
      official b Lefo;b(Ljava/lang/String;)Lrl;
      intermediary method_44037 Lnet/minecraft/class_7479;method_44037(Ljava/lang/String;)Lnet/minecraft/class_2561;
      named tryConsumeResponse Lnet/minecraft/client/network/ChatPreviewer;tryConsumeResponse(Ljava/lang/String;)Lnet/minecraft/text/Text;
    • shouldRenderPreview

      public boolean shouldRenderPreview()
      Returns whether the preview should be rendered.
      Returns:
      whether the preview should be rendered
      Implementation Note:
      A preview should be rendered if there is a response, a pending query, or a query waiting for the response.
      Mappings:
      Namespace Name Mixin selector
      official d Lefo;d()Z
      intermediary method_44040 Lnet/minecraft/class_7479;method_44040()Z
      named shouldRenderPreview Lnet/minecraft/client/network/ChatPreviewer;shouldRenderPreview()Z
    • normalize

      static String normalize(String message)
      Returns the message normalized by trimming it and then normalizing spaces.
      Returns:
      the message normalized by trimming it and then normalizing spaces
      Mappings:
      Namespace Name Mixin selector
      official c Lefo;c(Ljava/lang/String;)Ljava/lang/String;
      intermediary method_44039 Lnet/minecraft/class_7479;method_44039(Ljava/lang/String;)Ljava/lang/String;
      named normalize Lnet/minecraft/client/network/ChatPreviewer;normalize(Ljava/lang/String;)Ljava/lang/String;