Update to 1.19.3
ci/woodpecker/push/jfmod Pipeline was successful Details
ci/woodpecker/tag/jfmod Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2022-12-08 18:06:28 +01:00
parent c3d91d61b3
commit 0e2b1f034d
Signed by: Johannes
GPG Key ID: E76429612C2929F4
8 changed files with 48 additions and 33 deletions

View File

@ -15,5 +15,5 @@ dependencies {
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-config-reflect-v1:${prop("libjf_version")}")
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-config-ui-tiny-v1:${prop("libjf_version")}")
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-devutil:${prop("libjf_version")}")
modLocalRuntime("com.terraformersmc:modmenu:4.1.1")
modLocalRuntime("com.terraformersmc:modmenu:5.0.1")
}

View File

@ -1,6 +1,6 @@
# https://fabricmc.net/develop/
minecraft_version=1.19.2
yarn_mappings=build.24
minecraft_version=1.19.3
yarn_mappings=build.2
loader_version=0.14.11
maven_group=io.gitlab.jfronny
@ -13,5 +13,5 @@ curseforge_id=574331
curseforge_required_dependencies=libjf
curseforge_optional_dependencies=modmenu
libjf_version=3.2.1
fabric_version=0.68.0+1.19.2
libjf_version=3.3.1
fabric_version=0.68.1+1.19.3

View File

@ -1,14 +1,15 @@
package io.gitlab.jfronny.googlechat.mixin;
import io.gitlab.jfronny.googlechat.*;
import io.gitlab.jfronny.libjf.LibJf;
import net.minecraft.client.gui.screen.*;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
@Mixin(ChatScreen.class)
public class ChatScreenMixin {
@ModifyVariable(method = "tryRequestChatPreview(Ljava/lang/String;)V", at = @At(value = "HEAD"), argsOnly = true, ordinal = 0)
String googlechat$translateChatText(String source) {
return GoogleChat.translateIfNeeded(source, GoogleChat.Direction.C2S, true);
@ModifyVariable(method = "sendMessage(Ljava/lang/String;Z)Z", at = @At(value = "HEAD"), argsOnly = true, ordinal = 0)
String googlechat$translateChatText(String chatText) {
return GoogleChat.translateIfNeeded(chatText, GoogleChat.Direction.C2S, true);
}
}

View File

@ -1,14 +1,16 @@
package io.gitlab.jfronny.googlechat.mixin;
import io.gitlab.jfronny.googlechat.*;
import net.minecraft.client.network.*;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
import io.gitlab.jfronny.googlechat.GoogleChat;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
@Mixin(ClientPlayerEntity.class)
public class ClientPlayerEntityMixin {
@ModifyVariable(method = "sendChatMessage(Ljava/lang/String;Lnet/minecraft/text/Text;)V", at = @At("HEAD"), argsOnly = true, ordinal = 0)
String googlechat$translateMessage(String source) {
@ModifyVariable(method = "sendMessage(Lnet/minecraft/text/Text;)V", at = @At("HEAD"), argsOnly = true, ordinal = 0)
Text googlechat$translateMessage(Text source) {
return GoogleChat.translateIfNeeded(source, GoogleChat.Direction.C2S, true);
}
}

View File

@ -1,35 +1,43 @@
package io.gitlab.jfronny.googlechat.mixin;
import com.mojang.authlib.GameProfile;
import io.gitlab.jfronny.googlechat.GoogleChat;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.ChatHud;
import net.minecraft.client.gui.hud.MessageIndicator;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.network.message.MessageHandler;
import net.minecraft.network.message.*;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.message.SignedMessage;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import java.time.Instant;
@Mixin(MessageHandler.class)
public class MessageHandlerMixin {
@Redirect(method = "processChatMessageInternal(Lnet/minecraft/network/message/MessageType$Parameters;Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/text/Text;Lnet/minecraft/client/network/PlayerListEntry;ZLjava/time/Instant;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V"))
void googlechat$injectAddMessage(ChatHud instance, Text message, @Nullable MessageSignatureData signature, @Nullable MessageIndicator indicator, MessageType.Parameters args$params, SignedMessage args$message, Text args$decorated, @Nullable PlayerListEntry args$senderEntry, boolean args$onlyShowSecureChat, Instant args$receptionTimestamp) {
MinecraftClient mc = MinecraftClient.getInstance();
if (mc != null && mc.player != null && args$senderEntry != null && !args$senderEntry.getProfile().getId().equals(mc.player.getUuid()))
message = googlechat$translate(message);
instance.addMessage(message, signature, indicator);
@Redirect(method = "onChatMessage(Lnet/minecraft/network/message/SignedMessage;Lcom/mojang/authlib/GameProfile;Lnet/minecraft/network/message/MessageType$Parameters;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageType$Parameters;applyChatDecoration(Lnet/minecraft/text/Text;)Lnet/minecraft/text/Text;"))
Text googlechat$applyDecoration(MessageType.Parameters instance, Text content, SignedMessage args$signed, GameProfile args$sender) {
return instance.applyChatDecoration(googlechat$shouldTranslate(args$sender) ? googlechat$translate(content) : content);
}
@Redirect(method = "processProfilelessMessage(Lnet/minecraft/network/message/MessageType$Parameters;Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/text/Text;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;addMessage(Lnet/minecraft/text/Text;)V"))
void googlechat$injectAddMessage(ChatHud instance, Text message) {
instance.addMessage(googlechat$translate(message));
@Redirect(method = "processChatMessageInternal(Lnet/minecraft/network/message/MessageType$Parameters;Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/text/Text;Lcom/mojang/authlib/GameProfile;ZLjava/time/Instant;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageType$Parameters;applyChatDecoration(Lnet/minecraft/text/Text;)Lnet/minecraft/text/Text;"))
Text googlechat$applyDecoration2(MessageType.Parameters instance, Text content, MessageType.Parameters args$params, SignedMessage args$message, Text args$decorated, GameProfile args$sender) {
return instance.applyChatDecoration(googlechat$shouldTranslate(args$sender) ? googlechat$translate(content) : content);
}
@ModifyVariable(method = "onProfilelessMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageType$Parameters;)V", at = @At(value = "HEAD"), argsOnly = true, ordinal = 0)
Text googlechat$applyTranslation(Text origin) {
return googlechat$translate(origin);
}
@ModifyVariable(method = "onGameMessage(Lnet/minecraft/text/Text;Z)V", at = @At(value = "HEAD"), argsOnly = true, ordinal = 0)
Text googlechat$applyTranslation2(Text origin) {
return googlechat$translate(origin);
}
private Text googlechat$translate(Text message) {
return GoogleChat.translateIfNeeded(message, GoogleChat.Direction.S2C, true);
}
private boolean googlechat$shouldTranslate(GameProfile sender) {
MinecraftClient mc = MinecraftClient.getInstance();
return mc != null && mc.player != null && sender != null && !sender.getId().equals(mc.player.getUuid());
}
}

