Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat fix #4183

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

Expand Down Expand Up @@ -118,14 +116,12 @@ private void onAddMessage(Text message, @Nullable MessageSignatureData signature
}
}

@ModifyExpressionValue(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V",
slice = @Slice(from = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/hud/ChatHud;visibleMessages:Ljava/util/List;")), at = @At(value = "INVOKE", target = "Ljava/util/List;size()I"))
private int addMessageListSizeProxy(int size) {
if (Modules.get() == null) return size;
//modify max lengths for messages and visible messages
@ModifyConstant(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", constant = @Constant(intValue = 100))
private int maxLength(int size) {
if (Modules.get() == null || !getBetterChat().isLongerChat()) return size;

BetterChat betterChat = getBetterChat();
if (betterChat.isLongerChat() && betterChat.getChatLength() >= 100) return size - betterChat.getChatLength();
return size;
return size + betterChat.getExtraChatLines();
}

// Player Heads
Expand Down Expand Up @@ -163,10 +159,10 @@ private void onBreakChatMessageLines(Text message, MessageSignatureData signatur
private void onRemoveMessage(Text message, MessageSignatureData signature, int ticks, MessageIndicator indicator, boolean refresh, CallbackInfo ci) {
if (Modules.get() == null) return;

BetterChat betterChat = getBetterChat();
int size = betterChat.lines.size() - (betterChat.isLongerChat() && betterChat.getChatLength() >= 100 ? betterChat.getChatLength() : 0);
int extra = getBetterChat().isLongerChat() ? getBetterChat().getExtraChatLines() : 0;
int size = betterChat.lines.size();

while (size > 100) {
while (size > 100 + extra) {
betterChat.lines.removeInt(size - 1);
size--;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ public class BetterChat extends Module {
.name("extra-lines")
.description("The amount of extra chat lines.")
.defaultValue(1000)
.min(100)
.sliderRange(100, 1000)
.min(0)
.sliderRange(0, 1000)
.visible(longerChatHistory::get)
.build()
);
Expand Down Expand Up @@ -541,7 +541,7 @@ public boolean isLongerChat() {

public boolean keepHistory() { return isActive() && keepHistory.get(); }

public int getChatLength() {
public int getExtraChatLines() {
return longerChatLines.get();
}
}