Class ChatPreviewer
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 efointermediary net/minecraft/class_7479named net/minecraft/client/network/ChatPreviewer
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA utility class that increments the ID by a random number from 0 to 99.private static final recordA query, or a request, to the server to send the chat message preview.private static final recordA response to the preview query. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MinecraftClientprivate static final longHow long the previewer should wait before consuming the response since the response arrived at the client in milliseconds.private static final longHow long the previewer should wait at a minimum before sending the next query in milliseconds.private final ChatPreviewer.IdIncrementorprivate @Nullable ChatPreviewer.Responseprivate static final longHow long the previewer can wait for the response at most before sending the next query in milliseconds.private @Nullable ChatPreviewer.QueryThe query that is waiting for the previewer to request (i.e.private @Nullable ChatPreviewer.QueryThe query that is waiting for the server to respond (i.e.private longThe last time a query was sent. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the last response and the queries (but not the query time).private longReturns the earliest time the next query can be sent.private longReturns the latest time the next query should be sent.Returns the preview text (also known as the last response text), ornullif the server responded as such.(package private) static StringReturns themessagenormalized by trimming it and then normalizing spaces.voidCalled whenquerywas input into the chat screen.voidonResponse(int id, @Nullable Text response) Called when the preview response was received.private voidquery(ChatPreviewer.Query query, long currentTime) Sendsqueryto the server.private booleanshouldQuery(long currentTime) Returns whether the delay for querying has passed.booleanReturns whether the preview should be rendered.tryConsumeResponse(String message) Returns the consumed response text, ornullif the server responded as such, or if the response could not be consumed.voidtryQuery()Sends the pending query, if it exists and the delay has passed.
-
Field Details
-
EARLIEST_NEXT_QUERY_DELAY
private static final long EARLIEST_NEXT_QUERY_DELAYHow 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 aLefo;a:Jintermediary field_39326Lnet/minecraft/class_7479;field_39326:Jnamed EARLIEST_NEXT_QUERY_DELAYLnet/minecraft/client/network/ChatPreviewer;EARLIEST_NEXT_QUERY_DELAY:J
-
LATEST_NEXT_QUERY_DELAY
private static final long LATEST_NEXT_QUERY_DELAYHow 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 bLefo;b:Jintermediary field_39327Lnet/minecraft/class_7479;field_39327:Jnamed LATEST_NEXT_QUERY_DELAYLnet/minecraft/client/network/ChatPreviewer;LATEST_NEXT_QUERY_DELAY:J
-
CONSUME_COOLDOWN
private static final long CONSUME_COOLDOWNHow 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 cLefo;c:Jintermediary field_39328Lnet/minecraft/class_7479;field_39328:Jnamed CONSUME_COOLDOWNLnet/minecraft/client/network/ChatPreviewer;CONSUME_COOLDOWN:J
-
client
- Mappings:
Namespace Name Mixin selector official dLefo;d:Leed;intermediary field_39329Lnet/minecraft/class_7479;field_39329:Lnet/minecraft/class_310;named clientLnet/minecraft/client/network/ChatPreviewer;client:Lnet/minecraft/client/MinecraftClient;
-
idIncrementor
- Mappings:
Namespace Name Mixin selector official eLefo;e:Lefo$c;intermediary field_39330Lnet/minecraft/class_7479;field_39330:Lnet/minecraft/class_7479$class_7482;named idIncrementorLnet/minecraft/client/network/ChatPreviewer;idIncrementor:Lnet/minecraft/client/network/ChatPreviewer$IdIncrementor;
-
pendingRequestQuery
The query that is waiting for the previewer to request (i.e. the next query to be sent). Can benullif there is no such query.- Mappings:
Namespace Name Mixin selector official fLefo;f:Lefo$a;intermediary field_39331Lnet/minecraft/class_7479;field_39331:Lnet/minecraft/class_7479$class_7480;named pendingRequestQueryLnet/minecraft/client/network/ChatPreviewer;pendingRequestQuery:Lnet/minecraft/client/network/ChatPreviewer$Query;
-
pendingResponseQuery
The query that is waiting for the server to respond (i.e. the last query). Can benullif there is no such query.- Mappings:
Namespace Name Mixin selector official gLefo;g:Lefo$a;intermediary field_39332Lnet/minecraft/class_7479;field_39332:Lnet/minecraft/class_7479$class_7480;named pendingResponseQueryLnet/minecraft/client/network/ChatPreviewer;pendingResponseQuery:Lnet/minecraft/client/network/ChatPreviewer$Query;
-
queryTime
private long queryTimeThe 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 hLefo;h:Jintermediary field_39333Lnet/minecraft/class_7479;field_39333:Jnamed queryTimeLnet/minecraft/client/network/ChatPreviewer;queryTime:J
-
lastResponse
- Mappings:
Namespace Name Mixin selector official iLefo;i:Lefo$b;intermediary field_39334Lnet/minecraft/class_7479;field_39334:Lnet/minecraft/class_7479$class_7481;named lastResponseLnet/minecraft/client/network/ChatPreviewer;lastResponse:Lnet/minecraft/client/network/ChatPreviewer$Response;
-
-
Constructor Details
-
ChatPreviewer
- Mappings:
Namespace Name Mixin selector official <init>Lefo;<init>(Leed;)Vintermediary <init>Lnet/minecraft/class_7479;<init>(Lnet/minecraft/class_310;)Vnamed <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 aLefo;a()Vintermediary method_44031Lnet/minecraft/class_7479;method_44031()Vnamed tryQueryLnet/minecraft/client/network/ChatPreviewer;tryQuery()V
-
query
Sendsqueryto the server.- Mappings:
Namespace Name Mixin selector official aLefo;a(Lefo$a;J)Vintermediary method_44034Lnet/minecraft/class_7479;method_44034(Lnet/minecraft/class_7479$class_7480;J)Vnamed queryLnet/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 aLefo;a(J)Zintermediary method_44033Lnet/minecraft/class_7479;method_44033(J)Znamed shouldQueryLnet/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 eLefo;e()Jintermediary method_44041Lnet/minecraft/class_7479;method_44041()Jnamed getEarliestNextQueryTimeLnet/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 fLefo;f()Jintermediary method_44042Lnet/minecraft/class_7479;method_44042()Jnamed getLatestNextQueryTimeLnet/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 bLefo;b()Vintermediary method_44036Lnet/minecraft/class_7479;method_44036()Vnamed clearLnet/minecraft/client/network/ChatPreviewer;clear()V
-
onInput
Called whenquerywas 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 aLefo;a(Ljava/lang/String;)Vintermediary method_44035Lnet/minecraft/class_7479;method_44035(Ljava/lang/String;)Vnamed onInputLnet/minecraft/client/network/ChatPreviewer;onInput(Ljava/lang/String;)V
-
onResponse
Called when the preview response was received.- Implementation Note:
- This sets the last response and clears
pendingResponseQueryif the pending query ID equalsid - Mappings:
Namespace Name Mixin selector official aLefo;a(ILrl;)Vintermediary method_44032Lnet/minecraft/class_7479;method_44032(ILnet/minecraft/class_2561;)Vnamed onResponseLnet/minecraft/client/network/ChatPreviewer;onResponse(ILnet/minecraft/text/Text;)V
-
getPreviewText
Returns the preview text (also known as the last response text), ornullif the server responded as such.This does not consume the response.
- Returns:
- the preview text (also known as the last response text), or
nullif the server responded as such - Mappings:
Namespace Name Mixin selector official cLefo;c()Lrl;intermediary method_44038Lnet/minecraft/class_7479;method_44038()Lnet/minecraft/class_2561;named getPreviewTextLnet/minecraft/client/network/ChatPreviewer;getPreviewText()Lnet/minecraft/text/Text;
-
tryConsumeResponse
Returns the consumed response text, ornullif 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
nullif the server responded as such, or if the response could not be consumed - Mappings:
Namespace Name Mixin selector official bLefo;b(Ljava/lang/String;)Lrl;intermediary method_44037Lnet/minecraft/class_7479;method_44037(Ljava/lang/String;)Lnet/minecraft/class_2561;named tryConsumeResponseLnet/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 dLefo;d()Zintermediary method_44040Lnet/minecraft/class_7479;method_44040()Znamed shouldRenderPreviewLnet/minecraft/client/network/ChatPreviewer;shouldRenderPreview()Z
-
normalize
Returns themessagenormalized by trimming it and then normalizing spaces.- Returns:
- the
messagenormalized by trimming it and then normalizing spaces - Mappings:
Namespace Name Mixin selector official cLefo;c(Ljava/lang/String;)Ljava/lang/String;intermediary method_44039Lnet/minecraft/class_7479;method_44039(Ljava/lang/String;)Ljava/lang/String;named normalizeLnet/minecraft/client/network/ChatPreviewer;normalize(Ljava/lang/String;)Ljava/lang/String;
-