View File

@ -41,6 +41,7 @@ public class GoogleChat implements ModInitializer {
return source;
if (GoogleChatConfig.desugar) {
MutableText translatedText = Text.literal(translateIfNeeded(sourceString, direction, true));
if (GoogleChatConfig.debugLogs) LOGGER.info("Translated " + sourceString + " to " + toString(translatedText));
if (GoogleChatConfig.translationTooltip)
return source.copy().setStyle(addHover(Style.EMPTY, Text.literal("Translated: ").append(translatedText)));
else
@ -110,7 +111,7 @@ public class GoogleChat implements ModInitializer {
}
private static boolean hasTarget(Direction direction) {
return TRANSLATE_SERVICE.parseLang(switch (direction) {
return !TRANSLATE_SERVICE.parseLang(switch (direction) {
case C2S -> GoogleChatConfig.serverLanguage;
case S2C -> GoogleChatConfig.clientLanguage;
}).getIdentifier().equals("auto");

View File

@ -44,8 +44,9 @@ public class GoogleChatConfig {
@Verifier
public static void verify() {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER && !clientLanguage.equals("auto")) {
System.err.println("Your client language is not set to \"auto\" and you are using a server.\n"
+ "This setup is not recommended! Please set up GoogleChat according to its documentation!");
System.err.println("""
Your client language is not set to "auto" and you are using a server.
This setup is not recommended! Please set up GoogleChat according to its documentation!""");
}
}
}

View File

@ -18,6 +18,8 @@
"google-chat.jfconfig.sendingRegex.tooltip": "A Regex pattern to check whether a sent message should be translated",
"google-chat.jfconfig.sendingRegexIsBlacklist": "Sending Regex Is Blacklist",
"google-chat.jfconfig.sendingRegexIsBlacklist.tooltip": "Whether the relevant regex should blacklist messages from translation instead of whitelisting",
"google-chat.jfconfig.debugLogs": "Debug Logs",
"google-chat.jfconfig.debugLogs.tooltips": "Log additional information about message processing. Useful for debugging",
"google-chat.jfconfig.client": "Client",
"google-chat.jfconfig.server": "Server"