Skip to content

Commit

Permalink
client logo
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkGG8181 committed Dec 23, 2024
1 parent a99c3a0 commit 420dac9
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 19 deletions.
19 changes: 2 additions & 17 deletions src/main/java/com/skidders/sigma/managers/FontManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public FontManager() {
if (folder.exists() && folder.isDirectory()) {
for (File file : folder.listFiles()) {
if (file.isFile()) {
copyResourceToFile(file.getName(), destinationPath + file.getName());
FileUtil.copyResourceToFile("/assets/sigma-reborn/fonts/" + file.getName(), destinationPath + file.getName());
}
}
} else {
Expand All @@ -53,7 +53,7 @@ public FontManager() {
}

this.textureQueue = new ConcurrentLinkedQueue<>();
this.defaultFont = new Renderer(textureQueue, new Font("Roboto-Regular", Font.PLAIN, 16));
this.defaultFont = new Renderer(textureQueue, new Font("Dialog.plain", Font.PLAIN, 16));
SigmaReborn.LOGGER.info("set the default font to: {}", defaultFont.font.getFontName());

try {
Expand All @@ -70,21 +70,6 @@ public FontManager() {
SigmaReborn.LOGGER.info("Finished loading fonts");
}

private void copyResourceToFile(String sourceFileName, String destinationPath) throws IOException {
try (InputStream in = getClass().getResourceAsStream("/assets/sigma-reborn/fonts/" + sourceFileName);
OutputStream out = new FileOutputStream(destinationPath)) {
if (in == null) {
throw new FileNotFoundException("Font resource not found: " + sourceFileName);
}

byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
}
}

private void loadFont(String fontPath, String fontName, int[] sizes) {
for (int size : sizes) {
Path fontFile = Paths.get(fontPath);
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/com/skidders/sigma/mixin/WindowMixin.java
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();
}

}
26 changes: 25 additions & 1 deletion src/main/java/com/skidders/sigma/utils/file/FileUtil.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.skidders.sigma.utils.file;

import com.mojang.blaze3d.systems.RenderSystem;
import com.skidders.SigmaReborn;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.texture.TextureUtil;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.stb.STBImage;
import org.lwjgl.system.MemoryUtil;

import java.io.IOException;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -43,4 +50,21 @@ public static java.util.List<String> getFilesInDirectory(String directoryPath) t
return filenames;
}

public static void copyResourceToFile(String sourceFileName, String destinationPath) throws IOException {
try (InputStream in = FileUtil.class.getResourceAsStream(sourceFileName); OutputStream out = new FileOutputStream(destinationPath)) {
System.out.println("Getting " + sourceFileName);
System.out.println("Sending to " + destinationPath);

if (in == null) {
throw new FileNotFoundException("Resource not found: " + sourceFileName);
}

byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
}
}

}
39 changes: 39 additions & 0 deletions src/main/java/com/skidders/sigma/utils/render/ImageParser.java
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);
}
}
Binary file modified src/main/resources/assets/sigma-reborn/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 420dac9

Please sign in to comment.