mirror of
https://github.com/chylex/Minecraft-Window-Title.git
synced 2024-11-24 20:42:48 +01:00
Compare commits
No commits in common. "73dab6b277457a17a7f12102ed6d4a9b3b83257b" and "ba22745940da89e0cc60737531d20eeb5f967aab" have entirely different histories.
73dab6b277
...
ba22745940
@ -11,7 +11,7 @@ public class CustomWindowTitle implements ClientModInitializer {
|
|||||||
private final TitleConfig config;
|
private final TitleConfig config;
|
||||||
|
|
||||||
public CustomWindowTitle() {
|
public CustomWindowTitle() {
|
||||||
config = TitleConfig.load(FabricLoader.getInstance().getConfigDir().toAbsolutePath().toString());
|
config = TitleConfig.read(FabricLoader.getInstance().getConfigDir().toAbsolutePath().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,33 +1,24 @@
|
|||||||
val modId: String by project
|
|
||||||
val neoForgeVersion: String by project
|
val neoForgeVersion: String by project
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("net.neoforged.moddev")
|
id("net.neoforged.gradle.userdev")
|
||||||
|
id("net.neoforged.gradle.mixin")
|
||||||
}
|
}
|
||||||
|
|
||||||
neoForge {
|
dependencies {
|
||||||
version = neoForgeVersion
|
implementation("net.neoforged:neoforge:$neoForgeVersion")
|
||||||
|
|
||||||
mods {
|
|
||||||
register(modId) {
|
|
||||||
sourceSet(sourceSets.main.get())
|
|
||||||
sourceSet(rootProject.sourceSets.main.get())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
runs {
|
runs {
|
||||||
val runJvmArgs: Set<String> by project
|
val runJvmArgs: Set<String> by project
|
||||||
|
|
||||||
configureEach {
|
configureEach {
|
||||||
gameDirectory = file("../run")
|
workingDirectory = file("../run")
|
||||||
jvmArguments.addAll(runJvmArgs)
|
modSource(project.sourceSets.main.get())
|
||||||
|
jvmArguments(runJvmArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
register("client") {
|
removeIf { it.name != "client" }
|
||||||
ideName.set("NeoForge Client")
|
|
||||||
client()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.processResources {
|
tasks.processResources {
|
||||||
|
@ -16,7 +16,7 @@ public class CustomWindowTitle {
|
|||||||
private final TitleConfig config;
|
private final TitleConfig config;
|
||||||
|
|
||||||
public CustomWindowTitle(IEventBus eventBus) {
|
public CustomWindowTitle(IEventBus eventBus) {
|
||||||
config = TitleConfig.load(FMLPaths.CONFIGDIR.get().toString());
|
config = TitleConfig.read(FMLPaths.CONFIGDIR.get().toString());
|
||||||
eventBus.addListener(this::onClientSetup);
|
eventBus.addListener(this::onClientSetup);
|
||||||
CommonTokenData.register(new TokenProvider());
|
CommonTokenData.register(new TokenProvider());
|
||||||
}
|
}
|
||||||
|
28
README.md
28
README.md
@ -14,7 +14,8 @@ To change the title or icon, navigate to the `.minecraft/config` folder, and ope
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
title = 'Minecraft {mcversion}'
|
title = 'Minecraft {mcversion}'
|
||||||
icon = ''
|
icon16 = ''
|
||||||
|
icon32 = ''
|
||||||
```
|
```
|
||||||
|
|
||||||
Only edit text inside quotes or apostrophes.
|
Only edit text inside quotes or apostrophes.
|
||||||
@ -31,30 +32,23 @@ If any of the tokens aren't working, search the game log for **CustomWindowTitle
|
|||||||
|
|
||||||
### Changing the Icon
|
### Changing the Icon
|
||||||
|
|
||||||
#### Minecraft 1.21+
|
**This feature is currently not supported in Minecraft 1.20+.**
|
||||||
|
|
||||||
**This feature is only available in Custom Window Title 1.4.0 and newer.**
|
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.
|
||||||
|
|
||||||
Create a square PNG image whose dimensions are a power of two, such as 32x32 or 48x48. Put the PNG file into the `.minecraft/config` folder, either directly or into a subfolder.
|
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 icon **must be saved with transparency** even if it doesn't use it, otherwise the icon may be corrupted or not appear at all. In Krita, for example, you must check _Store alpha channel (transparency)_ when saving.
|
* `.minecraft/config/customwindowtitle-client.toml`
|
||||||
|
* `.minecraft/config/customwindowtitle/icon16.png`
|
||||||
|
* `.minecraft/config/customwindowtitle/icon32.png`
|
||||||
|
|
||||||
The _icon_ configuration entry points to the PNG file relative to `.minecraft/config`.
|
Then, the two icon entries should look like this:
|
||||||
|
|
||||||
For example, if you placed the icon into `.minecraft/config/customwindowtitle/icon.png`, then the configuration entry should look like this:
|
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
icon = 'customwindowtitle/icon.png'
|
icon16 = 'customwindowtitle/icon16.png'
|
||||||
|
icon32 = 'customwindowtitle/icon32.png'
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Minecraft 1.20
|
|
||||||
|
|
||||||
This feature is not available in Minecraft 1.20.
|
|
||||||
|
|
||||||
#### Minecraft 1.19 and older
|
|
||||||
|
|
||||||
Instead of one `icon` configuration entry, there are two configuration entries `icon16` and `icon32` for icons with dimensions 16x16 and 32x32.
|
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||
These screenshots were taken using the following example configuration:
|
These screenshots were taken using the following example configuration:
|
||||||
|
@ -133,9 +133,11 @@ subprojects {
|
|||||||
archivesName.set("$modNameStripped-${project.name}")
|
archivesName.set("$modNameStripped-${project.name}")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.compileJava {
|
listOf("compileJava", "compileTestJava").forEach {
|
||||||
|
tasks.named<JavaCompile>(it) {
|
||||||
source({ rootProject.sourceSets.main.get().allSource })
|
source({ rootProject.sourceSets.main.get().allSource })
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tasks.processResources {
|
tasks.processResources {
|
||||||
from(rootProject.sourceSets.main.get().resources) {
|
from(rootProject.sourceSets.main.get().resources) {
|
||||||
|
@ -17,7 +17,6 @@ icon32 = ''
|
|||||||
```
|
```
|
||||||
|
|
||||||
Only edit text inside quotes or apostrophes.
|
Only edit text inside quotes or apostrophes.
|
||||||
|
|
||||||
### Changing the Title
|
### Changing the Title
|
||||||
|
|
||||||
You can use the following special tokens in the _title_ configuration entry:
|
You can use the following special tokens in the _title_ configuration entry:
|
||||||
@ -30,32 +29,24 @@ If any of the tokens aren't working, search the game log for **CustomWindowTitle
|
|||||||
|
|
||||||
### Changing the Icon
|
### Changing the Icon
|
||||||
|
|
||||||
#### Minecraft 1.21+
|
**This feature is currently not supported in Minecraft 1.20+.**
|
||||||
|
|
||||||
**This feature is only available in Custom Window Title 1.4.0 and newer.**
|
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.
|
||||||
|
|
||||||
Create a square PNG image whose dimensions are a power of two, such as 32x32 or 48x48. Put the PNG file into the `.minecraft/config` folder, either directly or into a subfolder.
|
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 icon **must be saved with transparency** even if it doesn't use it, otherwise the icon may be corrupted or not appear at all. In Krita, for example, you must check _Store alpha channel (transparency)_ when saving.
|
* `.minecraft/config/customwindowtitle-client.toml`
|
||||||
|
* `.minecraft/config/customwindowtitle/icon16.png`
|
||||||
|
* `.minecraft/config/customwindowtitle/icon32.png`
|
||||||
|
|
||||||
The _icon_ configuration entry points to the PNG file relative to `.minecraft/config`.
|
Then, the two icon entries should look like this:
|
||||||
|
|
||||||
For example, if you placed the icon into `.minecraft/config/customwindowtitle/icon.png`, then the configuration entry should look like this:
|
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
icon = 'customwindowtitle/icon.png'
|
icon16 = 'customwindowtitle/icon16.png'
|
||||||
|
icon32 = 'customwindowtitle/icon32.png'
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Minecraft 1.20
|
|
||||||
|
|
||||||
This feature is not available in Minecraft 1.20.
|
|
||||||
|
|
||||||
#### Minecraft 1.19 and older
|
|
||||||
|
|
||||||
Instead of one `icon` configuration entry, there are two configuration entries `icon16` and `icon32` for icons with dimensions 16x16 and 32x32.
|
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||
These screenshots were taken using the following example configuration:
|
These screenshots were taken using the following example configuration:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
|
@ -17,7 +17,6 @@ icon32 = ''
|
|||||||
```
|
```
|
||||||
|
|
||||||
Only edit text inside quotes or apostrophes.
|
Only edit text inside quotes or apostrophes.
|
||||||
|
|
||||||
### Changing the Title
|
### Changing the Title
|
||||||
|
|
||||||
You can use the following special tokens in the _title_ configuration entry:
|
You can use the following special tokens in the _title_ configuration entry:
|
||||||
@ -30,32 +29,24 @@ If any of the tokens aren't working, search the game log for **CustomWindowTitle
|
|||||||
|
|
||||||
### Changing the Icon
|
### Changing the Icon
|
||||||
|
|
||||||
#### Minecraft 1.21+
|
**This feature is currently not supported in Minecraft 1.20+.**
|
||||||
|
|
||||||
**This feature is only available in Custom Window Title 1.4.0 and newer.**
|
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.
|
||||||
|
|
||||||
Create a square PNG image whose dimensions are a power of two, such as 32x32 or 48x48. Put the PNG file into the `.minecraft/config` folder, either directly or into a subfolder.
|
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 icon **must be saved with transparency** even if it doesn't use it, otherwise the icon may be corrupted or not appear at all. In Krita, for example, you must check _Store alpha channel (transparency)_ when saving.
|
* `.minecraft/config/customwindowtitle-client.toml`
|
||||||
|
* `.minecraft/config/customwindowtitle/icon16.png`
|
||||||
|
* `.minecraft/config/customwindowtitle/icon32.png`
|
||||||
|
|
||||||
The _icon_ configuration entry points to the PNG file relative to `.minecraft/config`.
|
Then, the two icon entries should look like this:
|
||||||
|
|
||||||
For example, if you placed the icon into `.minecraft/config/customwindowtitle/icon.png`, then the configuration entry should look like this:
|
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
icon = 'customwindowtitle/icon.png'
|
icon16 = 'customwindowtitle/icon16.png'
|
||||||
|
icon32 = 'customwindowtitle/icon32.png'
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Minecraft 1.20
|
|
||||||
|
|
||||||
This feature is not available in Minecraft 1.20.
|
|
||||||
|
|
||||||
#### Minecraft 1.19 and older
|
|
||||||
|
|
||||||
Instead of one `icon` configuration entry, there are two configuration entries `icon16` and `icon32` for icons with dimensions 16x16 and 32x32.
|
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||
These screenshots were taken using the following example configuration:
|
These screenshots were taken using the following example configuration:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
# Mod
|
# Mod
|
||||||
modId=customwindowtitle
|
modId=customwindowtitle
|
||||||
modName=Custom Window Title
|
modName=Custom Window Title
|
||||||
modDescription=Customize window title and icon.
|
modDescription=Customize window title.
|
||||||
modAuthor=chylex
|
modAuthor=chylex
|
||||||
modVersion=1.4.0
|
modVersion=1.3.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
|
||||||
@ -12,12 +12,12 @@ modSides=client
|
|||||||
# Dependencies
|
# Dependencies
|
||||||
minecraftVersion=1.21
|
minecraftVersion=1.21
|
||||||
neoForgeVersion=21.0.0-beta
|
neoForgeVersion=21.0.0-beta
|
||||||
neoModDevVersion=1.0.21
|
neoGradleVersion=7.0.152
|
||||||
fabricVersion=0.15.11
|
fabricVersion=0.15.11
|
||||||
loomVersion=1.7
|
loomVersion=1.7
|
||||||
mixinVersion=0.12.5+mixin.0.8.5
|
mixinVersion=0.12.5+mixin.0.8.5
|
||||||
|
|
||||||
# https://projects.neoforged.net/neoforged/moddevgradle
|
# https://projects.neoforged.net/neoforged/neogradle/
|
||||||
# https://fabricmc.net/develop/
|
# https://fabricmc.net/develop/
|
||||||
# https://github.com/FabricMC/fabric-loom/releases
|
# https://github.com/FabricMC/fabric-loom/releases
|
||||||
|
|
||||||
|
@ -8,9 +8,10 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
val neoModDevVersion = settings.extra.get("neoModDevVersion") as? String
|
val neoGradleVersion = settings.extra.get("neoGradleVersion") as? String
|
||||||
if (neoModDevVersion != null) {
|
if (neoGradleVersion != null) {
|
||||||
id("net.neoforged.moddev") version neoModDevVersion
|
id("net.neoforged.gradle.userdev") version neoGradleVersion
|
||||||
|
id("net.neoforged.gradle.mixin") version neoGradleVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
val loomVersion = settings.extra.get("loomVersion") as? String
|
val loomVersion = settings.extra.get("loomVersion") as? String
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
package chylex.customwindowtitle;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
import org.lwjgl.glfw.GLFWImage;
|
|
||||||
import org.lwjgl.stb.STBImage;
|
|
||||||
import org.lwjgl.system.MemoryStack;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.IntBuffer;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public final class IconChanger {
|
|
||||||
private IconChanger() {}
|
|
||||||
|
|
||||||
public static void setIcon(Path iconPath) {
|
|
||||||
long windowHandle = Minecraft.getInstance().getWindow().getWindow();
|
|
||||||
setWindowIcon(windowHandle, iconPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setWindowIcon(long windowHandle, Path iconPath) {
|
|
||||||
try (MemoryStack stack = MemoryStack.stackPush()) {
|
|
||||||
IntBuffer w = stack.mallocInt(1);
|
|
||||||
IntBuffer h = stack.mallocInt(1);
|
|
||||||
IntBuffer channels = stack.mallocInt(1);
|
|
||||||
|
|
||||||
ByteBuffer icon = loadIcon(iconPath, w, h, channels);
|
|
||||||
if (icon == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try (GLFWImage glfwImage1 = GLFWImage.malloc(); GLFWImage glfwImage2 = GLFWImage.malloc(); GLFWImage.Buffer icons = GLFWImage.malloc(2)) {
|
|
||||||
glfwImage1.set(w.get(0), h.get(0), icon);
|
|
||||||
glfwImage2.set(w.get(0), h.get(0), icon);
|
|
||||||
|
|
||||||
icons.put(0, glfwImage1);
|
|
||||||
icons.put(1, glfwImage2);
|
|
||||||
|
|
||||||
GLFW.glfwSetWindowIcon(windowHandle, icons);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println("Failed to set window icon: " + iconPath);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ByteBuffer loadIcon(Path path, IntBuffer w, IntBuffer h, IntBuffer channels) throws IOException {
|
|
||||||
byte[] iconBytes = Files.readAllBytes(path);
|
|
||||||
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(iconBytes.length).put(iconBytes).flip();
|
|
||||||
ByteBuffer icon = STBImage.stbi_load_from_memory(buffer, w, h, channels, 4);
|
|
||||||
|
|
||||||
if (icon == null) {
|
|
||||||
System.err.println("Failed to load image from memory for: " + path + " - " + STBImage.stbi_failure_reason());
|
|
||||||
}
|
|
||||||
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,7 @@
|
|||||||
package chylex.customwindowtitle;
|
package chylex.customwindowtitle;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@ -11,79 +12,47 @@ 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 String KEY_TITLE = "title";
|
|
||||||
private static final String KEY_ICON = "icon";
|
|
||||||
|
|
||||||
private static final ImmutableMap<String, String> DEFAULTS = ImmutableMap.<String, String>builder()
|
private static final ImmutableMap<String, String> DEFAULTS = ImmutableMap.<String, String>builder()
|
||||||
.put(KEY_TITLE, "Minecraft {mcversion}")
|
.put("title", "Minecraft {mcversion}")
|
||||||
.put(KEY_ICON, "")
|
.build();
|
||||||
.buildOrThrow();
|
|
||||||
|
|
||||||
private static volatile TitleConfig instance;
|
private static final ImmutableSet<String> IGNORED_KEYS = ImmutableSet.of(
|
||||||
|
"icon16",
|
||||||
|
"icon32"
|
||||||
|
);
|
||||||
|
|
||||||
public static TitleConfig getInstance() {
|
public static TitleConfig read(final String folder) {
|
||||||
return instance;
|
final Path configFile = Paths.get(folder, "customwindowtitle-client.toml");
|
||||||
}
|
final Map<String, String> config = new LinkedHashMap<>(DEFAULTS);
|
||||||
|
|
||||||
public static TitleConfig load(String folder) {
|
|
||||||
if (instance != null) {
|
|
||||||
throw new IllegalStateException("TitleConfig has already been loaded and cannot be loaded again.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (instance == null) {
|
|
||||||
synchronized(TitleConfig.class) {
|
|
||||||
if (instance == null) {
|
|
||||||
instance = loadImpl(folder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TitleConfig loadImpl(String folder) {
|
|
||||||
Path configFile = Paths.get(folder, "customwindowtitle-client.toml");
|
|
||||||
Map<String, String> config = new LinkedHashMap<>(DEFAULTS);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!Files.exists(configFile)) {
|
if (!Files.exists(configFile)) {
|
||||||
Files.write(configFile, config.entrySet().stream()
|
Files.write(configFile, config.entrySet().stream().map(entry -> String.format("%s = '%s'", entry.getKey(), entry.getValue())).collect(Collectors.toList()), StandardCharsets.UTF_8);
|
||||||
.map(entry -> String.format("%s = '%s'", entry.getKey(), entry.getValue()))
|
|
||||||
.collect(Collectors.toList()), StandardCharsets.UTF_8);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Files.readAllLines(configFile, StandardCharsets.UTF_8).stream()
|
Files.readAllLines(configFile, StandardCharsets.UTF_8).stream().map(String::trim).filter(line -> !line.isEmpty()).forEach(line -> {
|
||||||
.map(String::trim)
|
final String[] split = line.split("=", 2);
|
||||||
.filter(line -> !line.isEmpty())
|
|
||||||
.forEach(line -> {
|
|
||||||
String[] split = line.split("=", 2);
|
|
||||||
|
|
||||||
if (split.length != 2) {
|
if (split.length != 2) {
|
||||||
throw new RuntimeException("CustomWindowTitle configuration has an invalid line: " + line);
|
throw new RuntimeException("CustomWindowTitle configuration has an invalid line: " + line);
|
||||||
}
|
}
|
||||||
|
|
||||||
String key = split[0].trim();
|
final String key = split[0].trim();
|
||||||
String value = parseTrimmedValue(split[1].trim());
|
final String value = parseTrimmedValue(split[1].trim());
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
throw new RuntimeException("CustomWindowTitle configuration error", e);
|
throw new RuntimeException("CustomWindowTitle configuration error", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
String iconPathStr = config.get(KEY_ICON);
|
return new TitleConfig(config.get("title"));
|
||||||
Path iconPath = iconPathStr.isEmpty() ? null : Paths.get(folder, iconPathStr);
|
|
||||||
if (iconPath != null && Files.notExists(iconPath)) {
|
|
||||||
throw new RuntimeException("CustomWindowTitle configuration points to a missing icon: " + iconPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new TitleConfig(config.get(KEY_TITLE), iconPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String parseTrimmedValue(String value) {
|
private static String parseTrimmedValue(String value) {
|
||||||
@ -106,22 +75,12 @@ public final class TitleConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final String title;
|
private final String title;
|
||||||
private final Path icon;
|
|
||||||
|
|
||||||
private TitleConfig(final String title, final Path icon) {
|
private TitleConfig(final String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.icon = icon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasIcon() {
|
|
||||||
return icon != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Path getIconPath() {
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
package chylex.customwindowtitle.mixin;
|
|
||||||
|
|
||||||
import chylex.customwindowtitle.IconChanger;
|
|
||||||
import chylex.customwindowtitle.TitleConfig;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(Minecraft.class)
|
|
||||||
public final class InitializeCustomIcon {
|
|
||||||
@Inject(method = "onResourceLoadFinished", at = @At("HEAD"))
|
|
||||||
private void onFinishedLoading(CallbackInfo callbackInfo) {
|
|
||||||
TitleConfig config = TitleConfig.getInstance();
|
|
||||||
if (config != null && config.hasIcon()) {
|
|
||||||
IconChanger.setIcon(config.getIconPath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,8 +5,7 @@
|
|||||||
"refmap": "customwindowtitle.refmap.json",
|
"refmap": "customwindowtitle.refmap.json",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"client": [
|
"client": [
|
||||||
"DisableVanillaTitle",
|
"DisableVanillaTitle"
|
||||||
"InitializeCustomIcon"
|
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
Loading…
Reference in New Issue
Block a user