Skip to content

Commit

Permalink
MaxChatLength Client Side Impl
Browse files Browse the repository at this point in the history
  • Loading branch information
senseiwells committed Jul 2, 2022
1 parent 0573d4d commit c65ed04
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public boolean isCarpetManager(String name) {
return this.MANAGERS.contains(name);
}

public CarpetClientRule<?> getRule(String name) {
return this.CURRENT_RULES.get(name);
}

public void onDisconnect() {
this.isServerCarpet = false;
this.CURRENT_RULES.clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.senseiwells.essentialclient.mixins.longChatMessages;

import me.senseiwells.essentialclient.utils.EssentialUtils;
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(ChatMessageC2SPacket.class)
public class ChatMessageC2SPacketMixin {
@ModifyConstant(method = "<init>(Ljava/lang/String;)V", constant = @Constant(intValue = 256))
private int onMaxLength(int constant) {
return EssentialUtils.getMaxChatLength(constant);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.senseiwells.essentialclient.mixins.longChatMessages;

import me.senseiwells.essentialclient.utils.EssentialUtils;
import net.minecraft.client.gui.screen.ChatScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(ChatScreen.class)
public class ChatScreenMixin {
@ModifyConstant(method = "init", constant = @Constant(intValue = 256))
private int getMaxLength(int constant) {
return EssentialUtils.getMaxChatLength(constant);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package me.senseiwells.essentialclient.utils;

import me.senseiwells.essentialclient.feature.CarpetClient;
import me.senseiwells.essentialclient.rule.carpet.CarpetClientRule;
import me.senseiwells.essentialclient.rule.carpet.IntegerCarpetRule;
import me.senseiwells.essentialclient.rule.carpet.StringCarpetRule;
import me.senseiwells.essentialclient.utils.render.Texts;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.MinecraftVersion;
Expand Down Expand Up @@ -123,6 +127,25 @@ public static boolean canMineBlock(ClientPlayerEntity player, BlockPos pos) {
return !state.isAir() && !state.contains(FluidBlock.LEVEL) && state.getHardness(null, null) >= 0;
}

public static int getMaxChatLength(int fallback) {
if (CarpetClient.INSTANCE.isServerCarpet()) {
CarpetClientRule<?> rule = CarpetClient.INSTANCE.getRule("maxChatLength");
if (rule instanceof IntegerCarpetRule intRule) {
int maxLength = intRule.getValue();
if (maxLength > 0) {
return maxLength;
}
}
if (rule instanceof StringCarpetRule stringRule) {
Integer maxLength = catchAsNull(() -> Integer.parseInt(stringRule.getValue()));
if (maxLength != null && maxLength >= 0) {
return maxLength;
}
}
}
return fallback;
}

public static void throwAsRuntime(ThrowableRunnable runnable) {
try {
runnable.run();
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/essentialclient.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"gameRuleSync.RuleInvoker",
"gameRuleSync.RuleMixin",
"keyboard.KeyboardMixin",
"longChatMessages.ChatMessageC2SPacketMixin",
"longChatMessages.ChatScreenMixin"
"mouseScrollRules.MouseMixin",
"openScreenshotDirectory.ScreenshotRecorderMixin",
"overrideCreativeWalkSpeed.LivingEntityMixin",
Expand Down

0 comments on commit c65ed04

Please sign in to comment.