Skip to content

Commit

Permalink
Merge pull request #13 from VM-Chinese-translate-group/1.21.x-v3tex
Browse files Browse the repository at this point in the history
VMTU v3
  • Loading branch information
TexBlock authored Jan 11, 2025
2 parents 8bdf449 + 232fefe commit 2a4c4b1
Show file tree
Hide file tree
Showing 51 changed files with 1,924 additions and 282 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ classes/
.metadata
.vscode
.settings
*.launch
*.launch
/.architectury-transformer/
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
# v3.0 更新日志

等待@TexBlock修复屏幕提示SuggestModScreen#L56-L59,新版本代码变动大,无法使用部分代码已被注释。文字不会换行,也没了背景

## 移除

- 移除指定玩家id称呼功能,包括`playerNameCheck``nameUrl`配置项
- 移除下载Modtinth汉化资源包功能
- 移除籽岷游戏id彩蛋
- 移除tips功能

# 新功能

- 现在自动切换语言(`autoSwitchLanguage`)功能默认为开启状态
- 支持1.21.4,中间版本1.20-1.21.1不支持,1.21.3未测试
- 未安装推荐模组时模组安装提示屏幕的“退出游戏”按钮改为“我知道我在做什么!”按钮,将不会退出游戏
- 模组安装提示屏幕现在仅会在简体中文时出现
- 重新添加资源包下载装载功能 (下载核心基于I18nUpdateMod3代码修改)

# 修复

- 修复按esc键无法退出推荐模组安装提示屏幕的bug
- 修复更新检测出现问题时提示两次的问题

# 优化

- 优化一些语言文件的内容表达
- 优化配置屏幕配置选项排布顺序,为`tipsMinutes`项加入滑块
- 优化网络请求,现在每次进入游戏只会发起一次获取tips的请求
- 繁体中文本地化改进
- 优化语言切换功能 (基于I18nUpdateMod3代码修改)
- 优化CoreMod检测方式

## 核心开发

- 合并模组为多模组加载器版工具 forgix -> modfusioner
- 更新所有依赖版本
- 修复GitHub CI 工作流
- 移除`util/NameUtil.java`合并代码至`ModEvents.java`
- 简化代码
- 添加部分跨版本兼容代码
- 升级游戏版本为1.21.4
- 添加基于I18nUpdateMod3代码的下载核心
661 changes: 661 additions & 0 deletions Core-LICENSE

Large diffs are not rendered by default.

