Experimental logless chat messages

This commit is contained in:
Levent
2026-03-12 22:36:33 +00:00
parent a22e3f53ff
commit 712ae97235
10 changed files with 90 additions and 19 deletions
@@ -0,0 +1,9 @@
package me.alpha432.oyvey.ducks.render;
import net.minecraft.client.GuiMessage;
import net.minecraft.network.chat.MessageSignature;
public interface IChatComponent {
void oyvey$addMessage(GuiMessage message);
void oyvey$removeMessage(MessageSignature signature);
}
@@ -25,7 +25,7 @@ public abstract class Command extends Feature {
public abstract void createArgumentBuilder(LiteralArgumentBuilder<CommandManager> builder);
protected int success(String message, Object... format) {
sendMessage(message, format);
sendMessage(message, "success", format);
return NO_OP;
}
@@ -34,7 +34,7 @@ public abstract class Command extends Feature {
}
protected int fail(String message, Object... format) {
sendMessage("{red} " + message, format);
sendMessage("{red} " + format, "fail");
return NO_OP;
}
@@ -58,11 +58,18 @@ public abstract class Command extends Feature {
return true;
}
public static void sendMessage(String message, Object... format) {
public static void sendMessage(String message, String identifier) {
if (message == null) {
return;
}
ChatUtil.sendMessage(TextUtil.text(message, format));
ChatUtil.sendMessage(TextUtil.text(message), identifier);
}
public static void sendMessage(String message, String identifier, Object... format) {
if (message == null) {
return;
}
ChatUtil.sendMessage(TextUtil.text(message, format), identifier);
}
public static LiteralArgumentBuilder<CommandManager> literal(String literal) {
@@ -40,7 +40,7 @@ public class BindCommand extends Command {
if (event.getKey() == GLFW_KEY_ESCAPE) {
module = null;
sendMessage("Operation canceled.");
sendMessage("Operation canceled.", "fail");
return;
}
@@ -66,7 +66,7 @@ public class HelpCommand extends Command {
List<Command> paginated = commands.subList((pageIndex - 1) * ITEMS_PER_PAGE,
Math.min(commands.size(), pageIndex * ITEMS_PER_PAGE));
sendMessage("Commands (%s):", commands.size());
sendMessage("Commands (%s):", "general", commands.size());
for (Command command : paginated) {
StringJoiner joiner = new StringJoiner(", ");
@@ -74,7 +74,7 @@ public class HelpCommand extends Command {
joiner.add(alias);
}
sendMessage("{dark_gray} %s: {reset}\n %s",
sendMessage("{dark_gray} %s: {reset}\n %s", "general",
joiner, command.getDescription());
}
@@ -88,11 +88,11 @@ public class Module extends Feature implements Jsonable, Toggleable {
Module module = OyVey.moduleManager.getModuleByDisplayName(name);
Module originalModule = OyVey.moduleManager.getModuleByName(name);
if (module == null && originalModule == null) {
Command.sendMessage(this.getDisplayName() + ", name: " + this.getName() + ", has been renamed to: " + name);
Command.sendMessage(this.getDisplayName() + ", name: " + this.getName() + ", has been renamed to: " + name, "general");
this.displayName.setValue(name);
return;
}
Command.sendMessage("{red} A module of this name already exists.");
Command.sendMessage("{red} A module of this name already exists.", "general");
}
@Override
@@ -28,6 +28,6 @@ public class NotificationsModule extends Module {
ChatUtil.sendMessage(TextUtil.text(MODULE_FORMAT,
event.getFeature().getName(),
moduleState ? "{green}" : "{red}",
moduleState ? "on" : "off"));
moduleState ? "on" : "off"), event.getFeature().getName());
}
}
@@ -48,9 +48,9 @@ public class CommandManager extends Feature implements Jsonable {
int result = dispatcher.execute(message.substring(
commandPrefix.length()).trim(), this);
if (result == SINGLE_SUCCESS) {
Command.sendMessage("{green} Command executed successfully");
Command.sendMessage("{green} Command executed successfully", "general");
} else if (result == SINGLE_FAILURE) {
Command.sendMessage("{red} Failed to execute command");
Command.sendMessage("{red} Failed to execute command", "general");
}
} catch (CommandSyntaxException e) {
LOGGER.error("Failed to execute command", e);
@@ -0,0 +1,32 @@
package me.alpha432.oyvey.mixin.render;
import me.alpha432.oyvey.ducks.render.IChatComponent;
import net.minecraft.client.GuiMessage;
import net.minecraft.client.gui.components.ChatComponent;
import net.minecraft.network.chat.MessageSignature;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.List;
@Mixin(ChatComponent.class)
public abstract class MixinChatComponent implements IChatComponent {
@Shadow
private List<GuiMessage> allMessages;
@Shadow
private void refreshTrimmedMessages() {}
@Override
public void oyvey$addMessage(GuiMessage message) {
this.allMessages.addFirst(message);
this.refreshTrimmedMessages();
}
@Override
public void oyvey$removeMessage(MessageSignature signature) {
this.allMessages.removeIf(message -> signature.equals(message.signature()));
this.refreshTrimmedMessages();
}
}
@@ -1,33 +1,55 @@
package me.alpha432.oyvey.util.player;
import me.alpha432.oyvey.OyVey;
import me.alpha432.oyvey.ducks.render.IChatComponent;
import me.alpha432.oyvey.features.commands.Command;
import net.minecraft.ChatFormatting;
import net.minecraft.client.GuiMessage;
import net.minecraft.client.GuiMessageTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MessageSignature;
import net.minecraft.network.chat.Style;
import java.nio.charset.StandardCharsets;
import static me.alpha432.oyvey.util.traits.Util.mc;
public class ChatUtil {
public static void sendMessage(Component message) {
sendSilentMessage(Component.empty()
private static final GuiMessageTag MESSAGE_TAG = new GuiMessageTag(
OyVey.colorManager.getColorAsInt(),
null,
null,
null
);
public static void sendMessage(Component message, String identifier) {
sendClientSideMessage(Component.empty()
.setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY))
.append("<")
.append(getClientNameComponent())
.append(">")
.append(" ")
.append(message));
.append(message), identifier);
}
public static void sendSilentMessage(Component message) {
public static void sendClientSideMessage(Component message, String identifier) {
if (Command.nullCheck()) {
return;
}
// TODO add silent support ig
mc.gui.getChat().addMessage(message);
IChatComponent chat = (IChatComponent) mc.gui.getChat();
MessageSignature signature = new MessageSignature(get256Bytes(identifier));
chat.oyvey$removeMessage(signature);
chat.oyvey$addMessage(new GuiMessage(mc.gui.getGuiTicks(), message, signature, MESSAGE_TAG));
}
public static Component getClientNameComponent() {
return Component.empty().withColor(OyVey.colorManager.getColorAsInt()).append("OyVey");
}
private static byte[] get256Bytes(String identifier) {
byte[] bytes = new byte[256];
byte[] identifierBytes = identifier.getBytes(StandardCharsets.UTF_8);
System.arraycopy(identifierBytes, 0, bytes, 0, Math.min(bytes.length, identifierBytes.length));
return bytes;
}
}
+1
View File
@@ -11,6 +11,7 @@
"input.MixinKeyboard",
"input.MixinMouse",
"network.MixinClientPlayNetworkHandler",
"render.MixinChatComponent",
"render.MixinLevelRenderer",
"render.MixinRenderTickCounter",
"render.MixinWorldRenderer",