mirror of
https://github.com/chylex/Minecraft-Window-Title.git
synced 2024-11-24 20:42:48 +01:00
Compare commits
1 Commits
6854f05c05
...
15b922a6f2
Author | SHA1 | Date | |
---|---|---|---|
|
15b922a6f2 |
@ -5,7 +5,6 @@
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="openjdk-21" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
@ -11,8 +11,9 @@ import net.minecraft.client.Minecraft;
|
||||
|
||||
public class CustomWindowTitle implements ClientModInitializer {
|
||||
private final TitleConfig config;
|
||||
|
||||
public CustomWindowTitle() {
|
||||
config = TitleConfig.load(FabricLoader.getInstance().getConfigDir().toAbsolutePath().toString());
|
||||
config = TitleConfig.read(FabricLoader.getInstance().getConfigDir().toAbsolutePath().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,8 +15,8 @@ public class CustomWindowTitle {
|
||||
|
||||
private final TitleConfig config;
|
||||
|
||||
public CustomWindowTitle(final IEventBus eventBus) {
|
||||
config = TitleConfig.load(FMLPaths.CONFIGDIR.get().toString());
|
||||
public CustomWindowTitle(IEventBus eventBus) {
|
||||
config = TitleConfig.read(FMLPaths.CONFIGDIR.get().toString());
|
||||
eventBus.addListener(this::onClientSetup);
|
||||
CommonTokenData.register(new TokenProvider());
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import java.nio.IntBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class IconChanger {
|
||||
public class IconChanger {
|
||||
|
||||
public static void setIcon(final Path iconPath) {
|
||||
final long windowHandle = Minecraft.getInstance().getWindow().getWindow();
|
||||
|
@ -13,7 +13,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public final class TitleConfig {
|
||||
private static final Map<String, String> DEFAULTS;
|
||||
private static volatile TitleConfig instance = null;
|
||||
private static TitleConfig instance;
|
||||
|
||||
static {
|
||||
final Map<String, String> defaults = new LinkedHashMap<>();
|
||||
@ -22,16 +22,7 @@ public final class TitleConfig {
|
||||
DEFAULTS = Collections.unmodifiableMap(defaults);
|
||||
}
|
||||
|
||||
public static TitleConfig getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static TitleConfig load(final String folder) {
|
||||
if (instance != null)
|
||||
throw new IllegalStateException("TitleConfig has already been loaded and cannot be loaded again.");
|
||||
|
||||
if (instance == null) {
|
||||
synchronized (TitleConfig.class) {
|
||||
public static TitleConfig read(final String folder) {
|
||||
if (instance == null) {
|
||||
final Path configFile = Paths.get(folder, "customwindowtitle-client.toml");
|
||||
final Map<String, String> config = new LinkedHashMap<>(DEFAULTS);
|
||||
@ -47,11 +38,14 @@ public final class TitleConfig {
|
||||
.filter(line -> !line.isEmpty())
|
||||
.forEach(line -> {
|
||||
final String[] split = line.split("=", 2);
|
||||
|
||||
if (split.length != 2) {
|
||||
throw new RuntimeException("CustomWindowTitle configuration has an invalid line: " + line);
|
||||
}
|
||||
|
||||
final String key = split[0].trim();
|
||||
final String value = parseTrimmedValue(split[1].trim());
|
||||
|
||||
if (config.containsKey(key)) {
|
||||
config.put(key, value);
|
||||
} else {
|
||||
@ -64,15 +58,15 @@ public final class TitleConfig {
|
||||
}
|
||||
|
||||
final String iconPath = config.get("squareIcon");
|
||||
|
||||
final Path pathIcon = iconPath.isEmpty() ? null : Paths.get(folder, iconPath);
|
||||
|
||||
if (pathIcon != null && Files.notExists(pathIcon)) {
|
||||
throw new RuntimeException("CustomWindowTitle icon not found: " + pathIcon);
|
||||
}
|
||||
|
||||
instance = new TitleConfig(config.get("title"), pathIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -103,7 +97,9 @@ public final class TitleConfig {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
|
||||
public static TitleConfig getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
|
@ -15,4 +15,12 @@ public final class DisableVanillaTitle {
|
||||
private void updateTitle(final CallbackInfo info) {
|
||||
info.cancel();
|
||||
}
|
||||
|
||||
@Inject(method = "onResourceLoadFinished", at = @At("HEAD"))
|
||||
private void onFinishedLoading(final CallbackInfo callbackInfo) {
|
||||
final TitleConfig config = TitleConfig.getInstance();
|
||||
if (config != null && config.hasIcon()) {
|
||||
IconChanger.setIcon(config.getIconPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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(final CallbackInfo callbackInfo) {
|
||||
final TitleConfig config = TitleConfig.getInstance();
|
||||
if (config != null && config.hasIcon()) {
|
||||
IconChanger.setIcon(config.getIconPath());
|
||||
}
|
||||
}
|
||||
}
|
@ -5,8 +5,7 @@
|
||||
"refmap": "customwindowtitle.refmap.json",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"client": [
|
||||
"DisableVanillaTitle",
|
||||
"InitializeCustomIcon"
|
||||
"DisableVanillaTitle"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
Loading…
Reference in New Issue
Block a user