Fixed naming being swapped. Derp.

This commit is contained in:
Sollace 2021-07-22 18:48:44 +02:00
parent e6c3c25ac4
commit 8bfa54b408
5 changed files with 32 additions and 31 deletions

View file

@ -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<MsgPlayerAbility<?>> CLIENT_PLAYER_ABILITY = SimpleNetworking.clientToServer(new Identifier("unicopia", "player_ability"), MsgPlayerAbility::new);
S2CPacketType<MsgRequestCapabilities> CLIENT_REQUEST_CAPABILITIES = SimpleNetworking.clientToServer(new Identifier("unicopia", "request_capabilities"), MsgRequestCapabilities::new);
S2CBroadcastPacketType<MsgOtherPlayerCapabilities> SERVER_OTHER_PLAYER_CAPABILITIES = SimpleNetworking.serverToClients(new Identifier("unicopia", "other_player_capabilities"), MsgOtherPlayerCapabilities::new);
C2SPacketType<MsgPlayerAbility<?>> CLIENT_PLAYER_ABILITY = SimpleNetworking.clientToServer(new Identifier("unicopia", "player_ability"), MsgPlayerAbility::new);
C2SPacketType<MsgRequestCapabilities> CLIENT_REQUEST_CAPABILITIES = SimpleNetworking.clientToServer(new Identifier("unicopia", "request_capabilities"), MsgRequestCapabilities::new);
C2SPacketType<MsgPlayerCapabilities> SERVER_PLAYER_CAPABILITIES = SimpleNetworking.serverToClient(new Identifier("unicopia", "player_capabilities"), MsgPlayerCapabilities::new);
C2SPacketType<MsgSpawnProjectile> SERVER_SPAWN_PROJECTILE = SimpleNetworking.serverToClient(new Identifier("unicopia", "projectile_entity"), MsgSpawnProjectile::new);
C2SPacketType<MsgBlockDestruction> SERVER_BLOCK_DESTRUCTION = SimpleNetworking.serverToClient(new Identifier("unicopia", "block_destruction"), MsgBlockDestruction::new);
S2CPacketType<MsgPlayerCapabilities> SERVER_PLAYER_CAPABILITIES = SimpleNetworking.serverToClient(new Identifier("unicopia", "player_capabilities"), MsgPlayerCapabilities::new);
S2CPacketType<MsgSpawnProjectile> SERVER_SPAWN_PROJECTILE = SimpleNetworking.serverToClient(new Identifier("unicopia", "projectile_entity"), MsgSpawnProjectile::new);
S2CPacketType<MsgBlockDestruction> SERVER_BLOCK_DESTRUCTION = SimpleNetworking.serverToClient(new Identifier("unicopia", "block_destruction"), MsgBlockDestruction::new);
S2CBroadcastPacketType<MsgOtherPlayerCapabilities> SERVER_OTHER_PLAYER_CAPABILITIES = SimpleNetworking.serverToClients(new Identifier("unicopia", "other_player_capabilities"), MsgOtherPlayerCapabilities::new);
static void bootstrap() { }
}

View file

@ -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<T extends Packet<PlayerEntity>> {
public interface C2SPacketType<T extends Packet<ServerPlayerEntity>> {
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());
}
}

View file

@ -19,4 +19,4 @@ public interface S2CBroadcastPacketType<T extends Packet<PlayerEntity>> {
}
});
}
}
}

View file

@ -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<T extends Packet<ServerPlayerEntity>> {
public interface S2CPacketType<T extends Packet<PlayerEntity>> {
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());
}
}

View file

@ -23,7 +23,7 @@ import net.minecraft.util.Identifier;
* All of the above is handled in a black-box style by this class.
* <p>
* <ul>
* <li>Packets are automatically reigstered on the appropriate sides.</li>
* <li>Packets are automatically registered on the appropriate sides.</li>
* <li>Sending is done in the same way by calling `send` on your packet type.</li>
* <li>Your packet's <code>handle</code> method is executed on the main thread where it is safe to interact with the world.</li>
*/
@ -41,7 +41,7 @@ public final class SimpleNetworking {
*
* @return A registered PacketType
*/
public static <T extends Packet<ServerPlayerEntity>> S2CPacketType<T> clientToServer(Identifier id, Function<PacketByteBuf, T> factory) {
public static <T extends Packet<ServerPlayerEntity>> C2SPacketType<T> clientToServer(Identifier id, Function<PacketByteBuf, T> 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 <T extends Packet<PlayerEntity>> C2SPacketType<T> serverToClient(Identifier id, Function<PacketByteBuf, T> factory) {
public static <T extends Packet<PlayerEntity>> S2CPacketType<T> serverToClient(Identifier id, Function<PacketByteBuf, T> factory) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
ClientProxy.register(id, factory);
}