fix a bunch of stuff

This commit is contained in:
blackilykat 2024-11-02 17:31:31 +01:00
parent 9d9283c70b
commit de55b8208e
2 changed files with 48 additions and 12 deletions

View file

@ -12,10 +12,13 @@ import net.minecraft.client.gui.hud.MessageIndicator;
import net.minecraft.network.message.MessageSignatureData;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent;
import net.minecraft.util.Nullables;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
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.callback.CallbackInfo;
@ -28,31 +31,55 @@ public abstract class ChatHudMixin {
public abstract void addMessage(Text message, @Nullable MessageSignatureData signature, @Nullable MessageIndicator indicator);
@Shadow @Final private MinecraftClient client;
@Shadow @Final private static Logger LOGGER;
@Shadow protected abstract void logChatMessage(ChatHudLine message);
@Shadow protected abstract void addVisibleMessage(ChatHudLine message);
@Shadow protected abstract void addMessage(ChatHudLine message);
/*
@Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;logChatMessage(Lnet/minecraft/client/gui/hud/ChatHudLine;)V"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
public void chipmunkmod$preventDoubleMessageLogging(Text message, MessageSignatureData signatureData, MessageIndicator indicator, CallbackInfo ci, ChatHudLine chatHudLine) {
// addMessage(message, signature, client.inGameHud.getTicks(), indicator, false);
addVisibleMessage(chatHudLine);
addMessage(chatHudLine);
//addVisibleMessage(chatHudLine);
//addMessage(chatHudLine);
//ci.cancel();
new Throwable().printStackTrace();
}
*/
// super jank
@Inject(method = "logChatMessage", at = @At("HEAD"), cancellable = true)
public void chipmunkmod$temp(ChatHudLine message, CallbackInfo ci) {
ci.cancel();
}
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;logChatMessage(Lnet/minecraft/client/gui/hud/ChatHudLine;)V"), method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
public void chipmunkmod$generalAddMessageMixin(Text message, MessageSignatureData signatureData, MessageIndicator indicator, CallbackInfo ci, ChatHudLine chatHudLine) {
// ChipmunkMod.LOGGER.info("gex");
@Unique
private void customLogChatMessage(ChatHudLine message) {
String string = message.content().getString().replaceAll("\r", "\\\\r").replaceAll("\n", "\\\\n");
String string2 = Nullables.map(message.indicator(), MessageIndicator::loggedName);
if (string2 != null) {
LOGGER.info("[{}] [CHAT] {}", string2, string);
} else {
LOGGER.info("[CHAT] {}", string);
}
}
@Inject(at = @At("HEAD"), method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", cancellable = true)
public void chipmunkmod$generalAddMessageMixin(Text message, MessageSignatureData signatureData, MessageIndicator indicator, CallbackInfo ci) {
ChatHudLine chatHudLine = new ChatHudLine(this.client.inGameHud.getTicks(), message, signatureData, indicator);
if(AntiChatSpamModule.instance.isEnabled && message.equals(AntiChatSpamModule.latestPassedThroughMessage)) {
AntiChatSpamModule.latestPassedThroughMessage = Text.empty();
logChatMessage(chatHudLine);
customLogChatMessage(chatHudLine);
addVisibleMessage(chatHudLine);
addMessage(chatHudLine);
ci.cancel();
return;
}
// ChipmunkMod.LOGGER.info("gex2");
try {
if (RainbowName.INSTANCE.enabled) {
if (message.getString().contains("Your nickname is now ") || message.getString().contains("Nickname changed.")) {
@ -90,8 +117,12 @@ public abstract class ChatHudMixin {
e.printStackTrace();
}
});
ci.cancel();
} else {
customLogChatMessage(chatHudLine);
addVisibleMessage(chatHudLine);
addMessage(chatHudLine);
}
ci.cancel();
}
}

View file

@ -139,7 +139,9 @@ public class Players extends Listener {
final PlayerListEntryAccessor entryAccessor = (PlayerListEntryAccessor) accessor.playerListEntries().get(newEntry.profileId());
entryAccessor.setGameMode(newEntry.gameMode());
if(entryAccessor != null) {
entryAccessor.setGameMode(newEntry.gameMode());
}
} catch (Exception e) {
e.printStackTrace();
}
@ -172,7 +174,10 @@ public class Players extends Listener {
if (accessor == null) return;
accessor.playerListEntries().get(newEntry.profileId()).setDisplayName(newEntry.displayName());
PlayerListEntry oldEntry = accessor.playerListEntries().get(newEntry.profileId());
if(oldEntry != null) {
oldEntry.setDisplayName(newEntry.displayName());
}
}
private void removePlayer (UUID uuid) {