Skip to content

Commit

Permalink
Remove customWindowTitleWithActivity (MC 1.14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrix-Shen committed May 25, 2022
1 parent 227bc7b commit aef7247
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class Configs {
@Config(category = ConfigCategory.GENERIC)
public static String customWindowTitle = "Minecraft {mc_version} with TweakMyClient {tmc_version} | Player {mc_username} | FPS: {mc_fps}";

@Config(category = ConfigCategory.GENERIC)
@Config(category = ConfigCategory.GENERIC, dependencies = @Dependencies(not = @Dependency(value = "minecraft", versionPredicate = "<1.15")))
public static String customWindowTitleWithActivity = "Minecraft {mc_version} ({mc_activity}) with TweakMyClient {tmc_version} | Player {mc_username} | FPS: {mc_fps}";

@Numeric(maxValue = 24000, minValue = 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@ public static void featureCustomBlockHitBoxOverlayOutlineCallBack(Option option)

public static void featureCustomWindowTitleCallback(Option option) {
if (Configs.featureCustomWindowTitle) {
//#if MC >= 11500
CustomWindowUtil.rebuildCache(CustomWindowUtil.TitleType.TITLE);
CustomWindowUtil.rebuildCache(CustomWindowUtil.TitleType.TITLE_WITH_ACTIVITY);
//#else
//$$ CustomWindowUtil.rebuildCache();
//#endif
CustomWindowUtil.updateTitle();
} else {
CustomWindowUtil.reSetTitle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public class CustomWindowUtil {
public static final HashMap<String, String> PLACEHOLDER_STATIC_MAP = Maps.newHashMap();
public static final Pattern MOD_PATTERN = Pattern.compile("(?<=(\\{fabric_mod_ver:)).*?(?=(}))");
private static String TITLE_CACHE;
//#if MC >= 11500
private static String TITLE_CACHE_WITH_ACTIVITY;
//#endif

public static final Minecraft mc = TweakMyClient.getMinecraftClient();

Expand All @@ -45,8 +47,12 @@ public class CustomWindowUtil {
CustomWindowUtil.PLACEHOLDER_STATIC_MAP.put("{tmc_version}", TweakMyClientReference.getModVersion());
CustomWindowUtil.PLACEHOLDER_STATIC_MAP.put("{tmc_version_type}", TweakMyClientReference.getModVersionType());
if (Configs.featureCustomWindowTitle) {
//#if MC >= 11500
CustomWindowUtil.rebuildCache(TitleType.TITLE);
CustomWindowUtil.rebuildCache(TitleType.TITLE_WITH_ACTIVITY);
//#else
//$$ CustomWindowUtil.rebuildCache();
//#endif
}
}

Expand All @@ -58,9 +64,14 @@ public static String replacePlaceholders(HashMap<String, String> map, String str
}

public static String getWindowTitle() {
//#if MC >= 11500
return CustomWindowUtil.replacePlaceholders(PLACEHOLDER_MAP, (hasActivity() ? TITLE_CACHE_WITH_ACTIVITY : TITLE_CACHE));
//#else
//$$ return CustomWindowUtil.replacePlaceholders(PLACEHOLDER_MAP, TITLE_CACHE);
//#endif
}

//#if MC >= 11500
public static String getActivity() {
if (mc.getSingleplayerServer() != null && !mc.getSingleplayerServer().isPublished()) {
return I18n.get("title.singleplayer");
Expand All @@ -78,17 +89,21 @@ public static boolean hasActivity() {
return clientPacketListener != null && clientPacketListener.getConnection().isConnected();
}

//#endif
public static void updatePlaceholders() {
// Maybe changed by other mods.
CustomWindowUtil.PLACEHOLDER_MAP.put("{mc_username}", TweakMyClient.getMinecraftClient().getUser().getName());
//#if MC >= 11500
// Activity data.
CustomWindowUtil.PLACEHOLDER_MAP.put("{mc_activity}", hasActivity() ? getActivity() : "Null");
//#endif
}

public static void updateFPS(int fps) {
CustomWindowUtil.PLACEHOLDER_MAP.put("{mc_fps}", String.valueOf(fps));
}

//#if MC >= 11500
public static void rebuildCache(TitleType type) {
if (type == TitleType.TITLE) {
TITLE_CACHE = CustomWindowUtil.replacePlaceholders(PLACEHOLDER_STATIC_MAP, Configs.customWindowTitle);
Expand All @@ -98,6 +113,12 @@ public static void rebuildCache(TitleType type) {
TITLE_CACHE_WITH_ACTIVITY = CustomWindowUtil.replaceModVersion(TITLE_CACHE_WITH_ACTIVITY);
}
}
//#else
//$$ public static void rebuildCache() {
//$$ TITLE_CACHE = CustomWindowUtil.replacePlaceholders(PLACEHOLDER_STATIC_MAP, Configs.customWindowTitle);
//$$ TITLE_CACHE = CustomWindowUtil.replaceModVersion(TITLE_CACHE);
//$$ }
//#endif

public static String replaceModVersion(String str) {
Matcher matcher = MOD_PATTERN.matcher(str);
Expand All @@ -109,10 +130,12 @@ public static String replaceModVersion(String str) {
return str;
}

//#if MC >= 11500
public enum TitleType {
TITLE,
TITLE_WITH_ACTIVITY
}
//#endif

public static void reSetTitle() {
//#if MC >= 11500
Expand Down

0 comments on commit aef7247

Please sign in to comment.