Skip to content

Commit

Permalink
Merge v1.5.4 changes into 1.19 (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
SiongSng authored Feb 26, 2023
2 parents 8677664 + 5da37ff commit 7b16876
Show file tree
Hide file tree
Showing 35 changed files with 773 additions and 637 deletions.
10 changes: 5 additions & 5 deletions README/zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

在任何版本的 Minecraft 中或游戏外聊天交流,每个玩家就像在同个世界中游玩!

- ### 配置选单
- ### 配置菜单

内置精致的配置选单,任何功能都可供您自由调整。
内置精致的配置菜单,任何功能都可供您自由调整。

- ### 原文显示

Expand All @@ -37,7 +37,7 @@

- ### 翻译资源包

自动载入最新的翻译资源包,由许多热心的社群参与者共同翻译而成
自动加载最新的翻译资源包,由许多热心的社区参与者共同翻译而成

- ### 机器翻译

Expand All @@ -46,7 +46,7 @@
- ### 开启 Crowdin 页面

想要协助翻译手中的物品或者您注视的方块或实体吗?
使用这功能即可,请记得到设定选单中修改本功能的快捷键
使用这项功能即可,请记得到设置菜单中修改本功能的快捷键

## ⚙ 开发者

Expand All @@ -73,4 +73,4 @@

## 🎓 许可证

[GNU 通用公共许可证 3.0 版 (GPL3)](https://www.gnu.org/licenses/gpl-3.0.html)
[GNU 通用公共许可证 3.0 版 (GPL3)](https://www.gnu.org/licenses/gpl-3.0.html)
4 changes: 2 additions & 2 deletions README/zh_tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@
- [Cloth Config](https://github.com/shedaniel/cloth-config)
- [Socket.IO](https://github.com/socketio/socket.io-client-java)

## 🎓 許可證
## 🎓 授權條款

[GNU 通用公眾授權條款 3.0 版 (GPL3)](https://www.gnu.org/licenses/gpl-3.0.html)
[GNU 通用公眾授權條款 3.0 版 (GPL3)](https://www.gnu.org/licenses/gpl-3.0.html)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.rpmtw.rpmtw_platform_mod.mixins;

import com.rpmtw.rpmtw_platform_mod.translation.resourcepack.TranslateResourcePack;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.repository.PackCompatibility;
import org.spongepowered.asm.mixin.Final;
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.CallbackInfoReturnable;

@Environment(EnvType.CLIENT)
@Mixin(Pack.class)
public class FixPackCompatibility {
@Shadow
@Final
private String id;

/**
* Fix the compatibility of the translation resource pack.
* <p>
* Because the translation pack is for 1.19.x, but the pack format in 1.19 ~ 1.19.2 is 9, and the pack format in 1.19.3+ is 12.
* So we need to change the compatibility of the translation pack to {@link PackCompatibility#COMPATIBLE}.
*/
@Inject(method = "getCompatibility", at = @At(value = "HEAD"), cancellable = true)
public void fixPackCompatibility(CallbackInfoReturnable<PackCompatibility> cir) {
String packId = TranslateResourcePack.INSTANCE.getPackId();
if (cir.isCancelled() || !id.equals(packId)) return;

cir.setReturnValue(PackCompatibility.COMPATIBLE);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rpmtw.rpmtw_platform_mod.mixins;

import com.rpmtw.rpmtw_platform_mod.events.OnReloadLanguage;
import com.rpmtw.rpmtw_platform_mod.RPMTWPlatformMod;
import com.rpmtw.rpmtw_platform_mod.translation.machineTranslation.MTStorage;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.resources.language.LanguageManager;
Expand All @@ -15,6 +16,7 @@
public class LanguageManagerMixin {
@Inject(method = "onResourceManagerReload", at = @At("HEAD"))
void onReloadLanguage(ResourceManager resourceManager, CallbackInfo ci) {
OnReloadLanguage.INSTANCE.onReload(resourceManager);
RPMTWPlatformMod.LOGGER.info("Reloading language...");
MTStorage.INSTANCE.load(resourceManager);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.rpmtw.rpmtw_platform_mod.mixins;

import com.rpmtw.rpmtw_platform_mod.RPMTWPlatformMod;
import com.rpmtw.rpmtw_platform_mod.translation.resourcepack.TranslateResourcePack;
import net.minecraft.client.Options;
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(Options.class)
public class LoadGameOptions {
private boolean called = false;

@Inject(method = "load", at = @At("HEAD"))
public void loading(CallbackInfo ci) {
if (called) return;

RPMTWPlatformMod.LOGGER.info("Loading the game options...");
TranslateResourcePack.INSTANCE.init();
called = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ import com.rpmtw.rpmtw_platform_mod.command.CommandHandler
import com.rpmtw.rpmtw_platform_mod.config.RPMTWConfig
import com.rpmtw.rpmtw_platform_mod.handlers.EventHandler
import com.rpmtw.rpmtw_platform_mod.handlers.SentryHandler
import com.rpmtw.rpmtw_platform_mod.translation.resourcepack.TranslateResourcePack
import dev.architectury.platform.Platform
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger

object RPMTWPlatformMod {
const val MOD_ID = "rpmtw_platform_mod"
val VERSION: String = Platform.getMod(MOD_ID).version

@JvmField
val LOGGER: Logger = LogManager.getLogger(MOD_ID)

val VERSION: String
get() = Platform.getMod(MOD_ID).version

@JvmStatic
fun init() {
LOGGER.info("Initializing RPMTW Platform Mod")
RPMTWConfig.register()
if (RPMTWConfig.get().advanced.sendExceptionToSentry) {
SentryHandler.init()
}
RPMTWApiClient.init()
TranslateResourcePack.deleteResourcePack()
CommandHandler.init()
EventHandler.handle()
RPMTWPlatformModPlugin.registerConfigScreen()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,23 @@ import net.fabricmc.api.Environment
@Config(name = "rpmtw_platform_mod")
@Environment(EnvType.CLIENT)
class ConfigObject : ConfigData {
@JvmField
@ConfigEntry.Gui.CollapsibleObject(startExpanded = true)
var base = Base()

@JvmField
@ConfigEntry.Gui.CollapsibleObject(startExpanded = false)
var translate = Translate()

@JvmField
@ConfigEntry.Gui.CollapsibleObject(startExpanded = false)
var universeChat = UniverseChat()

@JvmField
@ConfigEntry.Gui.CollapsibleObject(startExpanded = false)
val keyBindings = KeyBindings()

@JvmField
@ConfigEntry.Gui.CollapsibleObject(startExpanded = false)
val advanced = Advanced()

class Base {
@JvmField
@ConfigEntry.Gui.Excluded
var rpmtwAuthToken: String? = null

fun isLogin(): Boolean {
return rpmtwAuthToken != null && rpmtwAuthToken!!.isNotEmpty()
}
}

class Translate {
@JvmField
@ConfigEntry.Gui.Tooltip(count = 1)
@ConfigEntry.Gui.RequiresRestart
var machineTranslation = true

@JvmField
@ConfigEntry.Gui.Tooltip(count = 1)
@ConfigEntry.Gui.RequiresRestart
var autoMachineTranslation = false
Expand All @@ -67,72 +47,75 @@ class ConfigObject : ConfigData {

@ConfigEntry.Gui.Tooltip(count = 1)
@ConfigEntry.Gui.RequiresRestart
var loadTranslateResourcePack = true
var loadTranslateResourcePack = false
get() {
return if (GameLanguage.getMinecraft() == GameLanguage.English) {
false
return if (GameLanguage.getSystem() == GameLanguage.TraditionalChinese) {
true
} else {
field
}
}

@ConfigEntry.Gui.Tooltip(count = 1)
@ConfigEntry.Gui.RequiresRestart
var autoToggleLanguage = true
}

class UniverseChat {
@JvmField
@ConfigEntry.Gui.Tooltip(count = 1)
@ConfigEntry.Gui.RequiresRestart
var enable = true

@JvmField
var enableReceiveMessage = true

@JvmField
@ConfigEntry.Gui.Tooltip(count = 1)
var enableButton = true

@JvmField
@ConfigEntry.Gui.Excluded
var eula = false

@JvmField
@ConfigEntry.Gui.Tooltip(count = 1)
var nickname: String? = null

@JvmField
@ConfigEntry.Gui.Tooltip(count = 1)
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
var accountType: UniverseChatAccountType = UniverseChatAccountType.MINECRAFT

@JvmField
@ConfigEntry.Gui.Tooltip(count = 1)
var blockUsers: MutableList<String> = mutableListOf()
}

class KeyBindings {
@JvmField
var machineTranslation: ModifierKeyCode = ModifierKeyCode.unknown()

// Ctrl + R
@JvmField
var config: ModifierKeyCode = ModifierKeyCode.of(
InputConstants.Type.KEYSYM.getOrCreate(InputConstants.KEY_R), Modifier.of(false, true, false)
)

@JvmField
@ConfigEntry.Gui.Tooltip(count = 1)
var reloadTranslatePack: ModifierKeyCode = ModifierKeyCode.unknown()

@JvmField
@ConfigEntry.Gui.Tooltip(count = 1)
var openCrowdinPage: ModifierKeyCode = ModifierKeyCode.unknown()
}

class Advanced {
@JvmField
@ConfigEntry.Gui.Tooltip(count = 1)
@ConfigEntry.Gui.RequiresRestart
var sendExceptionToSentry = true
}


@ConfigEntry.Gui.Excluded
var rpmtwAuthToken: String? = null

@ConfigEntry.Gui.Excluded
var firstJoinLevel: Boolean = true

fun isLogin(): Boolean {
return rpmtwAuthToken != null && rpmtwAuthToken!!.isNotEmpty()
}
}

enum class UniverseChatAccountType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.rpmtw.rpmtw_platform_mod.config
import com.mojang.blaze3d.platform.InputConstants
import com.mojang.blaze3d.vertex.PoseStack
import com.rpmtw.rpmtw_platform_mod.RPMTWPlatformMod
import com.rpmtw.rpmtw_platform_mod.RPMTWPlatformModPlugin
import com.rpmtw.rpmtw_platform_mod.handlers.RPMTWAuthHandler
import com.rpmtw.rpmtw_platform_mod.handlers.UniverseChatHandler
import me.shedaniel.autoconfig.AutoConfig
Expand Down Expand Up @@ -36,15 +35,15 @@ object RPMTWConfig {
private var config: ConfigObject? = null


fun register() {
private fun register() {
RPMTWPlatformMod.LOGGER.info("Registering config")
// register config
// Register config
AutoConfig.register(ConfigObject::class.java) { definition: Config?, configClass: Class<ConfigObject?>? ->
JanksonConfigSerializer(definition, configClass, buildJankson(Jankson.builder()))
}
val guiRegistry: GuiRegistry = AutoConfig.getGuiRegistry(ConfigObject::class.java)

// key mapping gui
// Key mapping gui
guiRegistry.registerPredicateProvider({ i13n, field, config, defaults, _ ->
if (field.isAnnotationPresent(ConfigEntry.Gui.Excluded::class.java)) return@registerPredicateProvider emptyList()
val entry: KeyCodeEntry = ConfigEntryBuilder.create().startModifierKeyCodeField(
Expand All @@ -57,11 +56,10 @@ object RPMTWConfig {
listOf(entry)
}) { field -> field.type === ModifierKeyCode::class.java }

val holder: ConfigHolder<ConfigObject> = AutoConfig.getConfigHolder(ConfigObject::class.java)
val holder = AutoConfig.getConfigHolder(ConfigObject::class.java)
config = holder.config
listenOnSave(holder, holder.config)

RPMTWPlatformModPlugin.registerConfigScreen()
RPMTWPlatformMod.LOGGER.info("Registered config")
}

Expand Down Expand Up @@ -93,16 +91,16 @@ object RPMTWConfig {

private fun listenOnSave(holder: ConfigHolder<ConfigObject>, oldConfig: ConfigObject) {
var oldAccountType = oldConfig.universeChat.accountType
var oldRPMTWAuthToken = oldConfig.base.rpmtwAuthToken
var oldRPMTWAuthToken = oldConfig.rpmtwAuthToken

holder.registerSaveListener { _, edited ->
if (edited.universeChat.accountType != oldAccountType || edited.base.rpmtwAuthToken != oldRPMTWAuthToken) {
if (edited.universeChat.accountType != oldAccountType || edited.rpmtwAuthToken != oldRPMTWAuthToken) {
UniverseChatHandler.restart()
}

// Save the new configs
oldAccountType = edited.universeChat.accountType
oldRPMTWAuthToken = edited.base.rpmtwAuthToken
oldRPMTWAuthToken = edited.rpmtwAuthToken

return@registerSaveListener InteractionResult.SUCCESS
}
Expand Down Expand Up @@ -169,7 +167,7 @@ internal class RPMTWAccountEntry : AbstractConfigListEntry<Any?>(Component.liter
super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isHovered, delta)

val title = Component.translatable("auth.rpmtw_platform_mod.title")
val isLogin = RPMTWConfig.get().base.isLogin()
val isLogin = RPMTWConfig.get().isLogin()
val authStatus: String = if (isLogin) {
I18n.get("auth.rpmtw_platform_mod.status.logged_in")
} else {
Expand Down
Loading

0 comments on commit 7b16876

Please sign in to comment.