43 changes: 32 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,52 @@
[MC百科](https://www.mcmod.cn/class/11203.html)

<img alt="forge" height="56" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/supported/forge_vector.svg"> (1.12.2~1.20.4)
<img alt="neoforge" height="56" src="https://github.com/mc-wiki/minecraft-mod-heywiki/blob/master/docs/supports_neoforge.svg?raw=true"> (≥1.20.1)
<img alt="fabric" height="56" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/supported/fabric_vector.svg"> (≥1.16.4)
<img alt="neoforge" height="56" src="https://github.com/mc-wiki/minecraft-mod-heywiki/blob/master/docs/supports_neoforge.svg?raw=true">
<img alt="fabric" height="56" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/supported/fabric_vector.svg">
</div>

## 功能

1. 在汉化发布新版本时会在游戏里通知玩家去下载更新。
2. 可配置默认每25分钟在聊天栏发送一条自定义消息。
3. 如果玩家已经下载资源包且发生错误未启用,会在聊天框提示玩家在选项->资源包中手动启用。
4. 可配置自动修改游戏语言。
5. 可配置是否检测安装i18nupdate或Vault Patch补全汉化模组。如未安装将弹出提示页面引导下载(可按esc退出)
模组的所有功能都是可配置的,关于配置文件请看后文。

1. 可配置在汉化发布新版本时会在游戏里通知玩家去下载更新。
2. 可配置是否开启自动下载并启用VM模组汉化资源包。
3. 可配置自动修改游戏语言。
4. 可配置是否检测安装i18nUpdateMod或Vault Patch补全汉化模组。如未安装将弹出提示页面引导下载(可按esc退出)

## 使用与配置文件

VM汉化组汉化人员请注意:**发布汉化时,请在汉化更新时改一下模组配置里的版本号!**
本模组需要前置依赖:Cloth Config API

模组会在`.minecraft/<mcversion>/config/`文件夹创建名为`vmtranslationupdate.toml`的配置文件(1.12.2后缀是.cfg)。

详见:<https://vmct-cn.top/vmtu/config>
默认情况下,配置文件的内容和功能启用情况如下所示:
```toml
autoSwitchLanguage = true # 自动切换语言
switchLanguage = "zh_cn" # 自动切换为简体中文
autoDownloadVMTranslationPack = false # 默认不自动下载VM汉化资源包
translationPackSource = "GITEE" # 汉化资源包下载源
checkModPackTranslationUpdate = true # 默认检查汉化更新
modPackTranslationUpdateCheckUrl = "https://gitee.com/Wulian233/vmtu/raw/main/update/example.txt" # 汉化更新检查地址
modPackTranslationUrl = "https://vmct-cn.top/modpacks/example/" # 汉化下载地址
modPackTranslationVersion = "1.0.0" # 汉化版本
i18nUpdateModCheck = true # 默认检查是否安装i18nUpdateMod模组
vaultPatcherCheck = false # 默认不检查是否安装Vault Patch模组
```

---

## 支持版本

详见:<https://vmct-cn.top/vmtu/support>
| 模组加载器 | 支持的Minecraft版本 |
|----------|----------------------------------------|
| Forge | 1.12/1.16.5/1.18-1.20.4 |
| NeoForge | 1.20.1-1.21.4(1.20.1NeoForge兼容Forge模组) |
| Fabric | 1.16.5-1.21.4(支持ModMenu) |

## 其他
作者:Wulian233(捂脸)、TexTrue。以及Lichiiiiiii修复部分bug!

作者:Wulian233(捂脸)、TexTrue、Lichiiiiiii

本模组使用MIT许可证
VMTUCore基于I18nUpdateMod3修改,AGPL许可证
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ subprojects {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings "dev.architectury:yarn-mappings-patch-neoforge:${project.yarn_patch}"
}

implementation("com.google.auto.service:auto-service-annotations:1.1.1")
annotationProcessor("com.google.auto.service:auto-service:1.1.1")
}
}

Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies {
// Do NOT use other classes from fabric loader
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
modApi "me.shedaniel.cloth:cloth-config:${rootProject.clothconfig_version}"
implementation(project(":core"))
}

