mirror of
https://github.com/chylex/Minecraft-Window-Title.git
synced 2025-09-17 23:24:51 +02:00
Compare commits
4 Commits
425eb3f380
...
master
Author | SHA1 | Date | |
---|---|---|---|
50d77446f5
|
|||
1f92896e55
|
|||
2a17b46a1d
|
|||
![]() |
5e64fd81e3 |
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>
|
||||||
|
@@ -3,18 +3,18 @@ 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.2
|
||||||
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.4
|
minecraftVersion=1.21.6
|
||||||
neoForgeVersion=21.4.77-beta
|
neoForgeVersion=21.6.20-beta
|
||||||
neoModDevVersion=2.0.76
|
neoModDevVersion=2.0.103
|
||||||
fabricVersion=0.16.10
|
fabricVersion=0.16.14
|
||||||
loomVersion=1.9
|
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/neoforge
|
||||||
@@ -23,8 +23,8 @@ mixinVersion=0.12.5+mixin.0.8.5
|
|||||||
# https://github.com/FabricMC/fabric-loom/releases
|
# https://github.com/FabricMC/fabric-loom/releases
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
minimumMinecraftVersion=1.21
|
minimumMinecraftVersion=1.21.6
|
||||||
minimumNeoForgeVersion=21.0.0-beta
|
minimumNeoForgeVersion=21.6.0-beta
|
||||||
minimumFabricVersion=0.12.3
|
minimumFabricVersion=0.12.3
|
||||||
|
|
||||||
# Gradle
|
# Gradle
|
||||||
|
@@ -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,6 +14,8 @@ 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) {
|
||||||
@@ -20,28 +24,29 @@ public final class IconChanger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
@@ -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