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. ChatPreviewRequester handles the actual requesting.

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 egg
intermediary net/minecraft/class_7479
named net/minecraft/client/network/ChatPreviewer
  • Field Details

    • 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 a Legg;a:J
      intermediary field_39328 Lnet/minecraft/class_7479;field_39328:J
      named CONSUME_COOLDOWN Lnet/minecraft/client/network/ChatPreviewer;CONSUME_COOLDOWN:J
    • shouldRenderPreview

      private boolean shouldRenderPreview
      Mappings:
      Namespace Name Mixin selector
      official b Legg;b:Z
      intermediary field_39429 Lnet/minecraft/class_7479;field_39429:Z
      named shouldRenderPreview Lnet/minecraft/client/network/ChatPreviewer;shouldRenderPreview:Z
    • lastPreviewedMessage

      @Nullable private @Nullable String lastPreviewedMessage
      Mappings:
      Namespace Name Mixin selector
      official c Legg;c:Ljava/lang/String;
      intermediary field_39430 Lnet/minecraft/class_7479;field_39430:Ljava/lang/String;
      named lastPreviewedMessage Lnet/minecraft/client/network/ChatPreviewer;lastPreviewedMessage:Ljava/lang/String;
    • pendingRequestMessage

      @Nullable private @Nullable String pendingRequestMessage
      The message 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.
      Implementation Note:
      If the message is sent instantly, this field is not set.
      Mappings:
      Namespace Name Mixin selector
      official d Legg;d:Ljava/lang/String;
      intermediary field_39431 Lnet/minecraft/class_7479;field_39431:Ljava/lang/String;
      named pendingRequestMessage Lnet/minecraft/client/network/ChatPreviewer;pendingRequestMessage:Ljava/lang/String;
    • requester

      private final ChatPreviewRequester requester
      Mappings:
      Namespace Name Mixin selector
      official e Legg;e:Legf;
      intermediary field_39432 Lnet/minecraft/class_7479;field_39432:Lnet/minecraft/class_7516;
      named requester Lnet/minecraft/client/network/ChatPreviewer;requester:Lnet/minecraft/client/network/ChatPreviewRequester;
    • lastResponse

      Mappings:
      Namespace Name Mixin selector
      official f Legg;f:Legg$a;
      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> Legg;<init>(Leeu;)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

    • tryRequestPending

      public void tryRequestPending()
      Sends the message that was waiting for its request delay to pass, if it is able to.
      Mappings:
      Namespace Name Mixin selector
      official a Legg;a()V
      intermediary method_44031 Lnet/minecraft/class_7479;method_44031()V
      named tryRequestPending Lnet/minecraft/client/network/ChatPreviewer;tryRequestPending()V
    • tryRequest

      public void tryRequest(String message)
      Tries to send the request to preview message. If the delay has passed, it will send instantly; otherwise, it will set pendingRequestMessage which can be requested by calling tryRequestPending().
      Mappings:
      Namespace Name Mixin selector
      official a Legg;a(Ljava/lang/String;)V
      intermediary method_44274 Lnet/minecraft/class_7479;method_44274(Ljava/lang/String;)V
      named tryRequest Lnet/minecraft/client/network/ChatPreviewer;tryRequest(Ljava/lang/String;)V
    • tryRequestInternal

      private void tryRequestInternal(String message)
      Mappings:
      Namespace Name Mixin selector
      official c Legg;c(Ljava/lang/String;)V
      intermediary method_44276 Lnet/minecraft/class_7479;method_44276(Ljava/lang/String;)V
      named tryRequestInternal Lnet/minecraft/client/network/ChatPreviewer;tryRequestInternal(Ljava/lang/String;)V
    • disablePreview

      public void disablePreview()
      Sets shouldRenderPreview to false and clears this previewer.
      Mappings:
      Namespace Name Mixin selector
      official b Legg;b()V
      intermediary method_44275 Lnet/minecraft/class_7479;method_44275()V
      named disablePreview Lnet/minecraft/client/network/ChatPreviewer;disablePreview()V
    • clear

      private void clear()
      Clears the last response and the requester's state.
      Mappings:
      Namespace Name Mixin selector
      official e Legg;e()V
      intermediary method_44036 Lnet/minecraft/class_7479;method_44036()V
      named clear Lnet/minecraft/client/network/ChatPreviewer;clear()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 if the requester successfully handled the response.
      Mappings:
      Namespace Name Mixin selector
      official a Legg;a(ILrm;)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 Legg;c()Lrm;
      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 Legg;b(Ljava/lang/String;)Lrm;
      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 Legg;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 d Legg;d(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;