implemented all chat lengths

This commit is contained in:
FlorianMichael 2023-02-26 18:11:23 +01:00
parent d404c5b820
commit 1c30b26a2a
14 changed files with 191 additions and 7 deletions

View File

@ -5,7 +5,7 @@ minecraft_version=1.19.3
yarn_mappings=1.19.3+build.5 yarn_mappings=1.19.3+build.5
loader_version=0.14.14 loader_version=0.14.14
mod_version=1.4.0 mod_version=1.4.1
maven_group=de.florianmichael maven_group=de.florianmichael
archives_base_name=viafabricplus archives_base_name=viafabricplus

View File

@ -6,6 +6,7 @@ import com.viaversion.viaversion.libs.gson.JsonArray;
import com.viaversion.viaversion.libs.gson.JsonObject; import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider; import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import de.florianmichael.viafabricplus.definition.ChatLengthDefinition;
import de.florianmichael.viafabricplus.definition.ItemReleaseVersionDefinition; import de.florianmichael.viafabricplus.definition.ItemReleaseVersionDefinition;
import de.florianmichael.viafabricplus.definition.PackFormatsDefinition; import de.florianmichael.viafabricplus.definition.PackFormatsDefinition;
import de.florianmichael.viafabricplus.definition.v1_19_0.provider.CommandArgumentsProvider; import de.florianmichael.viafabricplus.definition.v1_19_0.provider.CommandArgumentsProvider;
@ -119,6 +120,7 @@ public class ViaFabricPlus {
builder = builder.onProtocolReload(protocolVersion -> { builder = builder.onProtocolReload(protocolVersion -> {
FabricLoader.getInstance().getEntrypoints("viafabricplus", ViaFabricPlusAddon.class).forEach(viaFabricPlusAddon -> viaFabricPlusAddon.onChangeVersion(protocolVersion)); FabricLoader.getInstance().getEntrypoints("viafabricplus", ViaFabricPlusAddon.class).forEach(viaFabricPlusAddon -> viaFabricPlusAddon.onChangeVersion(protocolVersion));
ItemReleaseVersionDefinition.reload(protocolVersion); ItemReleaseVersionDefinition.reload(protocolVersion);
ChatLengthDefinition.reload(protocolVersion);
}); });
builder.build(); builder.build();

View File

@ -0,0 +1,29 @@
package de.florianmichael.viafabricplus.definition;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.vialoadingbase.platform.ComparableProtocolVersion;
import net.minecraft.client.MinecraftClient;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
public class ChatLengthDefinition {
private static int maxLength = 256;
public static void reload(final ComparableProtocolVersion protocolVersion) {
maxLength = 256;
if (protocolVersion.isOlderThanOrEqualTo(ProtocolVersion.v1_10)) {
maxLength = 100;
if (protocolVersion.isOlderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
maxLength = 64 - MinecraftClient.getInstance().getSession().getUsername().length() - 2;
}
}
}
public static void expand() {
maxLength = Short.MAX_VALUE * 2;
}
public static int getMaxLength() {
return maxLength;
}
}

View File

@ -1,6 +1,7 @@
package de.florianmichael.viafabricplus.injection.mixin.base; package de.florianmichael.viafabricplus.injection.mixin.base;
import de.florianmichael.viafabricplus.screen.ProtocolSelectionScreen; import de.florianmichael.viafabricplus.screen.ProtocolSelectionScreen;
import de.florianmichael.viafabricplus.value.ValueHolder;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen; import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget;
@ -19,6 +20,16 @@ public class MixinMultiplayerScreen extends Screen {
@Inject(method = "init", at = @At("RETURN")) @Inject(method = "init", at = @At("RETURN"))
public void addProtocolSelectionButton(CallbackInfo ci) { public void addProtocolSelectionButton(CallbackInfo ci) {
this.addDrawableChild(ButtonWidget.builder(Text.literal("ViaFabricPlus"), button -> ProtocolSelectionScreen.open(this)).position(width - 98, 0).size(98, 20).build()); ButtonWidget.Builder builder = ButtonWidget.builder(Text.literal("ViaFabricPlus"), button -> ProtocolSelectionScreen.open(this));
final int orientation = ValueHolder.mainButtonOrientation.getIndex();
switch (orientation) {
case 0 -> builder = builder.position(0, 0);
case 1 -> builder = builder.position(width - 98, 0);
case 2 -> builder = builder.position(0, height - 20);
case 3 -> builder = builder.position(width - 98, height - 20);
}
this.addDrawableChild(builder.size(98, 20).build());
} }
} }

