mirror of
https://github.com/chylex/Minecraft-Window-Title.git
synced 2026-02-15 08:06:16 +01:00
Compare commits
9 Commits
73dab6b277
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
b17a1cb5cc
|
|||
|
4aa5d7d945
|
|||
|
50d77446f5
|
|||
|
1f92896e55
|
|||
|
2a17b46a1d
|
|||
|
|
5e64fd81e3 | ||
|
425eb3f380
|
|||
|
43698d23b5
|
|||
|
dbbd5b60f5
|
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -1,3 +1 @@
|
|||||||
github: chylex
|
|
||||||
patreon: chylex
|
|
||||||
ko_fi: chylex
|
ko_fi: chylex
|
||||||
|
|||||||
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -12,6 +12,7 @@
|
|||||||
<option value="$PROJECT_DIR$/NeoForge" />
|
<option value="$PROJECT_DIR$/NeoForge" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
|
<option name="resolveExternalAnnotations" value="true" />
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import net.fabricmc.loom.configuration.ide.RunConfigSettings
|
||||||
import org.gradle.jvm.tasks.Jar
|
import org.gradle.jvm.tasks.Jar
|
||||||
|
|
||||||
val modId: String by project
|
val modId: String by project
|
||||||
|
val modSides: String by project
|
||||||
val minecraftVersion: String by project
|
val minecraftVersion: String by project
|
||||||
val fabricVersion: String by project
|
val fabricVersion: String by project
|
||||||
|
|
||||||
@@ -24,12 +26,24 @@ loom {
|
|||||||
ideConfigGenerated(true)
|
ideConfigGenerated(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
named("client") {
|
fun side(name: String, configure: RunConfigSettings.() -> Unit) {
|
||||||
|
if (modSides == "both" || modSides == name) {
|
||||||
|
named(name, configure)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
findByName(name)?.let(::remove)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
side("client") {
|
||||||
configName = "Fabric Client"
|
configName = "Fabric Client"
|
||||||
client()
|
client()
|
||||||
}
|
}
|
||||||
|
|
||||||
findByName("server")?.let(::remove)
|
side("server") {
|
||||||
|
configName = "Fabric Server"
|
||||||
|
server()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mixin {
|
mixin {
|
||||||
@@ -47,7 +61,7 @@ tasks.register<Jar>("uncompressedRemapJar") {
|
|||||||
group = "fabric"
|
group = "fabric"
|
||||||
|
|
||||||
from(tasks.remapJar.map { it.outputs.files.map(::zipTree) })
|
from(tasks.remapJar.map { it.outputs.files.map(::zipTree) })
|
||||||
|
|
||||||
archiveClassifier.set("uncompressed")
|
archiveClassifier.set("uncompressed")
|
||||||
entryCompression = ZipEntryCompression.STORED // Reduces size of multiloader jar.
|
entryCompression = ZipEntryCompression.STORED // Reduces size of multiloader jar.
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package chylex.customwindowtitle.fabric;
|
package chylex.customwindowtitle.fabric;
|
||||||
|
|
||||||
|
import chylex.customwindowtitle.TitleChanger;
|
||||||
import chylex.customwindowtitle.TitleConfig;
|
import chylex.customwindowtitle.TitleConfig;
|
||||||
import chylex.customwindowtitle.TitleParser;
|
|
||||||
import chylex.customwindowtitle.data.CommonTokenData;
|
import chylex.customwindowtitle.data.CommonTokenData;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
@@ -17,10 +17,6 @@ public class CustomWindowTitle implements ClientModInitializer {
|
|||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
CommonTokenData.register(new TokenProvider());
|
CommonTokenData.register(new TokenProvider());
|
||||||
Minecraft.getInstance().execute(this::updateTitle);
|
Minecraft.getInstance().execute(() -> TitleChanger.setTitle(config));
|
||||||
}
|
|
||||||
|
|
||||||
private void updateTitle() {
|
|
||||||
Minecraft.getInstance().getWindow().setTitle(TitleParser.parse(config.getTitle()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
import net.neoforged.moddevgradle.dsl.RunModel
|
||||||
|
|
||||||
val modId: String by project
|
val modId: String by project
|
||||||
|
val modSides: String by project
|
||||||
val neoForgeVersion: String by project
|
val neoForgeVersion: String by project
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
@@ -23,10 +26,21 @@ neoForge {
|
|||||||
jvmArguments.addAll(runJvmArgs)
|
jvmArguments.addAll(runJvmArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
register("client") {
|
fun side(name: String, configure: RunModel.() -> Unit) {
|
||||||
|
if (modSides == "both" || modSides == name) {
|
||||||
|
register(name, configure)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
side("client") {
|
||||||
ideName.set("NeoForge Client")
|
ideName.set("NeoForge Client")
|
||||||
client()
|
client()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
side("server") {
|
||||||
|
ideName.set("NeoForge Server")
|
||||||
|
server()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package chylex.customwindowtitle.neoforge;
|
package chylex.customwindowtitle.neoforge;
|
||||||
|
|
||||||
|
import chylex.customwindowtitle.TitleChanger;
|
||||||
import chylex.customwindowtitle.TitleConfig;
|
import chylex.customwindowtitle.TitleConfig;
|
||||||
import chylex.customwindowtitle.TitleParser;
|
|
||||||
import chylex.customwindowtitle.data.CommonTokenData;
|
import chylex.customwindowtitle.data.CommonTokenData;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
@@ -18,15 +17,11 @@ public class CustomWindowTitle {
|
|||||||
public CustomWindowTitle(IEventBus eventBus) {
|
public CustomWindowTitle(IEventBus eventBus) {
|
||||||
config = TitleConfig.load(FMLPaths.CONFIGDIR.get().toString());
|
config = TitleConfig.load(FMLPaths.CONFIGDIR.get().toString());
|
||||||
eventBus.addListener(this::onClientSetup);
|
eventBus.addListener(this::onClientSetup);
|
||||||
CommonTokenData.register(new TokenProvider());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onClientSetup(final FMLClientSetupEvent e) {
|
public void onClientSetup(final FMLClientSetupEvent e) {
|
||||||
e.enqueueWork(this::updateTitle);
|
CommonTokenData.register(new TokenProvider());
|
||||||
}
|
e.enqueueWork(() -> TitleChanger.setTitle(config));
|
||||||
|
|
||||||
private void updateTitle() {
|
|
||||||
Minecraft.getInstance().getWindow().setTitle(TitleParser.parse(config.getTitle()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,6 +116,10 @@ allprojects {
|
|||||||
inputs.property("minimumMinecraftVersion", minimumMinecraftVersion)
|
inputs.property("minimumMinecraftVersion", minimumMinecraftVersion)
|
||||||
inputs.property("minimumNeoForgeVersion", minimumNeoForgeVersion)
|
inputs.property("minimumNeoForgeVersion", minimumNeoForgeVersion)
|
||||||
inputs.property("minimumFabricVersion", minimumFabricVersion)
|
inputs.property("minimumFabricVersion", minimumFabricVersion)
|
||||||
|
|
||||||
|
from(rootProject.file("logo.png")) {
|
||||||
|
into("assets/$modId")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<AbstractArchiveTask>().configureEach {
|
tasks.withType<AbstractArchiveTask>().configureEach {
|
||||||
|
|||||||
@@ -3,28 +3,29 @@ 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.4.0
|
modVersion=1.4.3
|
||||||
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
|
||||||
modSides=client
|
modSides=client
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
minecraftVersion=1.21
|
minecraftVersion=1.21.9
|
||||||
neoForgeVersion=21.0.0-beta
|
neoForgeVersion=21.9.2-beta
|
||||||
neoModDevVersion=1.0.21
|
neoModDevVersion=2.0.110
|
||||||
fabricVersion=0.15.11
|
fabricVersion=0.17.2
|
||||||
loomVersion=1.7
|
loomVersion=1.10
|
||||||
mixinVersion=0.12.5+mixin.0.8.5
|
mixinVersion=0.12.5+mixin.0.8.5
|
||||||
|
|
||||||
|
# https://projects.neoforged.net/neoforged/neoforge
|
||||||
# https://projects.neoforged.net/neoforged/moddevgradle
|
# https://projects.neoforged.net/neoforged/moddevgradle
|
||||||
# https://fabricmc.net/develop/
|
# https://fabricmc.net/develop/
|
||||||
# https://github.com/FabricMC/fabric-loom/releases
|
# https://github.com/FabricMC/fabric-loom/releases
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
minimumMinecraftVersion=1.21
|
minimumMinecraftVersion=1.21.9
|
||||||
minimumNeoForgeVersion=21.0.0-beta
|
minimumNeoForgeVersion=21.9.0-beta
|
||||||
minimumFabricVersion=0.12.3
|
minimumFabricVersion=0.15.0
|
||||||
|
|
||||||
# Gradle
|
# Gradle
|
||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
|
|||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
4
gradlew
vendored
4
gradlew
vendored
@@ -15,6 +15,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
@@ -84,7 +86,7 @@ done
|
|||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
|
|||||||
2
gradlew.bat
vendored
2
gradlew.bat
vendored
@@ -13,6 +13,8 @@
|
|||||||
@rem See the License for the specific language governing permissions and
|
@rem See the License for the specific language governing permissions and
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package chylex.customwindowtitle;
|
package chylex.customwindowtitle;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.lwjgl.glfw.GLFWImage;
|
import org.lwjgl.glfw.GLFWImage;
|
||||||
import org.lwjgl.stb.STBImage;
|
import org.lwjgl.stb.STBImage;
|
||||||
@@ -12,36 +14,39 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public final class IconChanger {
|
public final class IconChanger {
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger("CustomWindowTitle");
|
||||||
|
|
||||||
private IconChanger() {}
|
private IconChanger() {}
|
||||||
|
|
||||||
public static void setIcon(Path iconPath) {
|
public static void setIcon(Path iconPath) {
|
||||||
long windowHandle = Minecraft.getInstance().getWindow().getWindow();
|
long windowHandle = Minecraft.getInstance().getWindow().handle();
|
||||||
setWindowIcon(windowHandle, iconPath);
|
setWindowIcon(windowHandle, iconPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setWindowIcon(long windowHandle, Path iconPath) {
|
private static void setWindowIcon(long windowHandle, Path iconPath) {
|
||||||
|
ByteBuffer icon = null;
|
||||||
try (MemoryStack stack = MemoryStack.stackPush()) {
|
try (MemoryStack stack = MemoryStack.stackPush()) {
|
||||||
IntBuffer w = stack.mallocInt(1);
|
IntBuffer w = stack.mallocInt(1);
|
||||||
IntBuffer h = stack.mallocInt(1);
|
IntBuffer h = stack.mallocInt(1);
|
||||||
IntBuffer channels = stack.mallocInt(1);
|
IntBuffer channels = stack.mallocInt(1);
|
||||||
|
|
||||||
ByteBuffer icon = loadIcon(iconPath, w, h, channels);
|
icon = loadIcon(iconPath, w, h, channels);
|
||||||
if (icon == null) {
|
if (icon == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try (GLFWImage glfwImage1 = GLFWImage.malloc(); GLFWImage glfwImage2 = GLFWImage.malloc(); GLFWImage.Buffer icons = GLFWImage.malloc(2)) {
|
try (GLFWImage.Buffer icons = GLFWImage.malloc(1)) {
|
||||||
glfwImage1.set(w.get(0), h.get(0), icon);
|
GLFWImage iconImage = icons.get(0);
|
||||||
glfwImage2.set(w.get(0), h.get(0), icon);
|
iconImage.set(w.get(0), h.get(0), icon);
|
||||||
|
|
||||||
icons.put(0, glfwImage1);
|
|
||||||
icons.put(1, glfwImage2);
|
|
||||||
|
|
||||||
GLFW.glfwSetWindowIcon(windowHandle, icons);
|
GLFW.glfwSetWindowIcon(windowHandle, icons);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Failed to set window icon: " + iconPath);
|
LOGGER.error("Failed to set window icon from path: {}", iconPath, e);
|
||||||
e.printStackTrace();
|
} finally {
|
||||||
|
if (icon != null) {
|
||||||
|
STBImage.stbi_image_free(icon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +57,7 @@ public final class IconChanger {
|
|||||||
ByteBuffer icon = STBImage.stbi_load_from_memory(buffer, w, h, channels, 4);
|
ByteBuffer icon = STBImage.stbi_load_from_memory(buffer, w, h, channels, 4);
|
||||||
|
|
||||||
if (icon == null) {
|
if (icon == null) {
|
||||||
System.err.println("Failed to load image from memory for: " + path + " - " + STBImage.stbi_failure_reason());
|
LOGGER.error("Failed to load image from path: {} - {}", path, STBImage.stbi_failure_reason());
|
||||||
}
|
}
|
||||||
|
|
||||||
return icon;
|
return icon;
|
||||||
|
|||||||
11
src/main/java/chylex/customwindowtitle/TitleChanger.java
Normal file
11
src/main/java/chylex/customwindowtitle/TitleChanger.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package chylex.customwindowtitle;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
||||||
|
public final class TitleChanger {
|
||||||
|
private TitleChanger() {}
|
||||||
|
|
||||||
|
public static void setTitle(TitleConfig config) {
|
||||||
|
Minecraft.getInstance().getWindow().setTitle(TitleParser.parse(config.getTitle()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class TitleParser {
|
final class TitleParser {
|
||||||
private static final Pattern tokenRegex = Pattern.compile("\\{([a-z]+)(?::([^}]+))?}");
|
private static final Pattern tokenRegex = Pattern.compile("\\{([a-z]+)(?::([^}]+))?}");
|
||||||
private static final Logger logger = LogManager.getLogger("CustomWindowTitle");
|
private static final Logger logger = LogManager.getLogger("CustomWindowTitle");
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import net.minecraft.client.Minecraft;
|
|||||||
|
|
||||||
public interface CommonTokenProvider {
|
public interface CommonTokenProvider {
|
||||||
default String getMinecraftVersion() {
|
default String getMinecraftVersion() {
|
||||||
return SharedConstants.getCurrentVersion().getName();
|
return SharedConstants.getCurrentVersion().name();
|
||||||
}
|
}
|
||||||
|
|
||||||
String getModVersion(final String modId);
|
String getModVersion(String modId);
|
||||||
|
|
||||||
default String getUsername() {
|
default String getUsername() {
|
||||||
return Minecraft.getInstance().getUser().getName();
|
return Minecraft.getInstance().getUser().getName();
|
||||||
|
|||||||
Reference in New Issue
Block a user