Skip to content

Commit

Permalink
chore: Changed logger
Browse files Browse the repository at this point in the history
  • Loading branch information
CoasterFreakDE committed Sep 2, 2024
1 parent 5181fe7 commit 3ddb4f6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}")

implementation("com.liamxsage:KlassicX:2024.7.13-18.48")

compileOnly(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.liamxsage.shaderapi.client

import com.liamxsage.klassicx.extensions.getLogger
import com.liamxsage.shaderapi.Constants.logger
import com.liamxsage.shaderapi.ShaderReceivePayload
import com.liamxsage.shaderapi.client.config.ConfigManager
import com.liamxsage.shaderapi.client.config.ShaderPackAcceptState
Expand All @@ -16,7 +16,7 @@ import java.util.*

class ShaderReceivePayloadHandler : ClientPlayNetworking.PlayPayloadHandler<ShaderReceivePayload> {
override fun receive(payload: ShaderReceivePayload, context: ClientPlayNetworking.Context) {
getLogger().info("ShaderReceivePayload received")
logger.info("ShaderReceivePayload received")
val shaderUrl: String = payload.shaderUrl ?: return
val shaderHash: String = payload.hash ?: return
val serverGroup: String = payload.serverGroup.ifEmpty { context.player().server?.serverIp ?: "global" }
Expand Down Expand Up @@ -66,7 +66,7 @@ class ShaderReceivePayloadHandler : ClientPlayNetworking.PlayPayloadHandler<Shad

// Download the shader pack
val shaderPackFile: File = downloadShaderPack(url, shaderHash) ?: run {
getLogger().warn("Shader Pack Download failed")
logger.warn("Shader Pack Download failed")
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.liamxsage.shaderapi.client

import com.liamxsage.klassicx.extensions.getLogger
import com.liamxsage.shaderapi.Constants.logger
import com.liamxsage.shaderapi.ShaderReceivePayload
import com.liamxsage.shaderapi.ShaderRequestPayload
import com.liamxsage.shaderapi.client.config.ConfigManager
Expand All @@ -15,33 +15,33 @@ import net.minecraft.client.network.ClientPlayNetworkHandler
class ShaderapiClient : ClientModInitializer {

override fun onInitializeClient() {
getLogger().info("Initializing ShaderAPI Client")
logger.info("Initializing ShaderAPI Client")

// Check for a disabling condition, such as a missing dependency or a config flag
if (shouldDisableMod()) {
getLogger().warn("ShaderAPI Client is disabled.")
logger.warn("ShaderAPI Client is disabled.")
return // Exit the initialization early
}

ClientPlayNetworking.registerGlobalReceiver(ShaderReceivePayload.ID, ShaderReceivePayloadHandler())

getLogger().info("Registering ShaderRequestPayload Receiver")
logger.info("Registering ShaderRequestPayload Receiver")
ClientPlayConnectionEvents.JOIN.register(ClientPlayConnectionEvents.Join { handler: ClientPlayNetworkHandler, sender: PacketSender, client: MinecraftClient ->
ClientPlayNetworking.send(ShaderRequestPayload(true)).also { getLogger().info("ShaderRequestPayload sent") }
ClientPlayNetworking.send(ShaderRequestPayload(true)).also { logger.info("ShaderRequestPayload sent") }
})

getLogger().info("Loading config")
logger.info("Loading config")
ConfigManager.readConfig()

getLogger().info("ShaderAPI Client initialized")
logger.info("ShaderAPI Client initialized")
}

private fun shouldDisableMod(): Boolean {
// Example condition: Disable if Iris is not present
try {
Class.forName("net.irisshaders.iris.Iris")
} catch (e: ClassNotFoundException) {
getLogger().warn("ShaderAPI Client could not find Iris, disabling")
logger.warn("ShaderAPI Client could not find Iris, disabling")
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.liamxsage.shaderapi.client.config

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.liamxsage.klassicx.extensions.getLogger
import com.liamxsage.shaderapi.Constants.logger
import net.minecraft.client.MinecraftClient
import java.io.File

Expand All @@ -19,17 +19,17 @@ object ConfigManager {
fun readConfig() {
try {
serverGroups = Gson().fromJson(configFile.readText(), object : TypeToken<List<ServerGroupShaderState>>() {}.type)
getLogger().info("Loaded ${serverGroups.size} server groups")
logger.info("Loaded ${serverGroups.size} server groups")
} catch (e: Exception) {
getLogger().warn("Failed to read config file", e)
logger.warn("Failed to read config file", e)
}
}

private fun saveConfig() {
try {
configFile.writeText(Gson().toJson(serverGroups))
} catch (e: Exception) {
getLogger().warn("Failed to save config file", e)
logger.warn("Failed to save config file", e)
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/com/liamxsage/shaderapi/Constants.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.liamxsage.shaderapi

import net.minecraft.util.Identifier
import org.slf4j.Logger
import org.slf4j.LoggerFactory

object Constants {
@JvmStatic
val REQUEST_SHADER_PACKET_ID: Identifier = Identifier.of("shaderapi", "request_shader_url")

@JvmStatic
val RECEIVE_SHADER_PACKET_ID: Identifier = Identifier.of("shaderapi", "receive_shader_url")

@JvmStatic
val logger: Logger = LoggerFactory.getLogger(Shaderapi::class.java)
}
6 changes: 3 additions & 3 deletions src/main/kotlin/com/liamxsage/shaderapi/Shaderapi.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.liamxsage.shaderapi

import com.liamxsage.klassicx.extensions.getLogger
import com.liamxsage.shaderapi.Constants.logger
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry


class Shaderapi : ModInitializer {

override fun onInitialize() {
getLogger().info("Initializing ShaderAPI")
logger.info("Initializing ShaderAPI")

PayloadTypeRegistry.playC2S().register(ShaderRequestPayload.ID, ShaderRequestPayload.CODEC)
PayloadTypeRegistry.playS2C().register(ShaderReceivePayload.ID, ShaderReceivePayload.CODEC)

getLogger().info("ShaderAPI initialized")
logger.info("ShaderAPI initialized")
}
}

0 comments on commit 3ddb4f6

Please sign in to comment.