View File

@ -0,0 +1,16 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes;
import de.florianmichael.viafabricplus.definition.ChatLengthDefinition;
import net.minecraft.util.StringHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
@Mixin(StringHelper.class)
public class MixinStringHelper {
@ModifyConstant(method = "truncateChat", constant = @Constant(intValue = 256))
private static int expandChatLength(int constant) {
return ChatLengthDefinition.getMaxLength();
}
}

View File

@ -0,0 +1,16 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.packet;
import de.florianmichael.viafabricplus.definition.ChatLengthDefinition;
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 MixinChatMessageC2SPacket {
@ModifyConstant(method = "write", constant = @Constant(intValue = 256))
public int expandChatLength(int constant) {
return ChatLengthDefinition.getMaxLength();
}
}

View File

@ -0,0 +1,21 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.screen;
import de.florianmichael.viafabricplus.definition.ChatLengthDefinition;
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.callback.CallbackInfo;
@Mixin(ChatScreen.class)
public class MixinChatScreen {
@Shadow protected TextFieldWidget chatField;
@Inject(method = "init", at = @At("RETURN"))
public void changeChatLength(CallbackInfo ci) {
this.chatField.setMaxLength(ChatLengthDefinition.getMaxLength());
}
}

View File

@ -0,0 +1,20 @@
package de.florianmichael.viafabricplus.injection.mixin.vialegacy;
import de.florianmichael.viafabricplus.definition.ChatLengthDefinition;
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.data.ClassicProtocolExtension;
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.storage.ExtensionProtocolMetadataStorage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = ExtensionProtocolMetadataStorage.class, remap = false)
public class MixinExtensionProtocolMetadataStorage {
@Inject(method = "addServerExtension", at = @At("RETURN"))
public void updateChatLengthDefinition(ClassicProtocolExtension extension, int version, CallbackInfo ci) {
if (extension == ClassicProtocolExtension.LONGER_MESSAGES) {
ChatLengthDefinition.expand();
}
}
}

View File

@ -0,0 +1,15 @@
package de.florianmichael.viafabricplus.injection.mixin.viaversion.protocol1_11to1_10;
import de.florianmichael.viafabricplus.definition.ChatLengthDefinition;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
@Mixin(targets = "com.viaversion.viaversion.protocols.protocol1_11to1_10.Protocol1_11To1_10$13", remap = false)
public class MixinProtocol1_11To1_10 {
@ModifyConstant(method = "lambda$register$0", constant = @Constant(intValue = 100))
private static int changeMaxChatLength(int constant) {
return ChatLengthDefinition.getMaxLength();
}
}

View File

@ -36,8 +36,6 @@ public class ProtocolSelectionScreen extends Screen {
this.addDrawableChild(new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, height + 5, textRenderer.fontHeight + 2)); this.addDrawableChild(new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, height + 5, textRenderer.fontHeight + 2));
this.addDrawableChild(ButtonWidget.builder(Text.literal("<-"), button -> this.close()).position(0, height - 20).size(20, 20).build()); this.addDrawableChild(ButtonWidget.builder(Text.literal("<-"), button -> this.close()).position(0, height - 20).size(20, 20).build());
this.addDrawableChild(ButtonWidget.builder(Text.literal("Values"), button -> ValuesScreen.open(this)).position(0, 0).size(98, 20).build());
} }
@Override @Override

View File

