1
0
mirror of https://github.com/chylex/Minecraft-Window-Title.git synced 2025-09-15 17:32:14 +02:00

10 Commits

22 changed files with 120 additions and 138 deletions

51
.gitignore vendored
View File

@@ -1,29 +1,30 @@
bin/ # gradle
[Bb]uild/
eclipse/
run/
out/
.gradle/ .gradle/
.idea/$CACHE_FILE$ build/
.idea/codeStyles/ out/
.idea/compiler.xml classes/
.idea/dictionaries
.idea/inspectionProfiles/ # eclipse
.idea/jarRepositories.xml
.idea/libraries/
.idea/misc.xml
.idea/modules/
.idea/modules.xml
.idea/runConfigurations/
.idea/shelf/
.idea/uiDesigner.xml
.idea/workspace.xml
.settings/
.updateclasses/
.classpath
.project
.DS_Store
*.launch *.launch
# idea
.idea/
*.iml
*.ipr *.ipr
*.iws *.iws
Thumbs.db
# vscode
.settings/
.vscode/
bin/
.classpath
.project
# fabric
run/
logs/

View File

@@ -4,7 +4,7 @@ val fabricVersion: String by project
plugins { plugins {
idea idea
id("fabric-loom") version "0.10-SNAPSHOT" id("fabric-loom")
} }
dependencies { dependencies {

View File

@@ -1,8 +1,8 @@
package chylex.customwindowtitle.fabric; package chylex.customwindowtitle.fabric;
import chylex.customwindowtitle.TitleConfig; import chylex.customwindowtitle.TitleConfig;
import chylex.customwindowtitle.TitleParser; import chylex.customwindowtitle.TitleParser;
import chylex.customwindowtitle.data.CommonTokenData; import chylex.customwindowtitle.data.CommonTokenData;
import com.mojang.blaze3d.platform.Window;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@@ -11,7 +11,7 @@ public class CustomWindowTitle implements ClientModInitializer {
private final TitleConfig config; private final TitleConfig config;
public CustomWindowTitle() { public CustomWindowTitle() {
config = TitleConfig.read(FabricLoader.getInstance().getConfigDirectory().getAbsolutePath()); config = TitleConfig.read(FabricLoader.getInstance().getConfigDir().toAbsolutePath().toString());
} }
@Override @Override
@@ -21,11 +21,6 @@ public class CustomWindowTitle implements ClientModInitializer {
} }
private void updateTitle() { private void updateTitle() {
final Window window = Minecraft.getInstance().getWindow(); Minecraft.getInstance().getWindow().setTitle(TitleParser.parse(config.getTitle()));
window.setTitle(TitleParser.parse(config.getTitle()));
if (config.hasIcon()) {
window.setIcon(config.readIcon16(), config.readIcon32());
}
} }
} }

View File

@@ -1,4 +1,5 @@
package chylex.customwindowtitle.fabric; package chylex.customwindowtitle.fabric;
import chylex.customwindowtitle.TokenException; import chylex.customwindowtitle.TokenException;
import chylex.customwindowtitle.data.CommonTokenProvider; import chylex.customwindowtitle.data.CommonTokenProvider;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;

View File

@@ -1,6 +1,6 @@
{ {
"schemaVersion": 1, "schemaVersion": 1,
"id": "customwindowtitle", "id": "${id}",
"name": "${name}", "name": "${name}",
"description": "${description}", "description": "${description}",
"version": "${version}", "version": "${version}",
@@ -22,12 +22,13 @@
"chylex.customwindowtitle.fabric.CustomWindowTitle" "chylex.customwindowtitle.fabric.CustomWindowTitle"
] ]
}, },
"mixins": [
"customwindowtitle.mixins.json" "mixins": [{
], "config": "${id}.mixins.json"
}],
"depends": { "depends": {
"fabricloader": ">=0.7.2", "fabricloader": ">=${minimumFabricVersion}",
"minecraft": ">=1.17" "minecraft": ">=${minimumMinecraftVersion}"
} }
} }

