aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/apis/ingame/FirmamentCustomPayload.kt
blob: 34e39ab860068b325650e48e56d6e995b4ef2473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

package moe.nea.firmament.apis.ingame

import io.netty.buffer.ByteBuf
import net.minecraft.network.codec.PacketCodec
import net.minecraft.network.packet.CustomPayload
import net.minecraft.util.Identifier

interface FirmamentCustomPayload : CustomPayload {

    class Unhandled private constructor(val identifier: Identifier) : FirmamentCustomPayload {
        override fun getId(): CustomPayload.Id<out CustomPayload> {
            return CustomPayload.id(identifier.toString())
        }

        companion object {
            fun <B : ByteBuf> createCodec(identifier: Identifier): PacketCodec<B, Unhandled> {
                return object : PacketCodec<B, Unhandled> {
                    override fun decode(buf: B): Unhandled {
                        return Unhandled(identifier)
                    }

                    override fun encode(buf: B, value: Unhandled) {
                        // we will never send an unhandled packet stealthy
                    }
                }
            }
        }

    }
}