-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a99c3a0
commit 420dac9
Showing
5 changed files
with
93 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,47 @@ | ||
package com.skidders.sigma.mixin; | ||
|
||
import com.skidders.SigmaReborn; | ||
import com.skidders.sigma.utils.render.ImageParser; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.util.Window; | ||
import org.lwjgl.glfw.GLFWImage; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import static org.lwjgl.glfw.GLFW.*; | ||
|
||
@Mixin(Window.class) | ||
public class WindowMixin { | ||
|
||
@Inject( | ||
method = "onWindowSizeChanged", | ||
method = "onWindowSizeChanged", | ||
at = @At("TAIL") | ||
) | ||
public final void onWindowSizeUpdate(long window, int width, int height, CallbackInfo ci) { | ||
SigmaReborn.INSTANCE.screenProcessor.onResize(); | ||
} | ||
|
||
@Inject( | ||
method = "setIcon", | ||
at = @At("HEAD"), | ||
cancellable = true | ||
) | ||
private void injectSetIcon(InputStream icon16, InputStream icon32, CallbackInfo ci) { | ||
if (!glfwInit()) System.out.println("Could not initialise opengl4.5."); | ||
|
||
ImageParser logo = ImageParser.loadImage("/assets/sigma-reborn/icon.png", "sigma/icon.png"); | ||
|
||
GLFWImage image = GLFWImage.malloc(); GLFWImage.Buffer imagebf = GLFWImage.malloc(1); | ||
image.set(logo.width(), logo.height(), logo.image()); | ||
imagebf.put(0, image); | ||
glfwSetWindowIcon(MinecraftClient.getInstance().getWindow().getHandle(), imagebf); | ||
ci.cancel(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/skidders/sigma/utils/render/ImageParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.skidders.sigma.utils.render; | ||
|
||
import com.skidders.sigma.utils.file.FileUtil; | ||
import org.lwjgl.system.MemoryStack; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.ByteBuffer; | ||
import java.nio.IntBuffer; | ||
|
||
import static org.lwjgl.stb.STBImage.stbi_load; | ||
|
||
public record ImageParser(int width, int height, ByteBuffer image) { | ||
|
||
public static ImageParser loadImage(String resource, String path) { | ||
try { | ||
FileUtil.copyResourceToFile(resource, path); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
ByteBuffer image; | ||
int width, height; | ||
|
||
try (MemoryStack stack = MemoryStack.stackPush()) { | ||
IntBuffer comp = stack.mallocInt(1); | ||
IntBuffer w = stack.mallocInt(1); | ||
IntBuffer h = stack.mallocInt(1); | ||
|
||
image = stbi_load(path, w, h, comp, 4); | ||
if (image == null) { | ||
throw new RuntimeException("Could not load image " + path); | ||
} | ||
width = w.get(); | ||
height = h.get(); | ||
} | ||
return new ImageParser(width, height, image); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.