1
0
mirror of https://github.com/chylex/Minecraft-Window-Title.git synced 2024-11-25 23:42:45 +01:00

Compare commits

...

6 Commits

15 changed files with 68 additions and 104 deletions

51
.gitignore vendored
View File

@ -1,29 +1,30 @@
bin/
[Bb]uild/
eclipse/
run/
out/
# gradle
.gradle/
.idea/$CACHE_FILE$
.idea/codeStyles/
.idea/compiler.xml
.idea/dictionaries
.idea/inspectionProfiles/
.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
build/
out/
classes/
# eclipse
*.launch
# idea
.idea/
*.iml
*.ipr
*.iws
Thumbs.db
# vscode
.settings/
.vscode/
bin/
.classpath
.project
# fabric
run/
logs/

View File

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

View File

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

View File

@ -15,7 +15,7 @@ buildscript {
}
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")
}
}
@ -41,6 +41,8 @@ dependencies {
configure<UserDevExtension> {
mappings("official", minecraftVersion)
copyIdeResources.set(true)
runs {
create("client") {
taskName = "Client"

View File

@ -1,8 +1,8 @@
package chylex.customwindowtitle.forge;
import chylex.customwindowtitle.TitleConfig;
import chylex.customwindowtitle.TitleParser;
import chylex.customwindowtitle.data.CommonTokenData;
import com.mojang.blaze3d.platform.Window;
import net.minecraft.client.Minecraft;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.IExtensionPoint.DisplayTest;
@ -29,11 +29,6 @@ public class CustomWindowTitle {
}
private void updateTitle() {
final Window window = Minecraft.getInstance().getWindow();
window.setTitle(TitleParser.parse(config.getTitle()));
if (config.hasIcon()) {
window.setIcon(config.readIcon16(), config.readIcon32());
}
Minecraft.getInstance().getWindow().setTitle(TitleParser.parse(config.getTitle()));
}
}

View File

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

View File

@ -1,16 +1,16 @@
modLoader = "javafml"
loaderVersion = "[0,)"
authors = "${author}"
license = "${license}"
issueTrackerURL = "${issuesURL}"
[[mods]]
modId = "${id}"
version = "${version}"
displayName = "${name}"
description = "${description}"
displayURL = "${sourcesURL}"
description = "${description}"
authors = "${author}"
version = "${version}"
[[dependencies.${id}]]
modId = "minecraft"

View File

@ -31,6 +31,8 @@ If any of the tokens aren't working, search the game log for **CustomWindowTitle
### 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.
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

@ -3,21 +3,21 @@ modId=customwindowtitle
modName=Custom Window Title
modDescription=Customize window title and icon.
modAuthor=chylex
modVersion=1.1.2
modVersion=1.2.0
modLicense=Unlicense
modSourcesURL=https://github.com/chylex/Minecraft-Window-Title
modIssuesURL=https://github.com/chylex/Minecraft-Window-Title/issues
# Dependencies
minecraftVersion=1.19.3
forgeVersion=44.1.0
fabricVersion=0.14.12
loomVersion=0.12
minecraftVersion=1.20
#forgeVersion=46.0.1
fabricVersion=0.14.21
loomVersion=1.2
mixinVersion=0.8.5
# Constraints
minimumMinecraftVersion=1.19.3
minimumForgeVersion=44.0.0
minimumMinecraftVersion=1.20
minimumForgeVersion=46.0.0
minimumFabricVersion=0.12.3
# Gradle

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
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
zipStorePath=wrapper/dists

View File

@ -1,28 +1,25 @@
package chylex.customwindowtitle;
import net.minecraft.server.packs.resources.IoSupplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
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 {
final Map<String, String> defaults = new LinkedHashMap<>();
defaults.put("title", "Minecraft {mcversion}");
defaults.put("icon16", "");
defaults.put("icon32", "");
DEFAULTS = Collections.unmodifiableMap(defaults);
}
private static final ImmutableSet<String> IGNORED_KEYS = ImmutableSet.of(
"icon16",
"icon32"
);
public static TitleConfig read(final String folder) {
final Path configFile = Paths.get(folder, "customwindowtitle-client.toml");
@ -46,7 +43,7 @@ public final class TitleConfig {
if (config.containsKey(key)) {
config.put(key, value);
}
else {
else if (!IGNORED_KEYS.contains(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);
}
final String icon16 = config.get("icon16");
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);
return new TitleConfig(config.get("title"));
}
private static String parseTrimmedValue(String value) {
@ -96,28 +75,12 @@ public final class TitleConfig {
}
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.icon16 = icon16;
this.icon32 = icon32;
}
public String getTitle() {
return title;
}
public boolean hasIcon() {
return icon16 != null && icon32 != null;
}
public IoSupplier<InputStream> readIcon16() {
return IoSupplier.create(icon16);
}
public IoSupplier<InputStream> readIcon32() {
return IoSupplier.create(icon32);
}
}

View File

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

View File

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

View File

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

View File

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