Skip to content

Commit

Permalink
dynamically set max length again
Browse files Browse the repository at this point in the history
  • Loading branch information
StupidRepo committed Mar 26, 2024
1 parent 4f82a44 commit 09b1980
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.arguments.item.ItemInput;
import net.minecraft.network.chat.Component;
Expand All @@ -30,7 +29,7 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
dispatcher.register(literal("giveme")
.then(argument("item", itemStack(context)).executes(ctx -> give(ctx.getSource(), getCItemStackArgument(ctx, "item"), 1))
.then(argument("count", integer(1)).executes(ctx -> give(ctx.getSource(), getCItemStackArgument(ctx, "item"), getInteger(ctx, "count"))))));
LOGGER.info("Registered /giveme command");
LOGGER.info("Registered the giveme command");
}

private static int give(FabricClientCommandSource source, ItemInput itemInput, int count) throws CommandSyntaxException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.stupidrepo.giveme.client.mixins;

import com.stupidrepo.giveme.client.GiveMeClient;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.screens.ChatScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
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.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Objects;

@Mixin(ChatScreen.class)
public class ChatScreenMixin extends Screen {
protected ChatScreenMixin(Component component) {
Expand All @@ -29,21 +30,15 @@ protected ChatScreenMixin(Component component) {

@Inject(method = "onEdited", at = @At("TAIL"))
protected void onEdited(String string, CallbackInfo ci) {
if(string.startsWith("/giveme")) {
this.input.setMaxLength(Integer.MAX_VALUE);
} else {
this.input.setMaxLength(256);
}
var m = Objects.equals(string.split(" ")[0].trim(), "/giveme") ? Integer.MAX_VALUE : GiveMeClient.MAX_MESSAGE_LENGTH;
this.input.setMaxLength(m);
}

// @Inject(method = "normalizeChatMessage", at = @At("HEAD"), cancellable = true)
// protected void normalizeChatMessage(String string, CallbackInfoReturnable<String> cir) {
// if(string.length() > 256) {
// if(string.startsWith("/giveme")) {
// cir.setReturnValue(string);
// } else {
// cir.setReturnValue(StringUtil.trimChatMessage(StringUtils.normalizeSpace(string.trim())));
// }
// }
// }
@Inject(method = "normalizeChatMessage", at = @At("HEAD"), cancellable = true)
protected void normalizeChatMessage(String string, CallbackInfoReturnable<String> cir) {
if(Objects.equals(string.split(" ")[0].trim(), "/giveme")) {
cir.cancel();
cir.setReturnValue(string);
}
}
}

0 comments on commit 09b1980

Please sign in to comment.