Skip to content

Commit da9c606

Browse files
committed
maybe 1.13 icon replacing
1 parent aa50a59 commit da9c606

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

src/main/kotlin/org/polyfrost/polyplus/client/utils/IconLoader.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import javax.imageio.ImageIO
2323
* @author Chris Molini
2424
*/
2525
object IconLoader {
26+
@JvmField
27+
val IMAGE_SIZES = when {
28+
OmniDesktop.isWindows -> intArrayOf(16, 32)
29+
OmniDesktop.isMac -> intArrayOf(128)
30+
else -> intArrayOf(32)
31+
}
2632
/*************************************************************************
2733
* Loads an icon in ByteBuffer form.
2834
*
@@ -61,17 +67,9 @@ object IconLoader {
6167

6268
@JvmStatic
6369
fun load(image: BufferedImage): Array<ByteBuffer?> {
64-
val buffers: Array<ByteBuffer?>
65-
if (OmniDesktop.isWindows) {
66-
buffers = arrayOfNulls(2)
67-
buffers[0] = loadInstance(image, 16)
68-
buffers[1] = loadInstance(image, 32)
69-
} else if (OmniDesktop.isMac) {
70-
buffers = arrayOfNulls(1)
71-
buffers[0] = loadInstance(image, 128)
72-
} else {
73-
buffers = arrayOfNulls(1)
74-
buffers[0] = loadInstance(image, 32)
70+
val buffers: Array<ByteBuffer?> = arrayOfNulls(IMAGE_SIZES.size)
71+
for (i in IMAGE_SIZES.indices) {
72+
buffers[i] = loadInstance(image, IMAGE_SIZES[i])
7573
}
7674
return buffers
7775
}

versions/1.16.5-forge/src/main/java/org/polyfrost/polyplus/mixin/Mixin_ReplaceIcon.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,30 @@
2020
import java.util.Objects;
2121

2222
@Mixin(value = Minecraft.class, priority = Integer.MIN_VALUE)
23-
public class Mixin_ReplaceIcon { //todo: 1.13+
24-
//
25-
// @Shadow @Final private Window window;
26-
//
27-
// @Inject(method = "<init>", at = @At("TAIL"), cancellable = true)
28-
// private void setWindowIcon(CallbackInfo ci) {
29-
// try (InputStream stream = PolyPlusClient.class.getResourceAsStream("/assets/polyplus/PolyPlusIcon.png")) {
30-
// GLFWImage.Buffer icons = GLFWImage.malloc(2);
31-
// ByteBuffer[] buffers = IconLoader.load(ImageIO.read(Objects.requireNonNull(stream)));
32-
// icons.put(0, buffers[0]);
33-
// GLFW.glfwSetWindowIcon(this.window.getWindow(), icons);
34-
// ci.cancel();
35-
// } catch (Exception e) {
36-
// e.printStackTrace();
37-
// }
38-
// }
23+
public class Mixin_ReplaceIcon {
24+
25+
@Shadow @Final private Window window;
26+
27+
@Inject(method = "<init>", at = @At("TAIL"), cancellable = true)
28+
private void setWindowIcon(CallbackInfo ci) {
29+
try (InputStream stream = PolyPlusClient.class.getResourceAsStream("/assets/polyplus/PolyPlusIcon.png")) {
30+
GLFWImage.Buffer icons = GLFWImage.malloc(2);
31+
ByteBuffer[] buffers = IconLoader.load(ImageIO.read(Objects.requireNonNull(stream)));
32+
for (int i = 0; i < buffers.length; i++) {
33+
try (GLFWImage image = GLFWImage.malloc()) {
34+
int[] sizes = IconLoader.IMAGE_SIZES;
35+
image.height(sizes[i]);
36+
image.width(sizes[i]);
37+
image.pixels(buffers[i]);
38+
icons.put(i, image);
39+
}
40+
}
41+
42+
GLFW.glfwSetWindowIcon(this.window.getWindow(), icons);
43+
ci.cancel();
44+
} catch (Exception e) {
45+
e.printStackTrace();
46+
}
47+
}
3948
}
4049

0 commit comments

Comments
 (0)