Add custom chat to gui

This commit is contained in:
blackilykat 2024-11-04 22:40:19 +01:00
parent 8b6b7b71fc
commit 9260fb46b2
16 changed files with 59 additions and 47 deletions

View file

@ -4,6 +4,7 @@ import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import land.chipmunk.chipmunkmod.modules.CustomChat;
import land.chipmunk.chipmunkmod.testclient.modules.fun.CustomChatModule;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.text.Text;
@ -39,6 +40,7 @@ public class CustomChatCommand {
final FabricClientCommandSource source = context.getSource();
final boolean bool = getBool(context, "boolean");
CustomChat.INSTANCE.enabled = bool;
CustomChatModule.INSTANCE.isEnabled = bool;
source.sendFeedback(Text.literal("Custom chat is now " + (bool ? "on" : "off")));
return Command.SINGLE_SUCCESS;

View file

@ -1,21 +1,16 @@
package land.chipmunk.chipmunkmod.commands;
import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.SuggestionContext;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.Configuration;
import land.chipmunk.chipmunkmod.modules.SelfCare;
import land.chipmunk.chipmunkmod.testclient.modules.anti_annoyances.SelfCareModule;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.server.ServerMetadata;
import net.minecraft.text.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -73,11 +68,11 @@ public class SelfCareCommand {
SelfCare.INSTANCE.hasSkin = false;
SelfCare.INSTANCE.skin = skin;
if(skin.equals("off")) {
SelfCareModule.instance.skinOption.setOptionValue(false);
SelfCareModule.INSTANCE.skinOption.setOptionValue(false);
source.sendFeedback(Text.literal("Disabled skin self care"));
} else {
SelfCareModule.instance.skinOption.setOptionValue(true);
SelfCareModule.instance.skinUsernameOption.setOptionValue(skin);
SelfCareModule.INSTANCE.skinOption.setOptionValue(true);
SelfCareModule.INSTANCE.skinUsernameOption.setOptionValue(skin);
source.sendFeedback(Text.literal("Skin self care enabled for " + skin + "'s skin"));
}
@ -124,22 +119,22 @@ public class SelfCareCommand {
switch (type) {
case "op" -> {
SelfCare.INSTANCE.opEnabled = bool;
SelfCareModule.instance.opOption.setOptionValue(bool);
SelfCareModule.INSTANCE.opOption.setOptionValue(bool);
source.sendFeedback(Text.literal("The op self care is now " + (bool ? "enabled" : "disabled")));
}
case "gamemode" -> {
SelfCare.INSTANCE.gamemodeEnabled = bool;
SelfCareModule.instance.gmcOption.setOptionValue(bool);
SelfCareModule.INSTANCE.gmcOption.setOptionValue(bool);
source.sendFeedback(Text.literal("The gamemode self care is now " + (bool ? "enabled" : "disabled")));
}
case "cspy" -> {
SelfCare.INSTANCE.cspyEnabled = bool;
SelfCareModule.instance.cspyOption.setOptionValue(bool);
SelfCareModule.INSTANCE.cspyOption.setOptionValue(bool);
source.sendFeedback(Text.literal("The CommandSpy self care is now " + (bool ? "enabled" : "disabled")));
}
case "icu" -> {
SelfCare.INSTANCE.icuEnabled = bool;
SelfCareModule.instance.icuOption.setOptionValue(bool);
SelfCareModule.INSTANCE.icuOption.setOptionValue(bool);
source.sendFeedback(Text.literal("The iControlU self care is now " + (bool ? "enabled" : "disabled")));
}
}

View file

@ -22,7 +22,6 @@ 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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(net.minecraft.client.gui.hud.ChatHud.class)
public abstract class ChatHudMixin {
@ -72,7 +71,7 @@ public abstract class ChatHudMixin {
@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)) {
if(AntiChatSpamModule.INSTANCE.isEnabled && message.equals(AntiChatSpamModule.latestPassedThroughMessage)) {
AntiChatSpamModule.latestPassedThroughMessage = Text.empty();
customLogChatMessage(chatHudLine);
addVisibleMessage(chatHudLine);
@ -102,7 +101,7 @@ public abstract class ChatHudMixin {
// if(pattern.pattern().matcher(message.getString()).matches()) ci.cancel();
// }
// ChipmunkMod.LOGGER.info("gex3");
if(AntiChatSpamModule.instance.isEnabled) {
if(AntiChatSpamModule.INSTANCE.isEnabled) {
Executor.antiChatSpamService.submit(() -> {
try {
Debug.debug("started a run or wahever", "AntiChatSpam.addMessage.future");

View file

@ -1,7 +1,6 @@
package land.chipmunk.chipmunkmod.mixin;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.DecoderException;
import land.chipmunk.chipmunkmod.listeners.Listener;
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
import land.chipmunk.chipmunkmod.testclient.modules.lag_prevention.AntiParticleKickModule;
@ -56,7 +55,7 @@ public class ClientConnectionMixin {
// mabe mabe mabe
// lol i had my own im just gonna cop ypaste that :D
if(packet instanceof ParticleS2CPacket) {
if(AntiParticleKickModule.instance.isEnabled && ((ParticleS2CPacket) packet).getCount()>1000) {
if(AntiParticleKickModule.INSTANCE.isEnabled && ((ParticleS2CPacket) packet).getCount()>1000) {
if(((ParticleS2CPacket) packet).getCount()>1000) Chat.sendGold("ChipmunkMod prevented a particle kick!");
ci.cancel();
}

View file

@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public class ElderGuardianAppearanceParticleMixin {
@Inject(method = "createParticle(Lnet/minecraft/particle/SimpleParticleType;Lnet/minecraft/client/world/ClientWorld;DDDDDD)Lnet/minecraft/client/particle/Particle;", at = @At("HEAD"), cancellable = true)
private void testClient$limitGuardianParticles(SimpleParticleType defaultParticleType, ClientWorld clientWorld, double d, double e, double f, double g, double h, double i, CallbackInfoReturnable<Particle> cir) {
if(BlockGuardianParticlesModule.instance.isEnabled || SharedVariables.elderGuardianParticleTimer > 0) {
if(BlockGuardianParticlesModule.INSTANCE.isEnabled || SharedVariables.elderGuardianParticleTimer > 0) {
cir.setReturnValue(null);
cir.cancel();
}

View file

@ -18,9 +18,9 @@ public class FontStorageMixin {
@Inject(method = "getObfuscatedGlyphRenderer", at = @At("HEAD"), cancellable = true)
private void chipmunkmod$preventObfuscatedGlyphLag(Glyph glyph, CallbackInfoReturnable<GlyphRenderer> cir) {
if(!AntiTextObfuscationLagModule.instance.isEnabled) return;
if(AntiTextObfuscationLagModule.instance.exceededLimitThisTick || Instant.now().toEpochMilli() - AntiTextObfuscationLagModule.instance.renderTimeStart.toEpochMilli() > 18) {
AntiTextObfuscationLagModule.instance.exceededLimitThisTick = true;
if(!AntiTextObfuscationLagModule.INSTANCE.isEnabled) return;
if(AntiTextObfuscationLagModule.INSTANCE.exceededLimitThisTick || Instant.now().toEpochMilli() - AntiTextObfuscationLagModule.INSTANCE.renderTimeStart.toEpochMilli() > 18) {
AntiTextObfuscationLagModule.INSTANCE.exceededLimitThisTick = true;
cir.setReturnValue(blankGlyphRenderer);
}
// Debug.debug("Render time: "+(Instant.now().toEpochMilli() - AntiTextObfuscationLagModule.instance.renderTimeStart.toEpochMilli()), "AntiTextObfuscationLag.mixin");

View file

@ -13,7 +13,7 @@ import java.time.Instant;
public class WorldRendererMixin {
@Inject(method = "render", at = @At("HEAD"))
private void chipmunkmod$saveRenderStartTime(CallbackInfo ci) {
AntiTextObfuscationLagModule.instance.renderTimeStart = Instant.now();
AntiTextObfuscationLagModule.instance.exceededLimitThisTick = false;
AntiTextObfuscationLagModule.INSTANCE.renderTimeStart = Instant.now();
AntiTextObfuscationLagModule.INSTANCE.exceededLimitThisTick = false;
}
}

View file

@ -112,7 +112,7 @@ public class SelfCare extends Listener {
cleanup();
return;
}
if(!SelfCareModule.instance.isEnabled) return;
if(!SelfCareModule.INSTANCE.isEnabled) return;
final ClientPlayerEntity player = client.player;
if (player != null && !player.hasPermissionLevel(2) && opEnabled) { if (serverHasCommand("op")) networkHandler.sendChatCommand("op @s[type=player]"); }
@ -121,7 +121,7 @@ public class SelfCare extends Listener {
}
public void chatTick () {
if(!SelfCareModule.instance.isEnabled) return;
if(!SelfCareModule.INSTANCE.isEnabled) return;
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
if (!cspy && cspyEnabled) { if (serverHasCommand("c")) networkHandler.sendChatCommand("c on"); }

View file

@ -1,10 +1,10 @@
package land.chipmunk.chipmunkmod.testclient.gui;
import land.chipmunk.chipmunkmod.testclient.gui.components.Module;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.testclient.gui.components.Category;
import land.chipmunk.chipmunkmod.testclient.modules.anti_annoyances.AntiChatSpamModule;
import land.chipmunk.chipmunkmod.testclient.modules.anti_annoyances.SelfCareModule;
import land.chipmunk.chipmunkmod.testclient.modules.fun.CustomChatModule;
import land.chipmunk.chipmunkmod.testclient.modules.fun.RainbowNameModule;
import land.chipmunk.chipmunkmod.testclient.modules.lag_prevention.AntiParticleKickModule;
import land.chipmunk.chipmunkmod.testclient.modules.lag_prevention.AntiTextObfuscationLagModule;
@ -162,21 +162,19 @@ Gui extends Screen{
public static void addComponents() {
new Category("Lag prevention")
.withModule(AntiParticleKickModule.instance) //TODO: make kick prevention module
.withModule(BlockGuardianParticlesModule.instance)
.withModule(AntiTextObfuscationLagModule.instance)
.withModule(AntiParticleKickModule.INSTANCE)
.withModule(BlockGuardianParticlesModule.INSTANCE)
.withModule(AntiTextObfuscationLagModule.INSTANCE)
.register();
new Category("Anti annoyances")
.withModule(AntiChatSpamModule.instance)
.withModule(AntiChatSpamModule.INSTANCE)
.withModule(new AntiTeleportModule())
.withModule(SelfCareModule.instance)
.withModule(SelfCareModule.INSTANCE)
.register();
new Category("Fun")
.withModule(RainbowNameModule.instance)
.withModule(RainbowNameModule.INSTANCE)
.withModule(CustomChatModule.INSTANCE)
.register();
// new Category("OP")
// .withModule(AutoOpModule.instance) //TODO: make selfcare module
// .register();
}

View file

@ -11,14 +11,14 @@ import org.apache.commons.text.similarity.LevenshteinDistance;
import java.util.ArrayList;
public class AntiChatSpamModule extends Module {
public static Text latestPassedThroughMessage = Text.empty();
public static AntiChatSpamModule instance = new AntiChatSpamModule();
public ArrayList<ChatMessage> messages = new ArrayList<>();
public static final AntiChatSpamModule INSTANCE = new AntiChatSpamModule();
private static final String debugCallerPrefix = "AntiChatSpam.";
private static final String debugTickedCaller = debugCallerPrefix + "tick";
private static final String debugLevenshteinDistanceCaller = debugCallerPrefix + "levenshtein_distance";
private static final String debugLevenshteinDistanceCallerSpamless = debugCallerPrefix + "levenshtein_distance_spamless";
private static final String debugLevenshteinDistanceCallerSpamful = debugCallerPrefix + "levenshtein_distance_spamful";
public static Text latestPassedThroughMessage = Text.empty();
public ArrayList<ChatMessage> messages = new ArrayList<>();
public AntiChatSpamModule() {
super("Anti chat spam");
@ -44,7 +44,7 @@ public class AntiChatSpamModule extends Module {
this.content = content;
Debug.debug("AAAA", debugLevenshteinDistanceCallerSpamful);
ArrayList<ChatMessage> chatMessages = instance.messages;
ArrayList<ChatMessage> chatMessages = INSTANCE.messages;
Debug.debug("AAAA", debugLevenshteinDistanceCallerSpamful);
int similarMessages = 0;
Debug.debug("AAAA", debugLevenshteinDistanceCallerSpamful);
@ -80,7 +80,7 @@ public class AntiChatSpamModule extends Module {
Debug.debug("CCCC", debugLevenshteinDistanceCallerSpamful);
Debug.debug("Hidden: " + hidden, debugLevenshteinDistanceCaller);
Debug.debug("Hidden: " + hidden, debugLevenshteinDistanceCallerSpamless);
instance.messages.add(this);
INSTANCE.messages.add(this);
Debug.debug("CCCC", debugLevenshteinDistanceCallerSpamful);
// threadQueue.add(() -> {
// // code above used to be here but i cant decide if i should show it or not depending on the thread cuz i cant make it wait
@ -90,7 +90,7 @@ public class AntiChatSpamModule extends Module {
public void tick() {
timer--;
if (timer <= 0) instance.messages.remove(this);
if (timer <= 0) INSTANCE.messages.remove(this);
}
}
}

View file

@ -7,7 +7,7 @@ import land.chipmunk.chipmunkmod.testclient.gui.components.options.BooleanCheckb
import land.chipmunk.chipmunkmod.testclient.gui.components.options.StringOption;
public class SelfCareModule extends Module {
public static SelfCareModule instance = new SelfCareModule();
public static final SelfCareModule INSTANCE = new SelfCareModule();
public BooleanCheckboxOption opOption = new BooleanCheckboxOption(
"OP",
SelfCare.INSTANCE.opEnabled,

View file

@ -0,0 +1,20 @@
package land.chipmunk.chipmunkmod.testclient.modules.fun;
import land.chipmunk.chipmunkmod.modules.CustomChat;
import land.chipmunk.chipmunkmod.testclient.gui.components.Module;
public class CustomChatModule extends Module {
public static final CustomChatModule INSTANCE = new CustomChatModule();
// no format option cause horrors
public CustomChatModule() {
super("Custom chat");
onActivate(() -> {
CustomChat.INSTANCE.enabled = true;
});
onDeactivate(() -> {
CustomChat.INSTANCE.enabled = false;
});
}
}

View file

@ -8,11 +8,10 @@ import land.chipmunk.chipmunkmod.testclient.gui.components.options.IntSliderOpti
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
public class RainbowNameModule extends Module {
public static RainbowNameModule instance = new RainbowNameModule();
public static final RainbowNameModule INSTANCE = new RainbowNameModule();
public static DoubleSliderOption speedOption;
public static IntSliderOption saturationOption;
public static IntSliderOption valueOption;

View file

@ -3,7 +3,7 @@ package land.chipmunk.chipmunkmod.testclient.modules.lag_prevention;
import land.chipmunk.chipmunkmod.testclient.gui.components.Module;
public class AntiParticleKickModule extends Module {
public static AntiParticleKickModule instance = new AntiParticleKickModule();
public static final AntiParticleKickModule INSTANCE = new AntiParticleKickModule();
public AntiParticleKickModule() {
super("Anti particle crash");

View file

@ -5,7 +5,7 @@ import land.chipmunk.chipmunkmod.testclient.gui.components.Module;
import java.time.Instant;
public class AntiTextObfuscationLagModule extends Module {
public static AntiTextObfuscationLagModule instance = new AntiTextObfuscationLagModule();
public static final AntiTextObfuscationLagModule INSTANCE = new AntiTextObfuscationLagModule();
public Instant renderTimeStart = Instant.now();
public boolean exceededLimitThisTick = false;
public AntiTextObfuscationLagModule() {

View file

@ -5,7 +5,7 @@ import land.chipmunk.chipmunkmod.testclient.gui.components.options.StringOption;
import land.chipmunk.chipmunkmod.util.Chat;
public class BlockGuardianParticlesModule extends Module {
public static BlockGuardianParticlesModule instance = new BlockGuardianParticlesModule();
public static final BlockGuardianParticlesModule INSTANCE = new BlockGuardianParticlesModule();
public BlockGuardianParticlesModule() {
super("No guardian particles");