From 0600925ccc8a4647ed7d84e95c53ec68e48419ae Mon Sep 17 00:00:00 2001 From: Samarium <28302241+Samarium150@users.noreply.github.com> Date: Tue, 22 Mar 2022 12:30:54 +0800 Subject: [PATCH] fix: avoid using ClientPlayNetworking.PlayChannelHandler in packet initialization --- gradle.properties | 2 +- .../client/StructuresCompassClient.kt | 1 - .../client/init/ItemPredicateRegistry.kt | 1 - .../network/StructuresCompassClientNetwork.kt | 3 ++ .../init/CommandRegistry.kt | 3 +- .../network/packet/c2s/PacketHandler.kt | 36 +++++++++++++++++++ .../network/packet/c2s/RequestSyncPacket.kt | 3 +- .../network/packet/c2s/SearchPacket.kt | 4 +-- .../network/packet/c2s/SetSkipPacket.kt | 3 +- .../network/packet/s2c/PacketHandler.kt | 34 ++++++++++++++++++ .../network/packet/s2c/SyncPacket.kt | 3 +- .../{ => server}/command/GetCompass.kt | 2 +- 12 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/PacketHandler.kt create mode 100644 src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/s2c/PacketHandler.kt rename src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/{ => server}/command/GetCompass.kt (96%) diff --git a/gradle.properties b/gradle.properties index 5797c24..76e089b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ loaderVersion=0.13.3 fabricVersion=0.46.1+1.17 loomVersion=0.10-SNAPSHOT # Mod Properties -modVersion=1.17.1-1.4.0 +modVersion=1.17.1-1.4.1 mavenGroup=io.github.samarium150 archivesBaseName=structures_compass-fabric # Kotlin diff --git a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/StructuresCompassClient.kt b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/StructuresCompassClient.kt index 56a3565..3590e62 100644 --- a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/StructuresCompassClient.kt +++ b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/StructuresCompassClient.kt @@ -14,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - package io.github.samarium150.minecraft.mod.structures_compass.client import io.github.samarium150.minecraft.mod.structures_compass.client.init.HudRegistry diff --git a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/init/ItemPredicateRegistry.kt b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/init/ItemPredicateRegistry.kt index 1bd45e8..7a088a2 100644 --- a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/init/ItemPredicateRegistry.kt +++ b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/init/ItemPredicateRegistry.kt @@ -14,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - package io.github.samarium150.minecraft.mod.structures_compass.client.init import io.github.samarium150.minecraft.mod.structures_compass.client.item.StructuresCompassItemPredicate diff --git a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/network/StructuresCompassClientNetwork.kt b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/network/StructuresCompassClientNetwork.kt index 96a6afe..a4b2e98 100644 --- a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/network/StructuresCompassClientNetwork.kt +++ b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/network/StructuresCompassClientNetwork.kt @@ -18,9 +18,12 @@ package io.github.samarium150.minecraft.mod.structures_compass.client.network import io.github.samarium150.minecraft.mod.structures_compass.network.packet.s2c.SyncPacket import io.github.samarium150.minecraft.mod.structures_compass.util.MOD_ID +import net.fabricmc.api.EnvType +import net.fabricmc.api.Environment import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking import org.apache.logging.log4j.LogManager +@Environment(EnvType.CLIENT) object StructuresCompassClientNetwork { private val logger = LogManager.getLogger("${MOD_ID}/client_network") diff --git a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/init/CommandRegistry.kt b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/init/CommandRegistry.kt index 334f0c1..c8221e6 100644 --- a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/init/CommandRegistry.kt +++ b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/init/CommandRegistry.kt @@ -14,10 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - package io.github.samarium150.minecraft.mod.structures_compass.init -import io.github.samarium150.minecraft.mod.structures_compass.command.GetCompass +import io.github.samarium150.minecraft.mod.structures_compass.server.command.GetCompass import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback object CommandRegistry { diff --git a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/PacketHandler.kt b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/PacketHandler.kt new file mode 100644 index 0000000..4d51a27 --- /dev/null +++ b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/PacketHandler.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Samarium + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.samarium150.minecraft.mod.structures_compass.network.packet.c2s + +import net.fabricmc.fabric.api.networking.v1.PacketSender +import net.minecraft.network.PacketByteBuf +import net.minecraft.server.MinecraftServer +import net.minecraft.server.network.ServerPlayNetworkHandler +import net.minecraft.server.network.ServerPlayerEntity + +/** + * @see net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking.PlayChannelHandler + */ +fun interface PacketHandler { + fun receive( + server: MinecraftServer, + player: ServerPlayerEntity, + handler: ServerPlayNetworkHandler, + buf: PacketByteBuf, + responseSender: PacketSender + ) +} diff --git a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/RequestSyncPacket.kt b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/RequestSyncPacket.kt index e63b659..3e9c2a0 100644 --- a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/RequestSyncPacket.kt +++ b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/RequestSyncPacket.kt @@ -14,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - package io.github.samarium150.minecraft.mod.structures_compass.network.packet.c2s import io.github.samarium150.minecraft.mod.structures_compass.data.StructuresCompassData @@ -31,7 +30,7 @@ import net.minecraft.util.Identifier class RequestSyncPacket : PacketByteBuf(Unpooled.buffer()) { - companion object : ServerPlayNetworking.PlayChannelHandler { + companion object : PacketHandler { val ID = Identifier(MOD_ID, "request_sync_packet") diff --git a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/SearchPacket.kt b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/SearchPacket.kt index a375786..70131f3 100644 --- a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/SearchPacket.kt +++ b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/SearchPacket.kt @@ -14,14 +14,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - package io.github.samarium150.minecraft.mod.structures_compass.network.packet.c2s import io.github.samarium150.minecraft.mod.structures_compass.util.MOD_ID import io.github.samarium150.minecraft.mod.structures_compass.util.search import io.netty.buffer.Unpooled import net.fabricmc.fabric.api.networking.v1.PacketSender -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking import net.minecraft.network.PacketByteBuf import net.minecraft.server.MinecraftServer import net.minecraft.server.network.ServerPlayNetworkHandler @@ -30,7 +28,7 @@ import net.minecraft.util.Identifier class SearchPacket(structureId: Identifier) : PacketByteBuf(Unpooled.buffer()) { - companion object : ServerPlayNetworking.PlayChannelHandler { + companion object : PacketHandler { val ID = Identifier(MOD_ID, "search_packet") diff --git a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/SetSkipPacket.kt b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/SetSkipPacket.kt index 86aeadd..48d87cd 100644 --- a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/SetSkipPacket.kt +++ b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/c2s/SetSkipPacket.kt @@ -21,7 +21,6 @@ import io.github.samarium150.minecraft.mod.structures_compass.util.MOD_ID import io.github.samarium150.minecraft.mod.structures_compass.util.setSkip import io.netty.buffer.Unpooled import net.fabricmc.fabric.api.networking.v1.PacketSender -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking import net.minecraft.network.PacketByteBuf import net.minecraft.server.MinecraftServer import net.minecraft.server.network.ServerPlayNetworkHandler @@ -30,7 +29,7 @@ import net.minecraft.util.Identifier class SetSkipPacket(skip: Boolean) : PacketByteBuf(Unpooled.buffer()) { - companion object : ServerPlayNetworking.PlayChannelHandler { + companion object : PacketHandler { val ID = Identifier(MOD_ID, "set_skip") diff --git a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/s2c/PacketHandler.kt b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/s2c/PacketHandler.kt new file mode 100644 index 0000000..41d510f --- /dev/null +++ b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/s2c/PacketHandler.kt @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 Samarium + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.samarium150.minecraft.mod.structures_compass.network.packet.s2c + +import net.fabricmc.fabric.api.networking.v1.PacketSender +import net.minecraft.client.MinecraftClient +import net.minecraft.client.network.ClientPlayNetworkHandler +import net.minecraft.network.PacketByteBuf + +/** + * @see net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking.PlayChannelHandler + */ +fun interface PacketHandler { + fun receive( + client: MinecraftClient, + handler: ClientPlayNetworkHandler, + buf: PacketByteBuf, + responseSender: PacketSender + ) +} diff --git a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/s2c/SyncPacket.kt b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/s2c/SyncPacket.kt index 8f5f7ef..e3229b1 100644 --- a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/s2c/SyncPacket.kt +++ b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/network/packet/s2c/SyncPacket.kt @@ -22,7 +22,6 @@ import io.github.samarium150.minecraft.mod.structures_compass.util.MOD_ID import io.github.samarium150.minecraft.mod.structures_compass.util.getIdentifier import io.github.samarium150.minecraft.mod.structures_compass.util.getStructureFeature import io.netty.buffer.Unpooled -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking import net.fabricmc.fabric.api.networking.v1.PacketSender import net.minecraft.client.MinecraftClient import net.minecraft.client.network.ClientPlayNetworkHandler @@ -37,7 +36,7 @@ class SyncPacket( structuresDimensionsMap: Map, List> ) : PacketByteBuf(Unpooled.buffer()) { - companion object : ClientPlayNetworking.PlayChannelHandler { + companion object : PacketHandler { val ID = Identifier(MOD_ID, "sync_packet") diff --git a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/command/GetCompass.kt b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/server/command/GetCompass.kt similarity index 96% rename from src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/command/GetCompass.kt rename to src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/server/command/GetCompass.kt index 87c7d44..6658e11 100644 --- a/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/command/GetCompass.kt +++ b/src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/server/command/GetCompass.kt @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.samarium150.minecraft.mod.structures_compass.command +package io.github.samarium150.minecraft.mod.structures_compass.server.command import com.mojang.brigadier.Command import com.mojang.brigadier.CommandDispatcher