@ -4,6 +4,7 @@ import de.florianmichael.viafabricplus.util.ScreenUtil;
import de.florianmichael.viafabricplus.value.AbstractValue; import de.florianmichael.viafabricplus.value.AbstractValue;
import de.florianmichael.viafabricplus.value.ValueHolder; import de.florianmichael.viafabricplus.value.ValueHolder;
import de.florianmichael.viafabricplus.value.impl.BooleanValue; import de.florianmichael.viafabricplus.value.impl.BooleanValue;
import de.florianmichael.viafabricplus.value.impl.ModeValue;
import de.florianmichael.viafabricplus.value.impl.ProtocolSyncBooleanValue; import de.florianmichael.viafabricplus.value.impl.ProtocolSyncBooleanValue;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer; import net.minecraft.client.font.TextRenderer;
@ -16,6 +17,8 @@ import net.minecraft.util.Formatting;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import java.awt.*; import java.awt.*;
import java.text.Format;
import java.util.Arrays;
@SuppressWarnings({"DataFlowIssue", "DuplicatedCode"}) @SuppressWarnings({"DataFlowIssue", "DuplicatedCode"})
public class ValuesScreen extends Screen { public class ValuesScreen extends Screen {
@ -100,6 +103,11 @@ public class ValuesScreen extends Screen {
ScreenUtil.playClickSound(); ScreenUtil.playClickSound();
} }
} }
if (value instanceof ModeValue modeValue) {
final int currentIndex = Arrays.stream(modeValue.getOptions()).toList().indexOf(modeValue.value) + 1;
modeValue.setValue(currentIndex > modeValue.getOptions().length - 1 ? 0 : currentIndex);
ScreenUtil.playClickSound();
}
return super.mouseClicked(mouseX, mouseY, button); return super.mouseClicked(mouseX, mouseY, button);
} }
@ -111,14 +119,16 @@ public class ValuesScreen extends Screen {
final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
if (value instanceof BooleanValue booleanValue) { if (value instanceof BooleanValue booleanValue) {
final boolean isEnabled = booleanValue.getValue(); final boolean isEnabled = booleanValue.getValue();
drawCenteredText(matrices, textRenderer, (isEnabled ? Formatting.UNDERLINE : "") + booleanValue.getName(), entryWidth / 2, entryHeight / 2 - textRenderer.fontHeight / 2, isEnabled ? Color.GREEN.getRGB() : Color.RED.getRGB()); drawStringWithShadow(matrices, textRenderer, booleanValue.getName(), 3, entryHeight / 2 - textRenderer.fontHeight / 2, isEnabled ? Color.GREEN.getRGB() : Color.RED.getRGB());
} else if (value instanceof ProtocolSyncBooleanValue protocolSyncBooleanValue) { } else if (value instanceof ProtocolSyncBooleanValue protocolSyncBooleanValue) {
final boolean isEnabled = protocolSyncBooleanValue.getValue(); final boolean isEnabled = protocolSyncBooleanValue.getValue();
Color color = isEnabled ? Color.GREEN : Color.RED; Color color = isEnabled ? Color.GREEN : Color.RED;
if (protocolSyncBooleanValue.isSyncWithProtocol()) { if (protocolSyncBooleanValue.isSyncWithProtocol()) {
drawStringWithShadow(matrices, textRenderer, "Sync", entryWidth - textRenderer.getWidth("Sync") - 3, entryHeight / 2 - textRenderer.fontHeight / 2, Color.ORANGE.getRGB()); drawStringWithShadow(matrices, textRenderer, "Sync", entryWidth - textRenderer.getWidth("Sync") - 3, entryHeight / 2 - textRenderer.fontHeight / 2, Color.ORANGE.getRGB());
} }
drawStringWithShadow(matrices, textRenderer, (isEnabled ? Formatting.UNDERLINE.toString() : "") + protocolSyncBooleanValue.getName(), 3, entryHeight / 2 - textRenderer.fontHeight / 2, color.getRGB()); drawStringWithShadow(matrices, textRenderer, protocolSyncBooleanValue.getName(), 3, entryHeight / 2 - textRenderer.fontHeight / 2, color.getRGB());
} else if (value instanceof ModeValue modeValue) {
drawStringWithShadow(matrices, textRenderer, modeValue.getName() + ": " + Formatting.GOLD + modeValue.getValue(), 3, entryHeight / 2 - textRenderer.fontHeight / 2, -1);
} }
matrices.pop(); matrices.pop();
} }

View File

