diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/CustomResources.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/CustomResources.java index 6364329d..47d302a4 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/CustomResources.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/CustomResources.java @@ -3,6 +3,7 @@ import cn.zbx1425.mtrsteamloco.data.ScriptedCustomTrains; import cn.zbx1425.mtrsteamloco.data.EyeCandyRegistry; import cn.zbx1425.mtrsteamloco.data.RailModelRegistry; +import cn.zbx1425.mtrsteamloco.render.scripting.ScriptResourceUtil; import cn.zbx1425.mtrsteamloco.render.train.RenderTrainD51; import cn.zbx1425.mtrsteamloco.render.train.RenderTrainDK3; import cn.zbx1425.mtrsteamloco.render.train.RenderTrainDK3Mini; @@ -36,6 +37,7 @@ public static void init(ResourceManager resourceManager) { EyeCandyRegistry.reload(resourceManager); RailModelRegistry.reload(resourceManager); ScriptedCustomTrains.init(resourceManager); + ScriptResourceUtil.init(resourceManager); RenderTrainD51.initGLModel(resourceManager); RenderTrainDK3.initGLModel(resourceManager); diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/integration/DynamicTrainModelLoader.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/integration/DynamicTrainModelLoader.java index 1915f7fb..f21c0e47 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/integration/DynamicTrainModelLoader.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/integration/DynamicTrainModelLoader.java @@ -46,7 +46,7 @@ public static void loadInto(JsonObject model, DynamicTrainModel target) { public static void loadObjInto(JsonObject model, DynamicTrainModel target) { int bbDataType = MtrModelRegistryUtil.getDummyBbDataType(model); String path = MtrModelRegistryUtil.getPathFromDummyBbData(model); - Main.LOGGER.info("Loading DynamicTrainModel from OBJ " + path); + // Main.LOGGER.info("Loading DynamicTrainModel from OBJ " + path); target.parts.clear(); try { if (target.properties.has("atlasIndex")) { @@ -287,7 +287,7 @@ public static void loadObjInto(JsonObject model, DynamicTrainModel target) { public static void loadVanillaModelInto(JsonObject model, DynamicTrainModel target) { if (!model.has("dummyBbData")) return; String path = MtrModelRegistryUtil.getPathFromDummyBbData(model.get("dummyBbData").getAsJsonObject()); - Main.LOGGER.info("Optimizing DynamicTrainModel from BBMODEL " + path); + // Main.LOGGER.info("Optimizing DynamicTrainModel from BBMODEL " + path); try { String textureId = MtrModelRegistryUtil.getTextureIdFromDummyBbData(model.get("dummyBbData").getAsJsonObject()); ResourceLocation texture = resolveTexture(textureId, str -> str.endsWith(".png") ? str : (str + ".png")); diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/scripting/ScriptResourceUtil.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/scripting/ScriptResourceUtil.java index 87f460b7..e749ed83 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/scripting/ScriptResourceUtil.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/scripting/ScriptResourceUtil.java @@ -41,6 +41,10 @@ public class ScriptResourceUtil { protected static List> scriptsToExecute; protected static ResourceLocation relativeBase; + public static void init(ResourceManager resourceManager) { + hasNotoSansCjk = UtilitiesClient.hasResource(NOTO_SANS_CJK_LOCATION); + } + public static ResourceManager manager() { return MtrModelRegistryUtil.resourceManager; } @@ -89,15 +93,25 @@ public static void print(Object... objects) { Main.LOGGER.info(sb.toString().trim()); } + private static final ResourceLocation NOTO_SANS_CJK_LOCATION = new ResourceLocation(mtr.MTR.MOD_ID, "font/noto-sans-cjk-tc-medium.otf"); + private static final ResourceLocation NOTO_SANS_LOCATION = new ResourceLocation(mtr.MTR.MOD_ID, "font/noto-sans-semibold.ttf"); + private static final ResourceLocation NOTO_SERIF_LOCATION = new ResourceLocation(mtr.MTR.MOD_ID, "font/noto-serif-cjk-tc-semibold.ttf"); + private static boolean hasNotoSansCjk = false; + public static Font getSystemFont(String fontName) { ClientCacheAccessor clientCache = (ClientCacheAccessor) ClientData.DATA_CACHE; ResourceManager resourceManager = Minecraft.getInstance().getResourceManager(); switch (fontName) { case "Noto Sans" -> { - if (clientCache.getFont() == null || !clientCache.getFont().canDisplay('草')) { + if (clientCache.getFont() == null || (hasNotoSansCjk && !clientCache.getFont().canDisplay('草'))) { try { - clientCache.setFont(Font.createFont(Font.TRUETYPE_FONT, Utilities.getInputStream(resourceManager.getResource( - new ResourceLocation(mtr.MTR.MOD_ID, "font/noto-sans-cjk-tc-medium.otf"))))); + if (hasNotoSansCjk) { + clientCache.setFont(Font.createFont(Font.TRUETYPE_FONT, + Utilities.getInputStream(resourceManager.getResource(NOTO_SANS_CJK_LOCATION)))); + } else { + clientCache.setFont(Font.createFont(Font.TRUETYPE_FONT, + Utilities.getInputStream(resourceManager.getResource(NOTO_SANS_LOCATION)))); + } } catch (Exception ex) { Main.LOGGER.warn("Failed loading font", ex); } @@ -107,8 +121,8 @@ public static Font getSystemFont(String fontName) { case "Noto Serif" -> { if (clientCache.getFontCjk() == null) { try { - clientCache.setFontCjk(Font.createFont(Font.TRUETYPE_FONT, Utilities.getInputStream(resourceManager.getResource( - new ResourceLocation(mtr.MTR.MOD_ID, "font/noto-serif-cjk-tc-semibold.ttf"))))); + clientCache.setFontCjk(Font.createFont(Font.TRUETYPE_FONT, + Utilities.getInputStream(resourceManager.getResource(NOTO_SERIF_LOCATION)))); } catch (Exception ex) { Main.LOGGER.warn("Failed loading font", ex); } @@ -176,4 +190,5 @@ public static int getNTEVersionInt() { public static int getNTEProtoVersion() { return BuildConfig.MOD_PROTOCOL_VERSION; } + } diff --git a/common/src/main/resources/assets/mtr/font/noto-sans-cjk-tc-medium.otf b/common/src/main/resources/assets/mtr/font/noto-sans-cjk-tc-medium.otf deleted file mode 100644 index c6ec7b6c..00000000 Binary files a/common/src/main/resources/assets/mtr/font/noto-sans-cjk-tc-medium.otf and /dev/null differ