Skip to content

Commit

Permalink
Remove noto-sans-cjk font
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Aug 30, 2023
1 parent a2f2de6 commit a04f767
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public class ScriptResourceUtil {
protected static List<Map.Entry<ResourceLocation, String>> 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;
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -176,4 +190,5 @@ public static int getNTEVersionInt() {
public static int getNTEProtoVersion() {
return BuildConfig.MOD_PROTOCOL_VERSION;
}

}
Binary file not shown.

0 comments on commit a04f767

Please sign in to comment.