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

Ignore text size if starts with command (. by default) #262

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
50 changes: 50 additions & 0 deletions src/main/java/anticope/rejects/mixin/ChatScreenMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package anticope.rejects.mixin;

import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.misc.BetterChat;
import meteordevelopment.meteorclient.systems.config.Config;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ChatScreen.class)
public abstract class ChatScreenMixin {
@Shadow protected TextFieldWidget chatField;

@Inject(method = "onChatFieldUpdate", at = @At("HEAD"))
private void onChatFieldUpdate(String chatText, CallbackInfo ci) {
setCommandMaxLength(chatText);
}

@ModifyArg(method = "setChatFromHistory", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TextFieldWidget;setText(Ljava/lang/String;)V"))
private String setText(String text) {
setCommandMaxLength(text);
return text;
}

private void setCommandMaxLength(String message) {
String prefix = Config.get().prefix.get();

if (message.startsWith(prefix) || (Modules.get().get(BetterChat.class).isInfiniteChatBox()))
chatField.setMaxLength(Integer.MAX_VALUE);
else {
if (chatField.getCursor() > 256)
chatField.setCursor(Math.min(256, chatField.getText().length()));
chatField.setMaxLength(256);
}
}

@Inject(method = "normalize", at = @At(value = "HEAD"), cancellable = true)
private void avoidNormalizeWithCommand(String str, CallbackInfoReturnable<String> cir) {
String prefix = Config.get().prefix.get();

if (str.startsWith(prefix) || (Modules.get().get(BetterChat.class).isInfiniteChatBox()))
cir.setReturnValue(str);
}
}
4 changes: 3 additions & 1 deletion src/main/resources/meteor-rejects.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"TexturedRenderLayersMixin",
"ToastManagerMixin",
"VehicleMoveC2SPacketAccessor",
"baritone.MineProcessMixin"
"baritone.MineProcessMixin",
"MixinEntity",
"ChatScreenMixin"
yorik100 marked this conversation as resolved.
Show resolved Hide resolved
],
"injectors": {
"defaultRequire": 1
Expand Down