View File

@@ -15,7 +15,7 @@ buildscript {
} }
dependencies { dependencies {
classpath(group = "net.minecraftforge.gradle", name = "ForgeGradle", version = "5.1.+") { isChanging = true } classpath(group = "net.minecraftforge.gradle", name = "ForgeGradle", version = "[6.0,6.2)")
classpath(group = "org.spongepowered", name = "mixingradle", version = "0.7-SNAPSHOT") classpath(group = "org.spongepowered", name = "mixingradle", version = "0.7-SNAPSHOT")
} }
} }
@@ -41,6 +41,8 @@ dependencies {
configure<UserDevExtension> { configure<UserDevExtension> {
mappings("official", minecraftVersion) mappings("official", minecraftVersion)
copyIdeResources.set(true)
runs { runs {
create("client") { create("client") {
taskName = "Client" taskName = "Client"

View File

@@ -1,8 +1,8 @@
package chylex.customwindowtitle.forge; package chylex.customwindowtitle.forge;
import chylex.customwindowtitle.TitleConfig; import chylex.customwindowtitle.TitleConfig;
import chylex.customwindowtitle.TitleParser; import chylex.customwindowtitle.TitleParser;
import chylex.customwindowtitle.data.CommonTokenData; import chylex.customwindowtitle.data.CommonTokenData;
import com.mojang.blaze3d.platform.Window;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.IExtensionPoint.DisplayTest; import net.minecraftforge.fml.IExtensionPoint.DisplayTest;
@@ -11,7 +11,6 @@ import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLPaths; import net.minecraftforge.fml.loading.FMLPaths;
import net.minecraftforge.fmllegacy.network.FMLNetworkConstants;
@Mod("customwindowtitle") @Mod("customwindowtitle")
public class CustomWindowTitle { public class CustomWindowTitle {
@@ -19,7 +18,7 @@ public class CustomWindowTitle {
public CustomWindowTitle() { public CustomWindowTitle() {
config = TitleConfig.read(FMLPaths.CONFIGDIR.get().toString()); config = TitleConfig.read(FMLPaths.CONFIGDIR.get().toString());
ModLoadingContext.get().registerExtensionPoint(DisplayTest.class, () -> new DisplayTest(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true)); ModLoadingContext.get().registerExtensionPoint(DisplayTest.class, () -> new DisplayTest(() -> DisplayTest.IGNORESERVERONLY, (a, b) -> true));
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onClientSetup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onClientSetup);
CommonTokenData.register(new TokenProvider()); CommonTokenData.register(new TokenProvider());
} }
@@ -30,11 +29,6 @@ public class CustomWindowTitle {
} }
private void updateTitle() { private void updateTitle() {
final Window window = Minecraft.getInstance().getWindow(); Minecraft.getInstance().getWindow().setTitle(TitleParser.parse(config.getTitle()));
window.setTitle(TitleParser.parse(config.getTitle()));
if (config.hasIcon()) {
window.setIcon(config.readIcon16(), config.readIcon32());
}
} }
} }

View File

@@ -1,4 +1,5 @@
package chylex.customwindowtitle.forge; package chylex.customwindowtitle.forge;
import chylex.customwindowtitle.TokenException; import chylex.customwindowtitle.TokenException;
import chylex.customwindowtitle.data.CommonTokenProvider; import chylex.customwindowtitle.data.CommonTokenProvider;
import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.ModList;

View File

@@ -1,27 +1,27 @@
modLoader = "javafml" modLoader = "javafml"
loaderVersion = "[31,)" loaderVersion = "[0,)"
authors = "${author}"
license = "${license}" license = "${license}"
issueTrackerURL = "${issuesURL}" issueTrackerURL = "${issuesURL}"
[[mods]] [[mods]]
modId = "customwindowtitle" modId = "${id}"
version = "${version}"
displayName = "${name}" displayName = "${name}"
description = "${description}"
displayURL = "${sourcesURL}" displayURL = "${sourcesURL}"
description = "${description}"
authors = "${author}"
version = "${version}"
[[dependencies.customwindowtitle]] [[dependencies.${id}]]
modId = "minecraft" modId = "minecraft"
mandatory = true mandatory = true
versionRange = "[1.17,)" versionRange = "[${minimumMinecraftVersion},)"
ordering = "NONE" ordering = "NONE"
side = "CLIENT" side = "CLIENT"
[[dependencies.customwindowtitle]] [[dependencies.${id}]]
modId = "forge" modId = "forge"
mandatory = true mandatory = true
versionRange = "[31.2.45,)" versionRange = "[${minimumForgeVersion},)"
ordering = "NONE" ordering = "NONE"
side = "CLIENT" side = "CLIENT"

View File

@@ -1,7 +0,0 @@
{
"pack": {
"description": "Custom Window Title",
"pack_format": 5,
"_comment": ""
}
}

View File

@@ -31,6 +31,8 @@ If any of the tokens aren't working, search the game log for **CustomWindowTitle
### Changing the Icon ### Changing the Icon
**This feature is currently not supported in Minecraft 1.20.**
You must create two PNG images with sizes 16x16 and 32x32 pixels. The images **must be saved with transparency** even if they don't use it, **otherwise the icons will appear corrupted**. In Krita for example, you must check _Store alpha channel (transparency)_ when saving the image. You must create two PNG images with sizes 16x16 and 32x32 pixels. The images **must be saved with transparency** even if they don't use it, **otherwise the icons will appear corrupted**. In Krita for example, you must check _Store alpha channel (transparency)_ when saving the image.
The _icon16_ and _icon32_ configuration entries point to the PNG files relative to the **.minecraft/config** folder. For example, if you place the two icons in a folder named _customwindowtitle_ as follows: The _icon16_ and _icon32_ configuration entries point to the PNG files relative to the **.minecraft/config** folder. For example, if you place the two icons in a folder named _customwindowtitle_ as follows:

View File

@@ -14,6 +14,10 @@ val modIssuesURL: String by project
val minecraftVersion: String by project val minecraftVersion: String by project
val mixinVersion: String by project val mixinVersion: String by project
val minimumMinecraftVersion: String by project
val minimumForgeVersion: String by project
val minimumFabricVersion: String by project
val modNameStripped = modName.replace(" ", "") val modNameStripped = modName.replace(" ", "")
val jarVersion = "$minecraftVersion+v$modVersion" val jarVersion = "$minecraftVersion+v$modVersion"
@@ -74,12 +78,12 @@ allprojects {
} }
extensions.getByType<JavaPluginExtension>().apply { extensions.getByType<JavaPluginExtension>().apply {
toolchain.languageVersion.set(JavaLanguageVersion.of(16)) toolchain.languageVersion.set(JavaLanguageVersion.of(17))
} }
tasks.withType<JavaCompile> { tasks.withType<JavaCompile> {
options.encoding = "UTF-8" options.encoding = "UTF-8"
options.release.set(16) options.release.set(17)
} }
} }
@@ -101,8 +105,7 @@ subprojects {
} }
tasks.processResources { tasks.processResources {
from(rootProject.sourceSets.main.get().resources) inputs.property("id", modId)
inputs.property("name", modName) inputs.property("name", modName)
inputs.property("description", modDescription) inputs.property("description", modDescription)
inputs.property("version", modVersion) inputs.property("version", modVersion)
@@ -110,6 +113,13 @@ subprojects {
inputs.property("license", modLicense) inputs.property("license", modLicense)
inputs.property("sourcesURL", modSourcesURL) inputs.property("sourcesURL", modSourcesURL)
inputs.property("issuesURL", modIssuesURL) inputs.property("issuesURL", modIssuesURL)
inputs.property("minimumMinecraftVersion", minimumMinecraftVersion)
inputs.property("minimumForgeVersion", minimumForgeVersion)
inputs.property("minimumFabricVersion", minimumFabricVersion)
from(rootProject.sourceSets.main.get().resources) {
expand(inputs.properties)
}
} }
tasks.jar { tasks.jar {
@@ -130,6 +140,10 @@ subprojects {
) )
} }
} }
tasks.test {
onlyIf { false }
}
} }
tasks.register("setupIdea") { tasks.register("setupIdea") {

View File

@@ -3,16 +3,22 @@ modId=customwindowtitle
modName=Custom Window Title modName=Custom Window Title
modDescription=Customize window title and icon. modDescription=Customize window title and icon.
modAuthor=chylex modAuthor=chylex
modVersion=1.1.1 modVersion=1.2.0
modLicense=Unlicense modLicense=Unlicense
modSourcesURL=https://github.com/chylex/Minecraft-Window-Title modSourcesURL=https://github.com/chylex/Minecraft-Window-Title
modIssuesURL=https://github.com/chylex/Minecraft-Window-Title/issues modIssuesURL=https://github.com/chylex/Minecraft-Window-Title/issues
# Dependencies # Dependencies
minecraftVersion=1.17.1 minecraftVersion=1.20
forgeVersion=37.0.75 #forgeVersion=46.0.1
fabricVersion=0.11.7 fabricVersion=0.14.21
mixinVersion=0.8.4 loomVersion=1.2
mixinVersion=0.8.5
# Constraints
minimumMinecraftVersion=1.20
minimumForgeVersion=46.0.0
minimumFabricVersion=0.12.3
# Gradle # Gradle
org.gradle.jvmargs=-Xmx3G org.gradle.jvmargs=-Xmx3G

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@@ -6,6 +6,12 @@ pluginManagement {
maven(url = "https://maven.fabricmc.net/") { name = "Fabric" } maven(url = "https://maven.fabricmc.net/") { name = "Fabric" }
maven(url = "https://repo.spongepowered.org/repository/maven-public/") { name = "Sponge Snapshots" } maven(url = "https://repo.spongepowered.org/repository/maven-public/") { name = "Sponge Snapshots" }
} }
plugins {
if (settings.extra.has("loomVersion")) {
id("fabric-loom") version "${settings.extra["loomVersion"]}-SNAPSHOT"
}
}
} }
if (settings.extra.has("forgeVersion")) { if (settings.extra.has("forgeVersion")) {

View File

@@ -1,28 +1,25 @@
package chylex.customwindowtitle; package chylex.customwindowtitle;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public final class TitleConfig { public final class TitleConfig {
private static final Map<String, String> DEFAULTS; private static final ImmutableMap<String, String> DEFAULTS = ImmutableMap.<String, String>builder()
.put("title", "Minecraft {mcversion}")
.build();
static { private static final ImmutableSet<String> IGNORED_KEYS = ImmutableSet.of(
final Map<String, String> defaults = new LinkedHashMap<>(); "icon16",
"icon32"
defaults.put("title", "Minecraft {mcversion}"); );
defaults.put("icon16", "");
defaults.put("icon32", "");
DEFAULTS = Collections.unmodifiableMap(defaults);
}
public static TitleConfig read(final String folder) { public static TitleConfig read(final String folder) {
final Path configFile = Paths.get(folder, "customwindowtitle-client.toml"); final Path configFile = Paths.get(folder, "customwindowtitle-client.toml");
@@ -46,7 +43,7 @@ public final class TitleConfig {
if (config.containsKey(key)) { if (config.containsKey(key)) {
config.put(key, value); config.put(key, value);
} }
else { else if (!IGNORED_KEYS.contains(key)) {
throw new RuntimeException("CustomWindowTitle configuration has an invalid key: " + key); throw new RuntimeException("CustomWindowTitle configuration has an invalid key: " + key);
} }
}); });
@@ -55,25 +52,7 @@ public final class TitleConfig {
throw new RuntimeException("CustomWindowTitle configuration error", e); throw new RuntimeException("CustomWindowTitle configuration error", e);
} }
final String icon16 = config.get("icon16"); return new TitleConfig(config.get("title"));
final String icon32 = config.get("icon32");
final Path pathIcon16 = icon16.isEmpty() ? null : Paths.get(folder, icon16);
final Path pathIcon32 = icon32.isEmpty() ? null : Paths.get(folder, icon32);
if ((pathIcon16 == null) != (pathIcon32 == null)) {
throw new RuntimeException("CustomWindowTitle configuration specifies only one icon, both 'icon16' and 'icon32' must be set.");
}
if (pathIcon16 != null && Files.notExists(pathIcon16)) {
throw new RuntimeException("CustomWindowTitle 16x16 icon not found: " + pathIcon16);
}
if (pathIcon32 != null && Files.notExists(pathIcon32)) {
throw new RuntimeException("CustomWindowTitle 32x32 icon not found: " + pathIcon32);
}
return new TitleConfig(config.get("title"), pathIcon16, pathIcon32);
} }
private static String parseTrimmedValue(String value) { private static String parseTrimmedValue(String value) {
@@ -96,36 +75,12 @@ public final class TitleConfig {
} }
private final String title; private final String title;
private final Path icon16;
private final Path icon32;
private TitleConfig(final String title, final Path icon16, final Path icon32) { private TitleConfig(final String title) {
this.title = title; this.title = title;
this.icon16 = icon16;
this.icon32 = icon32;
} }
public String getTitle() { public String getTitle() {
return title; return title;
} }
public boolean hasIcon() {
return icon16 != null && icon32 != null;
}
public InputStream readIcon16() {
try {
return Files.newInputStream(icon16, StandardOpenOption.READ);
} catch (final IOException e) {
throw new RuntimeException("CustomWindowTitle could not open the specified 16x16 icon: " + icon16, e);
}
}
public InputStream readIcon32() {
try {
return Files.newInputStream(icon32, StandardOpenOption.READ);
} catch (final IOException e) {
throw new RuntimeException("CustomWindowTitle could not open the specified 32x32 icon: " + icon16, e);
}
}
} }

