From b5aa4cb54d5e5477dfd0c525742d4a18a338078c Mon Sep 17 00:00:00 2001 From: CoasterFreakDE Date: Wed, 4 Sep 2024 13:27:01 +0200 Subject: [PATCH] feat: Shader Response closes #1 --- .../client/ShaderReceivePayloadHandler.kt | 19 +++++++++++++----- .../shaderapi/client/ShaderStatusResponse.kt | 5 +++++ .../client/functions/PacketFunctions.kt | 13 ++++++++++++ .../com/liamxsage/shaderapi/Constants.kt | 3 +++ .../ShaderStatusResponsePayload.java | 20 +++++++++++++++++++ .../com/liamxsage/shaderapi/Shaderapi.kt | 4 ++++ 6 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 src/client/kotlin/com/liamxsage/shaderapi/client/ShaderStatusResponse.kt create mode 100644 src/client/kotlin/com/liamxsage/shaderapi/client/functions/PacketFunctions.kt create mode 100644 src/main/kotlin/com/liamxsage/shaderapi/ShaderStatusResponsePayload.java diff --git a/src/client/kotlin/com/liamxsage/shaderapi/client/ShaderReceivePayloadHandler.kt b/src/client/kotlin/com/liamxsage/shaderapi/client/ShaderReceivePayloadHandler.kt index e0e0202..f49c952 100644 --- a/src/client/kotlin/com/liamxsage/shaderapi/client/ShaderReceivePayloadHandler.kt +++ b/src/client/kotlin/com/liamxsage/shaderapi/client/ShaderReceivePayloadHandler.kt @@ -4,6 +4,7 @@ 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 +import com.liamxsage.shaderapi.client.functions.sendShaderStatusResponse import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking import net.irisshaders.iris.Iris import net.minecraft.client.MinecraftClient @@ -13,6 +14,7 @@ import java.io.File import java.net.HttpURLConnection import java.net.URI import java.util.* +import kotlin.reflect.jvm.jvmName class ShaderReceivePayloadHandler : ClientPlayNetworking.PlayPayloadHandler { override fun receive(payload: ShaderReceivePayload, context: ClientPlayNetworking.Context) { @@ -36,8 +38,9 @@ class ShaderReceivePayloadHandler : ClientPlayNetworking.PlayPayloadHandler ID = new Id<>(Constants.getSTATUS_RESPONSE_PACKET_ID()); + public static final PacketCodec CODEC = PacketCodec.tuple( + PacketCodecs.STRING, ShaderStatusResponsePayload::statusResponse, + ShaderStatusResponsePayload::new); + + @Override + public Id getId() { + return ID; + } +} diff --git a/src/main/kotlin/com/liamxsage/shaderapi/Shaderapi.kt b/src/main/kotlin/com/liamxsage/shaderapi/Shaderapi.kt index 23f81f0..899e7f1 100644 --- a/src/main/kotlin/com/liamxsage/shaderapi/Shaderapi.kt +++ b/src/main/kotlin/com/liamxsage/shaderapi/Shaderapi.kt @@ -10,7 +10,11 @@ class Shaderapi : ModInitializer { override fun onInitialize() { logger.info("Initializing ShaderAPI") + // Client 2 Server PayloadTypeRegistry.playC2S().register(ShaderRequestPayload.ID, ShaderRequestPayload.CODEC) + PayloadTypeRegistry.playC2S().register(ShaderStatusResponsePayload.ID, ShaderStatusResponsePayload.CODEC) + + // Server 2 Client PayloadTypeRegistry.playS2C().register(ShaderReceivePayload.ID, ShaderReceivePayload.CODEC) logger.info("ShaderAPI initialized")