@ -3,6 +3,7 @@ package de.florianmichael.viafabricplus.value;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.platform.ProtocolRange; import de.florianmichael.viafabricplus.platform.ProtocolRange;
import de.florianmichael.viafabricplus.value.impl.BooleanValue; import de.florianmichael.viafabricplus.value.impl.BooleanValue;
import de.florianmichael.viafabricplus.value.impl.ModeValue;
import de.florianmichael.viafabricplus.value.impl.ProtocolSyncBooleanValue; import de.florianmichael.viafabricplus.value.impl.ProtocolSyncBooleanValue;
import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.api.LegacyProtocolVersion;
@ -13,6 +14,7 @@ public class ValueHolder {
public final static List<AbstractValue<?>> values = new ArrayList<>(); public final static List<AbstractValue<?>> values = new ArrayList<>();
// General settings // General settings
public static final ModeValue mainButtonOrientation = new ModeValue("Main button orientation", "Left; Top", "Right; Top", "Left; Bottom", "Right: Bottom");
public static final BooleanValue removeNotAvailableItemsFromCreativeTab = new BooleanValue("Remove not available items from creative tab", true); public static final BooleanValue removeNotAvailableItemsFromCreativeTab = new BooleanValue("Remove not available items from creative tab", true);
// 1.19 -> 1.18.2 // 1.19 -> 1.18.2

View File

@ -0,0 +1,39 @@
package de.florianmichael.viafabricplus.value.impl;
import com.google.gson.JsonObject;
import de.florianmichael.viafabricplus.value.AbstractValue;
import java.util.Arrays;
public class ModeValue extends AbstractValue<String> {
private final String[] options;
public ModeValue(String name, String... options) {
super(name, options[0]);
this.options = options;
}
@Override
public void write(JsonObject object) {
object.addProperty(getName(), getValue());
}
@Override
public void read(JsonObject object) {
if (!object.has(getName())) return;
setValue(object.get(getName()).getAsString());
}
public void setValue(int index) {
super.setValue(options[index]);
}
public int getIndex() {
return Arrays.stream(options).toList().indexOf(getValue());
}
public String[] getOptions() {
return options;
}
}

View File

@ -21,6 +21,7 @@
"fixes.MixinProfileKeysImpl", "fixes.MixinProfileKeysImpl",
"fixes.MixinServerAddress", "fixes.MixinServerAddress",
"fixes.MixinServerResourcePackProvider", "fixes.MixinServerResourcePackProvider",
"fixes.MixinStringHelper",
"fixes.block.MixinAbstractBlock_AbstractBlockState", "fixes.block.MixinAbstractBlock_AbstractBlockState",
"fixes.block.MixinAnvilBlock", "fixes.block.MixinAnvilBlock",
"fixes.block.MixinBambooBlock", "fixes.block.MixinBambooBlock",
@ -79,6 +80,7 @@
"fixes.item.MixinPickaxeItem", "fixes.item.MixinPickaxeItem",
"fixes.item.MixinShovelItem", "fixes.item.MixinShovelItem",
"fixes.item.MixinSwordItem", "fixes.item.MixinSwordItem",
"fixes.packet.MixinChatMessageC2SPacket",
"fixes.packet.MixinPacketByteBuf", "fixes.packet.MixinPacketByteBuf",
"fixes.packet.MixinUpdatePlayerAbilitiesC2SPacket", "fixes.packet.MixinUpdatePlayerAbilitiesC2SPacket",
"fixes.screen.MixinConnectScreen_1", "fixes.screen.MixinConnectScreen_1",
@ -94,11 +96,13 @@
"fixes.screen.screenhandler.MixinScreenHandler", "fixes.screen.screenhandler.MixinScreenHandler",
"sodium.MixinChunkTracker", "sodium.MixinChunkTracker",
"viaaprilfools.MixinProtocol1_16to20w14infinite", "viaaprilfools.MixinProtocol1_16to20w14infinite",
"vialegacy.MixinExtensionProtocolMetadataStorage",
"vialegacy.MixinProtocol1_8to1_7_6_10", "vialegacy.MixinProtocol1_8to1_7_6_10",
"vialoadingbase.MixinCustomViaConfig", "vialoadingbase.MixinCustomViaConfig",
"viaversion.MixinCommonBoss", "viaversion.MixinCommonBoss",
"viaversion.MixinPacketWrapperImpl", "viaversion.MixinPacketWrapperImpl",
"viaversion.MixinProtocolVersion", "viaversion.MixinProtocolVersion",
"viaversion.protocol1_11to1_10.MixinProtocol1_11To1_10",
"viaversion.protocol1_12to1_11_1.MixinChatItemRewriter", "viaversion.protocol1_12to1_11_1.MixinChatItemRewriter",
"viaversion.protocol1_13to1_12_2.MixinAbstractFenceConnectionHandler", "viaversion.protocol1_13to1_12_2.MixinAbstractFenceConnectionHandler",
"viaversion.protocol1_13to1_12_2.MixinGlassConnectionHandler", "viaversion.protocol1_13to1_12_2.MixinGlassConnectionHandler",
@ -128,6 +132,7 @@
"client": [ "client": [
"base.MixinOptionsScreen", "base.MixinOptionsScreen",
"bridge.MixinConnectScreen", "bridge.MixinConnectScreen",
"bridge.MixinDownloadingTerrainScreen" "bridge.MixinDownloadingTerrainScreen",
"fixes.screen.MixinChatScreen"
] ]
} }