View File

@@ -1,4 +1,5 @@
package chylex.customwindowtitle; package chylex.customwindowtitle;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@@ -11,7 +12,7 @@ public final class TitleParser {
private static final Logger logger = LogManager.getLogger("CustomWindowTitle"); private static final Logger logger = LogManager.getLogger("CustomWindowTitle");
public static String parse(final String input) { public static String parse(final String input) {
final StringBuffer buffer = new StringBuffer(); final StringBuilder buffer = new StringBuilder();
final Matcher matcher = tokenRegex.matcher(input); final Matcher matcher = tokenRegex.matcher(input);
while (matcher.find()) { while (matcher.find()) {

View File

@@ -1,4 +1,5 @@
package chylex.customwindowtitle; package chylex.customwindowtitle;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;

View File

@@ -1,9 +1,10 @@
package chylex.customwindowtitle.data; package chylex.customwindowtitle.data;
import net.minecraft.client.Minecraft;
import net.minecraft.SharedConstants;
public interface CommonTokenProvider { public interface CommonTokenProvider {
default String getMinecraftVersion() { default String getMinecraftVersion() {
return Minecraft.getInstance().getGame().getVersion().getName(); return SharedConstants.getCurrentVersion().getName();
} }
String getModVersion(final String modId); String getModVersion(final String modId);

View File

@@ -1,4 +1,5 @@
package chylex.customwindowtitle.mixin; package chylex.customwindowtitle.mixin;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;

View File

@@ -3,7 +3,7 @@
"minVersion": "0.8", "minVersion": "0.8",
"package": "chylex.customwindowtitle.mixin", "package": "chylex.customwindowtitle.mixin",
"refmap": "customwindowtitle.refmap.json", "refmap": "customwindowtitle.refmap.json",
"compatibilityLevel": "JAVA_16", "compatibilityLevel": "JAVA_17",
"client": [ "client": [
"DisableVanillaTitle" "DisableVanillaTitle"
], ],

View File

@@ -0,0 +1,7 @@
{
"pack": {
"description": "${name}",
"pack_format": 7,
"_comment": ""
}
}