Skip to content

Commit

Permalink
fix: avoid using ClientPlayNetworking.PlayChannelHandler in packet in…
Browse files Browse the repository at this point in the history
…itialization
  • Loading branch information
Samarium150 committed Mar 22, 2022
1 parent 8f338b5 commit 0600925
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
*/

package io.github.samarium150.minecraft.mod.structures_compass.client

import io.github.samarium150.minecraft.mod.structures_compass.client.init.HudRegistry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
*/

package io.github.samarium150.minecraft.mod.structures_compass.client.init

import io.github.samarium150.minecraft.mod.structures_compass.client.item.StructuresCompassItemPredicate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
*/

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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/gpl-3.0.html>.
*/
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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
*/

package io.github.samarium150.minecraft.mod.structures_compass.network.packet.c2s

import io.github.samarium150.minecraft.mod.structures_compass.data.StructuresCompassData
Expand All @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
*/

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
Expand All @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/gpl-3.0.html>.
*/
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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,7 +36,7 @@ class SyncPacket(
structuresDimensionsMap: Map<StructureFeature<*>, List<Identifier>>
) : PacketByteBuf(Unpooled.buffer()) {

companion object : ClientPlayNetworking.PlayChannelHandler {
companion object : PacketHandler {

val ID = Identifier(MOD_ID, "sync_packet")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
*/
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
Expand Down

0 comments on commit 0600925

Please sign in to comment.