Skip to content

Commit cd9ae13

Browse files
committed
1.21.8 icon replacing
1 parent da9c606 commit cd9ae13

File tree

4 files changed

+45
-25
lines changed

4 files changed

+45
-25
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ repositories {
2323

2424
toolkitLoomHelper {
2525
useOneConfig {
26-
version = "1.0.0-alpha.177"
27-
loaderVersion = "1.1.0-alpha.53"
26+
version = "1.0.0-alpha.181"
27+
loaderVersion = "1.1.0-alpha.54"
2828

2929
usePolyMixin = true
3030
polyMixinVersion = "0.8.4+build.7"

src/main/kotlin/org/polyfrost/polyplus/client/gui/FullscreenLockerUI.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import dev.deftu.omnicore.api.client.screen.OmniScreen
55
import org.polyfrost.oneconfig.api.ui.v1.OCPolyUIBuilder
66
import org.polyfrost.oneconfig.api.ui.v1.UIManager
77
import org.polyfrost.polyplus.PolyPlusConstants
8+
import org.polyfrost.polyui.color.Colors
89
import org.polyfrost.polyui.color.rgba
910
import org.polyfrost.polyui.component.Drawable
1011
import org.polyfrost.polyui.component.extensions.disable
@@ -75,7 +76,7 @@ object FullscreenLockerUI {
7576
TextInput(
7677
placeholder = "polyplus.search.placeholder",
7778
visibleSize = Vec2(210f, 12f)
78-
).onChange { text: String ->
79+
).onChange { text: Colors.Palette ->
7980
// TODO: Filter cosmetics list based on search input
8081
false
8182
}.named("SearchInput"),

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package org.polyfrost.polyplus.client.utils
22

33

44
import dev.deftu.omnicore.api.client.OmniDesktop
5+
import org.lwjgl.BufferUtils
56
import java.awt.image.BufferedImage
67
import java.io.File
78
import java.io.IOException
8-
import java.io.InputStream
99
import java.nio.ByteBuffer
1010
import javax.imageio.ImageIO
1111

@@ -84,7 +84,8 @@ object IconLoader {
8484
*
8585
* @return A ByteBuffer of pixel data at the indicated size.
8686
*/
87-
private fun loadInstance(image: BufferedImage, dimension: Int): ByteBuffer {
87+
@JvmStatic
88+
fun loadInstance(image: BufferedImage, dimension: Int): ByteBuffer {
8889
val scaledIcon = BufferedImage(dimension, dimension, BufferedImage.TYPE_INT_ARGB_PRE)
8990
val g = scaledIcon.createGraphics()
9091
val ratio = getIconRatio(image, scaledIcon)
@@ -138,16 +139,18 @@ object IconLoader {
138139
* @return A ByteBuffer that contains the pixel data of the supplied image.
139140
*/
140141
fun convertToByteBuffer(image: BufferedImage): ByteBuffer {
141-
val buffer = ByteArray(image.width * image.height * 4)
142-
var counter = 0
143-
for (i in 0..<image.height) for (j in 0..<image.width) {
144-
val colorSpace = image.getRGB(j, i)
145-
buffer[counter] = ((colorSpace shl 8) shr 24).toByte()
146-
buffer[counter + 1] = ((colorSpace shl 16) shr 24).toByte()
147-
buffer[counter + 2] = ((colorSpace shl 24) shr 24).toByte()
148-
buffer[counter + 3] = (colorSpace shr 24).toByte()
149-
counter += 4
142+
val (width, height) = image.width to image.height
143+
val buffer = BufferUtils.createByteBuffer(width * height * 4)
144+
145+
for (y in 0..<height) for (x in 0..<width) {
146+
val colorSpace = image.getRGB(x, y)
147+
val index = (y * width + x) * 4
148+
buffer.put(index, ((colorSpace shr 16) and 0xFF).toByte())
149+
buffer.put(index + 1, ((colorSpace shr 8) and 0xFF).toByte())
150+
buffer.put(index + 2, (colorSpace and 0xFF).toByte())
151+
buffer.put(index + 3, ((colorSpace shr 24) and 0xFF).toByte())
150152
}
151-
return ByteBuffer.wrap(buffer)
153+
154+
return buffer
152155
}
153156
}

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,39 @@ public class Mixin_ReplaceIcon {
2424

2525
@Shadow @Final private Window window;
2626

27-
@Inject(method = "<init>", at = @At("TAIL"), cancellable = true)
27+
@Inject(method = "<init>", at = @At("TAIL"))
2828
private void setWindowIcon(CallbackInfo ci) {
2929
try (InputStream stream = PolyPlusClient.class.getResourceAsStream("/assets/polyplus/PolyPlusIcon.png")) {
3030
GLFWImage.Buffer icons = GLFWImage.malloc(2);
3131
ByteBuffer[] buffers = IconLoader.load(ImageIO.read(Objects.requireNonNull(stream)));
3232
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-
}
33+
GLFWImage image = GLFWImage.malloc();
34+
int size = IconLoader.IMAGE_SIZES[i];
35+
36+
image.height(size).width(size).pixels(buffers[i]);
37+
38+
icons.put(i, image);
39+
}
40+
41+
for (int i = 0; i < buffers.length; i++) {
42+
int expected = IconLoader.IMAGE_SIZES[i]
43+
* IconLoader.IMAGE_SIZES[i] * 4;
44+
45+
System.out.println(
46+
"[PolyPlus] icon " + i +
47+
" expected=" + expected +
48+
" actual=" + buffers[i].remaining() +
49+
" direct=" + buffers[i].isDirect()
50+
);
4051
}
4152

42-
GLFW.glfwSetWindowIcon(this.window.getWindow(), icons);
43-
ci.cancel();
53+
54+
Minecraft.getInstance().execute(() -> {
55+
GLFW.glfwSetWindowIcon(this.window.getWindow(), icons);
56+
57+
icons.forEach(GLFWImage::free);
58+
icons.free();
59+
});
4460
} catch (Exception e) {
4561
e.printStackTrace();
4662
}

0 commit comments

Comments
 (0)