publishing {
Expand Down
85 changes: 35 additions & 50 deletions common/src/main/java/top/vmctcn/vmtranslationupdate/ModEvents.java
Original file line number Diff line number Diff line change
@@ -1,74 +1,59 @@
package top.vmctcn.vmtranslationupdate;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import top.vmctcn.vmtranslationupdate.screen.SuggestModScreen;
import top.vmctcn.vmtranslationupdate.util.ModConfigUtil;
import top.vmctcn.vmtranslationupdate.util.TipsUtil;
import top.vmctcn.vmtranslationupdate.util.VersionCheckUtil;

import java.util.Objects;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import top.vmctcn.vmtranslationupdate.util.VersionCheckUtil;

public class ModEvents {
private static boolean isLoadedTips = false; // 标识Tips是否已经从网络加载
public static int tickCounter;
public static Random random = new Random();
public static boolean firstTitleScreenShown = false;

public static void playerJoinEvent(ServerPlayerEntity player) {
String localVersion = ModConfigUtil.getConfig().modPackTranslationVersion;
String onlineVersion = VersionCheckUtil.getOnlineVersion();

public static void clientTickEndEvent(MinecraftClient client) {
tickCounter++;
int tickInterval = 20 * 60 * TipsUtil.getTipsMinutes();
if (tickCounter >= tickInterval) {
if (!isLoadedTips) {
CompletableFuture.supplyAsync(() -> TipsUtil.getRandomMessageFromURLAsync(ModConfigUtil.getConfig().tipsUrl))
.thenAccept(message -> {
isLoadedTips = true;
if (message == null) return;
String randomMessage = getRandomMessageFromCache();
if (randomMessage != null) {
Objects.requireNonNull(client.player).sendMessage(Text.translatable(randomMessage), false);
}
});
} else {
// 如果已经加载过提示信息,直接从缓存中获取随机消息
String randomMessage = getRandomMessageFromCache();
if (randomMessage != null) {
Objects.requireNonNull(client.player).sendMessage(Text.translatable(randomMessage), false);
}
if (ModConfigUtil.getConfig().checkModPackTranslationUpdate) {
if (onlineVersion.isEmpty()) {
player.sendMessage(Text.translatable("vmtranslationupdate.message.error"), false);
VMTranslationUpdate.LOGGER.warn("Error fetching modpack translation version");
return;
}
}
}

private static String getRandomMessageFromCache() {
if (!TipsUtil.messagesList.isEmpty()) {
int index = random.nextInt(TipsUtil.messagesList.size());
return TipsUtil.messagesList.get(index);
if (!localVersion.equals(onlineVersion)) {
player.sendMessage(Text.translatable("vmtranslationupdate.message.update", localVersion, onlineVersion));
Text message = Text.translatable("vmtranslationupdate.message.update2")
.append(Text.translatable(ModConfigUtil.getConfig().modPackTranslationUrl)
.setStyle(Style.EMPTY
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, ModConfigUtil.getConfig().modPackTranslationUrl))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("vmtranslationupdate.message.hover")))
.withColor(Formatting.AQUA)
))
.append(Text.translatable("vmtranslationupdate.message.update3"));
player.sendMessage(message);
}
}
return null;
}

public static void playerJoinEvent(ServerPlayerEntity player) {
String name = player.getName().getString();
String localVersion = ModConfigUtil.getConfig().modPackTranslationVersion;
String onlineVersion = VersionCheckUtil.getOnlineVersion(player);
public static void screenAfterInitEvent(Screen screen) {
if (firstTitleScreenShown || !(screen instanceof TitleScreen)) {
return;
}

if (ModConfigUtil.getConfig().checkModPackTranslationUpdate && !localVersion.equals(onlineVersion)) {
player.sendMessage(Text.translatable("vmtranslationupdate.message.update", name, localVersion, onlineVersion));
Text message = Text.translatable("vmtranslationupdate.message.update2")
.append(Text.translatable(ModConfigUtil.getConfig().modPackTranslationUrl)
.setStyle(Style.EMPTY
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, ModConfigUtil.getConfig().modPackTranslationUrl))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("vmtranslationupdate.message.hover")))
.withColor(Formatting.AQUA)
))
.append(Text.translatable("vmtranslationupdate.message.update3"));
String language = MinecraftClient.getInstance().getLanguageManager().getLanguage();

player.sendMessage(message);
if ("zh_cn".equals(language)) {
MinecraftClient.getInstance().setScreen(new SuggestModScreen(screen));
}

firstTitleScreenShown = true;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package top.vmctcn.vmtranslationupdate;

