Provide convenient unit packet registration
This commit is contained in:
parent
7f299a6dec
commit
10f250b822
@ -28,6 +28,18 @@ fun <T : CustomPacketPayload> PayloadRegistrar.playToServer(
|
|||||||
handler: KFunction1<IPayloadContext, Unit>
|
handler: KFunction1<IPayloadContext, Unit>
|
||||||
): PayloadRegistrar = playToServer(type, codec) { _, context -> handler(context) }
|
): PayloadRegistrar = playToServer(type, codec) { _, context -> handler(context) }
|
||||||
|
|
||||||
|
fun <T : CustomPacketPayload> PayloadRegistrar.playToClient(
|
||||||
|
type: CustomPacketPayload.Type<T>,
|
||||||
|
value: T,
|
||||||
|
handler: KFunction1<IPayloadContext, Unit>
|
||||||
|
): PayloadRegistrar = playToClient(type, MatteryStreamCodec.MUnit(value)) { _, context -> handler(context) }
|
||||||
|
|
||||||
|
fun <T : CustomPacketPayload> PayloadRegistrar.playToServer(
|
||||||
|
type: CustomPacketPayload.Type<T>,
|
||||||
|
value: T,
|
||||||
|
handler: KFunction1<IPayloadContext, Unit>
|
||||||
|
): PayloadRegistrar = playToServer(type, MatteryStreamCodec.MUnit(value)) { _, context -> handler(context) }
|
||||||
|
|
||||||
inline fun encodePayload(registry: RegistryAccess, block: (RegistryFriendlyByteBuf) -> Unit): ByteArrayList {
|
inline fun encodePayload(registry: RegistryAccess, block: (RegistryFriendlyByteBuf) -> Unit): ByteArrayList {
|
||||||
val underlying = ByteBufAllocator.DEFAULT.buffer()
|
val underlying = ByteBufAllocator.DEFAULT.buffer()
|
||||||
val buf = RegistryFriendlyByteBuf(underlying, registry, ConnectionType.NEOFORGE)
|
val buf = RegistryFriendlyByteBuf(underlying, registry, ConnectionType.NEOFORGE)
|
||||||
|
@ -245,9 +245,6 @@ object ExopackMenuOpen : CustomPacketPayload {
|
|||||||
"exopack_menu_open"
|
"exopack_menu_open"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
val CODEC: StreamCodec<FriendlyByteBuf, ExopackMenuOpen> =
|
|
||||||
StreamCodec.ofMember({ _, _ -> }, { ExopackMenuOpen })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class PickItemFromInventoryPacket(
|
class PickItemFromInventoryPacket(
|
||||||
@ -347,8 +344,6 @@ object DisplayExopackPacket : CustomPacketPayload {
|
|||||||
"display_exopack"
|
"display_exopack"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val CODEC: StreamCodec<FriendlyByteBuf, DisplayExopackPacket> =
|
|
||||||
StreamCodec.ofMember({ _, _ -> }, { DisplayExopackPacket })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object HideExopackPacket : CustomPacketPayload {
|
object HideExopackPacket : CustomPacketPayload {
|
||||||
@ -366,8 +361,6 @@ object HideExopackPacket : CustomPacketPayload {
|
|||||||
"hide_exopack"
|
"hide_exopack"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val CODEC: StreamCodec<FriendlyByteBuf, HideExopackPacket> =
|
|
||||||
StreamCodec.ofMember({ _, _ -> }, { HideExopackPacket })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object EnableExopackGlowPacket : CustomPacketPayload {
|
object EnableExopackGlowPacket : CustomPacketPayload {
|
||||||
@ -385,8 +378,6 @@ object EnableExopackGlowPacket : CustomPacketPayload {
|
|||||||
"enable_exopack_glow"
|
"enable_exopack_glow"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val CODEC: StreamCodec<FriendlyByteBuf, EnableExopackGlowPacket> =
|
|
||||||
StreamCodec.ofMember({ _, _ -> }, { EnableExopackGlowPacket })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object DisableExopackGlowPacket : CustomPacketPayload {
|
object DisableExopackGlowPacket : CustomPacketPayload {
|
||||||
@ -404,8 +395,6 @@ object DisableExopackGlowPacket : CustomPacketPayload {
|
|||||||
"disable_exopack_glow"
|
"disable_exopack_glow"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val CODEC: StreamCodec<FriendlyByteBuf, DisableExopackGlowPacket> =
|
|
||||||
StreamCodec.ofMember({ _, _ -> }, { DisableExopackGlowPacket })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object ResetExopackColorPacket : CustomPacketPayload {
|
object ResetExopackColorPacket : CustomPacketPayload {
|
||||||
@ -423,8 +412,6 @@ object ResetExopackColorPacket : CustomPacketPayload {
|
|||||||
"reset_exopack_color"
|
"reset_exopack_color"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val CODEC: StreamCodec<FriendlyByteBuf, ResetExopackColorPacket> =
|
|
||||||
StreamCodec.ofMember({ _, _ -> }, { ResetExopackColorPacket })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExopackSmokePacket(val player: UUID) : CustomPacketPayload {
|
class ExopackSmokePacket(val player: UUID) : CustomPacketPayload {
|
||||||
|
@ -44,15 +44,15 @@ internal fun registerNetworkPackets(event: RegisterPayloadHandlersEvent) {
|
|||||||
.playToClient(ExopackSlotPacket.TYPE, ExopackSlotPacket.CODEC, ExopackSlotPacket::play)
|
.playToClient(ExopackSlotPacket.TYPE, ExopackSlotPacket.CODEC, ExopackSlotPacket::play)
|
||||||
.playToClient(ExopackMenuInitPacket.TYPE, ExopackMenuInitPacket.CODEC, ExopackMenuInitPacket::play)
|
.playToClient(ExopackMenuInitPacket.TYPE, ExopackMenuInitPacket.CODEC, ExopackMenuInitPacket::play)
|
||||||
.playToClient(ExopackSmokePacket.TYPE, ExopackSmokePacket.CODEC, ExopackSmokePacket::play)
|
.playToClient(ExopackSmokePacket.TYPE, ExopackSmokePacket.CODEC, ExopackSmokePacket::play)
|
||||||
.playToServer(ExopackMenuOpen.TYPE, ExopackMenuOpen.CODEC, ExopackMenuOpen::play)
|
.playToServer(ExopackMenuOpen.TYPE, ExopackMenuOpen, ExopackMenuOpen::play)
|
||||||
|
|
||||||
.playToServer(PickItemFromInventoryPacket.TYPE, PickItemFromInventoryPacket.CODEC, PickItemFromInventoryPacket::play)
|
.playToServer(PickItemFromInventoryPacket.TYPE, PickItemFromInventoryPacket.CODEC, PickItemFromInventoryPacket::play)
|
||||||
|
|
||||||
.playToServer(DisplayExopackPacket.TYPE, DisplayExopackPacket.CODEC, DisplayExopackPacket::play)
|
.playToServer(DisplayExopackPacket.TYPE, DisplayExopackPacket, DisplayExopackPacket::play)
|
||||||
.playToServer(HideExopackPacket.TYPE, HideExopackPacket.CODEC, HideExopackPacket::play)
|
.playToServer(HideExopackPacket.TYPE, HideExopackPacket, HideExopackPacket::play)
|
||||||
.playToServer(EnableExopackGlowPacket.TYPE, EnableExopackGlowPacket.CODEC, EnableExopackGlowPacket::play)
|
.playToServer(EnableExopackGlowPacket.TYPE, EnableExopackGlowPacket, EnableExopackGlowPacket::play)
|
||||||
.playToServer(DisableExopackGlowPacket.TYPE, DisableExopackGlowPacket.CODEC, DisableExopackGlowPacket::play)
|
.playToServer(DisableExopackGlowPacket.TYPE, DisableExopackGlowPacket, DisableExopackGlowPacket::play)
|
||||||
.playToServer(ResetExopackColorPacket.TYPE, ResetExopackColorPacket.CODEC, ResetExopackColorPacket::play)
|
.playToServer(ResetExopackColorPacket.TYPE, ResetExopackColorPacket, ResetExopackColorPacket::play)
|
||||||
.playToServer(SetExopackColorPacket.TYPE, SetExopackColorPacket.CODEC, SetExopackColorPacket::play)
|
.playToServer(SetExopackColorPacket.TYPE, SetExopackColorPacket.CODEC, SetExopackColorPacket::play)
|
||||||
|
|
||||||
// otm player general
|
// otm player general
|
||||||
|
Loading…
Reference in New Issue
Block a user