From 2bc1ee706fe980b7874d575f069e775c911067ab Mon Sep 17 00:00:00 2001 From: Lyzev Date: Sat, 25 May 2024 12:54:57 +0200 Subject: [PATCH] fixed the bug Signed-off-by: Lyzev --- build.gradle.kts | 2 +- src/main/kotlin/dev/lyzev/api/imgui/font/ImGuiFonts.kt | 3 +-- src/main/kotlin/dev/lyzev/api/opengl/shader/Shader.kt | 10 +++++----- src/main/kotlin/dev/lyzev/schizoid/Schizoid.kt | 6 +----- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b17fee444d..90e302c003 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -91,7 +91,7 @@ loom { tasks.register("fixRunResources") { group = project.extra["archives_base_name"] as String description = "Fix Run Resources" - dependsOn("generateProperties", "processResources") + dependsOn("processResources") doLast { copy { from("build/resources/main") diff --git a/src/main/kotlin/dev/lyzev/api/imgui/font/ImGuiFonts.kt b/src/main/kotlin/dev/lyzev/api/imgui/font/ImGuiFonts.kt index 935fcb74c3..83917ac09e 100644 --- a/src/main/kotlin/dev/lyzev/api/imgui/font/ImGuiFonts.kt +++ b/src/main/kotlin/dev/lyzev/api/imgui/font/ImGuiFonts.kt @@ -42,8 +42,7 @@ enum class ImGuiFonts(override val fontName: String, override val type: ImGuiFon init { val fontAtlas = getIO().fonts - val `is` = - ClassLoader.getSystemResourceAsStream("assets/${Schizoid.MOD_ID}/fonts/$fontName.${type.name.lowercase()}") + val `is` = javaClass.getResourceAsStream("/assets/${Schizoid.MOD_ID}/fonts/$fontName.${type.name.lowercase()}") requireNotNull(`is`) { "Font file not found: $fontName.${type.name.lowercase()}" } font = fontAtlas.addFontFromMemoryTTF(`is`.readAllBytes(), size, glyphRanges) } diff --git a/src/main/kotlin/dev/lyzev/api/opengl/shader/Shader.kt b/src/main/kotlin/dev/lyzev/api/opengl/shader/Shader.kt index 4d1a3f8f5f..9af699e8ae 100644 --- a/src/main/kotlin/dev/lyzev/api/opengl/shader/Shader.kt +++ b/src/main/kotlin/dev/lyzev/api/opengl/shader/Shader.kt @@ -145,7 +145,7 @@ abstract class Shader(val shader: String) : EventListener { var matchResult = includeRegex.find(modifiedSource) while (matchResult != null) { val includePath = matchResult.groupValues[1] - val includeFile = javaClass.classLoader.getResource("$PATH/include/$includePath") + val includeFile = javaClass.getResource("$PATH/include/$includePath") if (includeFile == null) { Schizoid.logger.error(FileNotFoundException("Could not find include file: $includePath")) return modifiedSource @@ -221,7 +221,7 @@ abstract class Shader(val shader: String) : EventListener { /** * The path to the shaders. */ - val PATH = "assets/${Schizoid.MOD_ID}/shaders" + val PATH = "/assets/${Schizoid.MOD_ID}/shaders" /** * Draws a full screen quad. @@ -247,13 +247,13 @@ abstract class ShaderVertexFragment( super.init() if (tmp == program) return - val vSource = ClassLoader.getSystemResourceAsStream("$PATH/core/$shader/${shader}_VP.glsl")?.use { + val vSource = javaClass.getResourceAsStream("$PATH/core/$shader/${shader}_VP.glsl")?.use { it.readAllBytes().decodeToString() } ?: "null" val vShader = compile(GL_VERTEX_SHADER, vSource) glAttachShader(program, vShader) - val fSource = ClassLoader.getSystemResourceAsStream("$PATH/core/$shader/${shader}_FP.glsl")?.use { + val fSource = javaClass.getResourceAsStream("$PATH/core/$shader/${shader}_FP.glsl")?.use { it.readAllBytes().decodeToString() } ?: "null" val fShader = compile(GL_FRAGMENT_SHADER, fSource) @@ -326,7 +326,7 @@ abstract class ShaderCompute( super.init() if (tmp == program) return - ClassLoader.getSystemResourceAsStream("$PATH/core/$shader/${shader}_CP.glsl") + javaClass.getResourceAsStream("$PATH/core/$shader/${shader}_CP.glsl") ?.use { val computeShader = compile( GL_COMPUTE_SHADER, diff --git a/src/main/kotlin/dev/lyzev/schizoid/Schizoid.kt b/src/main/kotlin/dev/lyzev/schizoid/Schizoid.kt index 506870ecaf..975423ab3e 100644 --- a/src/main/kotlin/dev/lyzev/schizoid/Schizoid.kt +++ b/src/main/kotlin/dev/lyzev/schizoid/Schizoid.kt @@ -47,11 +47,7 @@ import kotlin.concurrent.thread */ object Schizoid : EventListener { - private val properties = Properties().apply { - ClassLoader.getSystemResourceAsStream("app.properties").use { - load(it) - } - } + private val properties = Properties().apply { load(Schizoid::class.java.getResourceAsStream("/app.properties")) } /** * The unique identifier of the mod.