Created
April 29, 2023 11:43
-
-
Save isXander/1b67bce51161f4c64cf5e9839ef64442 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void addMessage(Component message, @Nullable MessageSignature signature, int ticks, @Nullable GuiMessageTag tag, boolean refresh) { | |
int i = Mth.floor((double)this.getWidth() / this.getScale()); | |
if (tag != null && tag.icon() != null) { | |
i -= tag.icon().width + 4 + 2; | |
} | |
List<FormattedCharSequence> list = ComponentRenderUtils.wrapComponents(message, i, this.minecraft.font); | |
boolean bl = this.isChatFocused(); | |
for(int j = 0; j < list.size(); ++j) { | |
FormattedCharSequence formattedCharSequence = (FormattedCharSequence)list.get(j); | |
if (bl && this.chatScrollbarPos > 0) { | |
this.newMessageSinceScroll = true; | |
this.scrollChat(1); | |
} | |
boolean bl2 = j == list.size() - 1; | |
this.trimmedMessages.add(0, new GuiMessage.Line(ticks, formattedCharSequence, tag, bl2)); | |
} | |
while(this.trimmedMessages.size() > 100) { | |
this.trimmedMessages.remove(this.trimmedMessages.size() - 1); | |
} | |
if (!refresh) { | |
this.allMessages.add(0, new GuiMessage(ticks, message, signature, tag)); | |
while(this.allMessages.size() > 100) { | |
this.allMessages.remove(this.allMessages.size() - 1); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ModifyExpressionValue(method = "addMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/MessageSignature;ILnet/minecraft/client/GuiMessageTag;Z)V", at = @At(value = "NEW", target = "Lnet/minecraft/client/GuiMessage$Line;<init>(ILnet/minecraft/util/FormattedCharSequence;Lnet/minecraft/client/GuiMessageTag;Z)V")) | |
private GuiMessage.Line hookMessageLineAdd(GuiMessage.Line line, @Share("lines") LocalRef<List<GuiMessage.Line>> linesRef) { | |
if (linesRef.get() == null) | |
linesRef.set(new ArrayList<>()); | |
linesRef.get().add(line); | |
return line; | |
} | |
@ModifyExpressionValue(method = "addMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/MessageSignature;ILnet/minecraft/client/GuiMessageTag;Z)V", at = @At(value = "NEW", target = "Lnet/minecraft/client/GuiMessage;<init>(ILnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/MessageSignature;Lnet/minecraft/client/GuiMessageTag;)V")) | |
private GuiMessage hookMessageAdd(GuiMessage message, @Share("lines") LocalRef<List<GuiMessage.Line>> linesRef) { | |
messageToLines.put(message, linesRef.get()); | |
return message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment