From 8bfa54b40851ff79f482c8194e743e325a2219dd Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 22 Jul 2021 18:48:44 +0200 Subject: [PATCH] Fixed naming being swapped. Derp. --- .../unicopia/network/Channel.java | 15 +++++++------- .../unicopia/util/network/C2SPacketType.java | 20 +++++++++---------- .../util/network/S2CBroadcastPacketType.java | 2 +- .../unicopia/util/network/S2CPacketType.java | 20 +++++++++---------- .../util/network/SimpleNetworking.java | 6 +++--- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/network/Channel.java b/src/main/java/com/minelittlepony/unicopia/network/Channel.java index ba18c24e..73aa6057 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/Channel.java +++ b/src/main/java/com/minelittlepony/unicopia/network/Channel.java @@ -1,20 +1,21 @@ package com.minelittlepony.unicopia.network; import com.minelittlepony.unicopia.util.network.S2CBroadcastPacketType; -import com.minelittlepony.unicopia.util.network.C2SPacketType; import com.minelittlepony.unicopia.util.network.S2CPacketType; +import com.minelittlepony.unicopia.util.network.C2SPacketType; import com.minelittlepony.unicopia.util.network.SimpleNetworking; import net.minecraft.util.Identifier; public interface Channel { - S2CPacketType> CLIENT_PLAYER_ABILITY = SimpleNetworking.clientToServer(new Identifier("unicopia", "player_ability"), MsgPlayerAbility::new); - S2CPacketType CLIENT_REQUEST_CAPABILITIES = SimpleNetworking.clientToServer(new Identifier("unicopia", "request_capabilities"), MsgRequestCapabilities::new); - S2CBroadcastPacketType SERVER_OTHER_PLAYER_CAPABILITIES = SimpleNetworking.serverToClients(new Identifier("unicopia", "other_player_capabilities"), MsgOtherPlayerCapabilities::new); + C2SPacketType> CLIENT_PLAYER_ABILITY = SimpleNetworking.clientToServer(new Identifier("unicopia", "player_ability"), MsgPlayerAbility::new); + C2SPacketType CLIENT_REQUEST_CAPABILITIES = SimpleNetworking.clientToServer(new Identifier("unicopia", "request_capabilities"), MsgRequestCapabilities::new); - C2SPacketType SERVER_PLAYER_CAPABILITIES = SimpleNetworking.serverToClient(new Identifier("unicopia", "player_capabilities"), MsgPlayerCapabilities::new); - C2SPacketType SERVER_SPAWN_PROJECTILE = SimpleNetworking.serverToClient(new Identifier("unicopia", "projectile_entity"), MsgSpawnProjectile::new); - C2SPacketType SERVER_BLOCK_DESTRUCTION = SimpleNetworking.serverToClient(new Identifier("unicopia", "block_destruction"), MsgBlockDestruction::new); + S2CPacketType SERVER_PLAYER_CAPABILITIES = SimpleNetworking.serverToClient(new Identifier("unicopia", "player_capabilities"), MsgPlayerCapabilities::new); + S2CPacketType SERVER_SPAWN_PROJECTILE = SimpleNetworking.serverToClient(new Identifier("unicopia", "projectile_entity"), MsgSpawnProjectile::new); + S2CPacketType SERVER_BLOCK_DESTRUCTION = SimpleNetworking.serverToClient(new Identifier("unicopia", "block_destruction"), MsgBlockDestruction::new); + + S2CBroadcastPacketType SERVER_OTHER_PLAYER_CAPABILITIES = SimpleNetworking.serverToClients(new Identifier("unicopia", "other_player_capabilities"), MsgOtherPlayerCapabilities::new); static void bootstrap() { } } diff --git a/src/main/java/com/minelittlepony/unicopia/util/network/C2SPacketType.java b/src/main/java/com/minelittlepony/unicopia/util/network/C2SPacketType.java index a81010c8..e9d0d1a6 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/network/C2SPacketType.java +++ b/src/main/java/com/minelittlepony/unicopia/util/network/C2SPacketType.java @@ -1,21 +1,21 @@ package com.minelittlepony.unicopia.util.network; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.entity.player.PlayerEntity; +import com.google.common.base.Preconditions; + +import net.fabricmc.api.EnvType; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; /** - * A client packet type. Sent by the server to a specific player. + * A server packet type. Sent by the client to the server. */ -public interface C2SPacketType> { +public interface C2SPacketType> { Identifier getId(); - default void send(ServerPlayerEntity recipient, T packet) { - ServerPlayNetworking.send(recipient, getId(), packet.toBuffer()); - } - - default net.minecraft.network.Packet toPacket(T packet) { - return ServerPlayNetworking.createS2CPacket(getId(), packet.toBuffer()); + default void send(T packet) { + Preconditions.checkState(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT, "Client packet send called by the server"); + ClientPlayNetworking.send(getId(), packet.toBuffer()); } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/util/network/S2CBroadcastPacketType.java b/src/main/java/com/minelittlepony/unicopia/util/network/S2CBroadcastPacketType.java index 06a215a8..643ec14e 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/network/S2CBroadcastPacketType.java +++ b/src/main/java/com/minelittlepony/unicopia/util/network/S2CBroadcastPacketType.java @@ -19,4 +19,4 @@ public interface S2CBroadcastPacketType> { } }); } -} \ No newline at end of file +} diff --git a/src/main/java/com/minelittlepony/unicopia/util/network/S2CPacketType.java b/src/main/java/com/minelittlepony/unicopia/util/network/S2CPacketType.java index aa9a4e6f..f17ce593 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/network/S2CPacketType.java +++ b/src/main/java/com/minelittlepony/unicopia/util/network/S2CPacketType.java @@ -1,21 +1,21 @@ package com.minelittlepony.unicopia.util.network; -import com.google.common.base.Preconditions; - -import net.fabricmc.api.EnvType; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; /** - * A server packet type. Sent by the client to the server. + * A client packet type. Sent by the server to a specific player. */ -public interface S2CPacketType> { +public interface S2CPacketType> { Identifier getId(); - default void send(T packet) { - Preconditions.checkState(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT, "Client packet send called by the server"); - ClientPlayNetworking.send(getId(), packet.toBuffer()); + default void send(ServerPlayerEntity recipient, T packet) { + ServerPlayNetworking.send(recipient, getId(), packet.toBuffer()); + } + + default net.minecraft.network.Packet toPacket(T packet) { + return ServerPlayNetworking.createS2CPacket(getId(), packet.toBuffer()); } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/util/network/SimpleNetworking.java b/src/main/java/com/minelittlepony/unicopia/util/network/SimpleNetworking.java index d96c3b78..8fce0ecd 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/network/SimpleNetworking.java +++ b/src/main/java/com/minelittlepony/unicopia/util/network/SimpleNetworking.java @@ -23,7 +23,7 @@ import net.minecraft.util.Identifier; * All of the above is handled in a black-box style by this class. *

*

    - *
  • Packets are automatically reigstered on the appropriate sides.
  • + *
  • Packets are automatically registered on the appropriate sides.
  • *
  • Sending is done in the same way by calling `send` on your packet type.
  • *
  • Your packet's handle method is executed on the main thread where it is safe to interact with the world.
  • */ @@ -41,7 +41,7 @@ public final class SimpleNetworking { * * @return A registered PacketType */ - public static > S2CPacketType clientToServer(Identifier id, Function factory) { + public static > C2SPacketType clientToServer(Identifier id, Function factory) { ServerPlayNetworking.registerGlobalReceiver(id, (server, player, handler, buffer, responder) -> { T packet = factory.apply(buffer); server.execute(() -> packet.handle(player)); @@ -59,7 +59,7 @@ public final class SimpleNetworking { * * @return A registered PacketType */ - public static > C2SPacketType serverToClient(Identifier id, Function factory) { + public static > S2CPacketType serverToClient(Identifier id, Function factory) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { ClientProxy.register(id, factory); }