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

      @Nullable private @Nullable String lastPreviewedMessage
      Mappings:
      Namespace Name Mixin selector
      official b Lehg;b: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 c Lehg;c: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 d Lehg;d:Lehf;
      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 e Lehg;e:Lehg$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> Lehg;<init>(Lefu;)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 Lehg;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 Lehg;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 d Lehg;d(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()
      Clears this previewer.
      Mappings:
      Namespace Name Mixin selector
      official b Lehg;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 Lehg;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 previewText)
      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 Lehg;a(ILrq;)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
    • cannotConsumePreview

      public boolean cannotConsumePreview()
      Returns whether the previewer cannot consume the preview (because the preview response hasn't arrived or because of the cooldown).
      Returns:
      whether the previewer cannot consume the preview (because the preview response hasn't arrived or because of the cooldown)
      Mappings:
      Namespace Name Mixin selector
      official c Lehg;c()Z
      intermediary method_44928 Lnet/minecraft/class_7479;method_44928()Z
      named cannotConsumePreview Lnet/minecraft/client/network/ChatPreviewer;cannotConsumePreview()Z
    • equalsLastPreviewed

      public boolean equalsLastPreviewed(String text)
      Returns whether normalized text equals the last previewed text.
      Returns:
      whether normalized text equals the last previewed text
      Mappings:
      Namespace Name Mixin selector
      official b Lehg;b(Ljava/lang/String;)Z
      intermediary method_44927 Lnet/minecraft/class_7479;method_44927(Ljava/lang/String;)Z
      named equalsLastPreviewed Lnet/minecraft/client/network/ChatPreviewer;equalsLastPreviewed(Ljava/lang/String;)Z
    • getPreviewText

      @Nullable public @Nullable ChatPreviewer.Response 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 d Lehg;d()Lehg$a;
      intermediary method_44038 Lnet/minecraft/class_7479;method_44038()Lnet/minecraft/class_7479$class_7481;
      named getPreviewText Lnet/minecraft/client/network/ChatPreviewer;getPreviewText()Lnet/minecraft/client/network/ChatPreviewer$Response;
    • tryConsumeResponse

      @Nullable public @Nullable ChatPreviewer.Response 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 c Lehg;c(Ljava/lang/String;)Lehg$a;
      intermediary method_44037 Lnet/minecraft/class_7479;method_44037(Ljava/lang/String;)Lnet/minecraft/class_7479$class_7481;
      named tryConsumeResponse Lnet/minecraft/client/network/ChatPreviewer;tryConsumeResponse(Ljava/lang/String;)Lnet/minecraft/client/network/ChatPreviewer$Response;
    • 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 e Lehg;e(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;