import net.minecraft.client.MinecraftClient;
import top.vmctcn.vmtranslationupdate.util.ModConfigUtil;
import top.vmctcn.vmtranslationupdate.util.ScreenUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class VMTranslationUpdate {
public static final String MOD_ID = "vmtranslationupdate";
static MinecraftClient client = MinecraftClient.getInstance();
public static final Logger LOGGER = LoggerFactory.getLogger("VMTranslationUpdateMod");

public static void init() {
ScreenUtil.checkModsLoaded();

if (ModConfigUtil.getConfig().autoSwitchLanguage && ModConfigUtil.getConfig().switchLanguage != null) {
client.options.language = ModConfigUtil.getConfig().switchLanguage;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;
import top.vmctcn.vmtranslationupdate.VMTranslationUpdate;
import top.vmctcn.vmtranslationupdate.respack.ResPackSource;

@Config(name = VMTranslationUpdate.MOD_ID)
public class ModConfigs implements ConfigData {
public boolean autoSwitchLanguage = true;
public String switchLanguage = "zh_cn";

public boolean autoDownloadVMTranslationPack = false;
@ConfigEntry.Gui.Tooltip
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
public ResPackSource translationPackSource = ResPackSource.GITEE;

public boolean checkModPackTranslationUpdate = true;
public String modPackTranslationUpdateCheckUrl = "https://gitee.com/Wulian233/vmtu/raw/main/update/example.txt";
public String modPackTranslationUrl = "https://vmct-cn.top/modpacks/example/";

public String modPackTranslationVersion = "1.0.0";
public boolean displayTips = true;
public String tipsUrl = "https://gitee.com/Wulian233/vmtu/raw/main/tips.txt";

@ConfigEntry.BoundedDiscrete(min = 1, max = 120)
public int tipsMinutes = 25;

public boolean i18nUpdateModCheck = true;
public boolean vaultPatcherCheck = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package top.vmctcn.vmtranslationupdate.respack;

import top.vmctcn.vmtranslationupdate.VMTranslationUpdate;
import top.vmctcn.vmtranslationupdate.util.ModConfigUtil;
import top.vmctcn.vmtucore.ModPlatform;
import top.vmctcn.vmtucore.VMTUCore;
import top.vmctcn.vmtucore.respack.GameOptionsWriter;

import java.io.IOException;
import java.nio.file.Path;

public class GameOptionsSetter {
public static void init(Path gamePath) {
if (ModConfigUtil.getConfig().autoSwitchLanguage && ModConfigUtil.getConfig().switchLanguage != null) {
try {
GameOptionsWriter config = new GameOptionsWriter(gamePath.resolve("options.txt"));
config.switchLanguage(ModConfigUtil.getConfig().switchLanguage);
} catch (IOException e) {
VMTranslationUpdate.LOGGER.warn("Failed to switch language: ", e);
}
}

if (ModConfigUtil.getConfig().autoDownloadVMTranslationPack) {
String gameVersion = ModPlatform.INSTANCE.getGameVersion();
ResPackSource resPackSource = ModConfigUtil.getConfig().translationPackSource;
VMTUCore.init(gamePath, gameVersion, "VM汉化组模组汉化包1.20", resPackSource.getUrl());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package top.vmctcn.vmtranslationupdate.respack;

public enum ResPackSource {
GITEE("https://gitee.com/Wulian233/vmtu/raw/main/resourcepack/");

private final String sourceUrl;

ResPackSource(String sourceUrl) {
this.sourceUrl = sourceUrl;
}

public String getUrl() {
return this.sourceUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import top.vmctcn.vmtranslationupdate.util.ModConfigUtil;
import top.vmctcn.vmtranslationupdate.util.ScreenUtil;
import top.vmctcn.vmtranslationupdate.verlayer.ScreenHelper;

public class SuggestModScreen extends Screen {
public final Screen lastScreen;
Expand Down Expand Up @@ -46,18 +48,16 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {

@Override
public void renderBackground(DrawContext context, int mouseX, int mouseY, float partial) {

super.renderBackground(context, mouseX, mouseY, partial);

//Render header and footer separators
RenderSystem.enableBlend();
ScreenUtil.resetShaderColor(context);
// Identifier identifier = MinecraftClient.getInstance().world == null ? Screen.HEADER_SEPARATOR_TEXTURE : Screen.INWORLD_HEADER_SEPARATOR_TEXTURE;
// Identifier identifier2 = MinecraftClient.getInstance().world == null ? Screen.FOOTER_SEPARATOR_TEXTURE : Screen.INWORLD_FOOTER_SEPARATOR_TEXTURE;
// context.drawTexture(identifier, 0, 40 - 2, 0.0F, 0.0F, this.width, 2, 32, 2);
// context.drawTexture(identifier2, 0, this.height - 50, 0.0F, 0.0F, this.width, 2, 32, 2);
ScreenUtil.resetShaderColor(context);

ScreenHelper.resetShaderColor(context);
Identifier headerIdentifier = MinecraftClient.getInstance().world == null ? Screen.HEADER_SEPARATOR_TEXTURE : Screen.INWORLD_HEADER_SEPARATOR_TEXTURE;
Identifier footerIdentifier = MinecraftClient.getInstance().world == null ? Screen.FOOTER_SEPARATOR_TEXTURE : Screen.INWORLD_FOOTER_SEPARATOR_TEXTURE;
ScreenHelper.drawGuiTexture(context, headerIdentifier, 0, 40 - 2, 0.0F, 0.0F, this.width, 2, 32, 2);
ScreenHelper.drawGuiTexture(context, footerIdentifier, 0, this.height - 50, 0.0F, 0.0F, this.width, 2, 32, 2);
ScreenHelper.resetShaderColor(context);
}

@Override
Expand Down
Loading

0 comments on commit 2a4c4b1

Please sign in to comment.