mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 07:17:58 +01:00
Fixed naming being swapped. Derp.
This commit is contained in:
parent
e6c3c25ac4
commit
8bfa54b408
5 changed files with 32 additions and 31 deletions
|
@ -1,20 +1,21 @@
|
||||||
package com.minelittlepony.unicopia.network;
|
package com.minelittlepony.unicopia.network;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.util.network.S2CBroadcastPacketType;
|
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.S2CPacketType;
|
||||||
|
import com.minelittlepony.unicopia.util.network.C2SPacketType;
|
||||||
import com.minelittlepony.unicopia.util.network.SimpleNetworking;
|
import com.minelittlepony.unicopia.util.network.SimpleNetworking;
|
||||||
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public interface Channel {
|
public interface Channel {
|
||||||
S2CPacketType<MsgPlayerAbility<?>> CLIENT_PLAYER_ABILITY = SimpleNetworking.clientToServer(new Identifier("unicopia", "player_ability"), MsgPlayerAbility::new);
|
C2SPacketType<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);
|
C2SPacketType<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<MsgPlayerCapabilities> SERVER_PLAYER_CAPABILITIES = SimpleNetworking.serverToClient(new Identifier("unicopia", "player_capabilities"), MsgPlayerCapabilities::new);
|
S2CPacketType<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);
|
S2CPacketType<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<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() { }
|
static void bootstrap() { }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
package com.minelittlepony.unicopia.util.network;
|
package com.minelittlepony.unicopia.util.network;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
import com.google.common.base.Preconditions;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
|
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.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.util.Identifier;
|
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();
|
Identifier getId();
|
||||||
|
|
||||||
default void send(ServerPlayerEntity recipient, T packet) {
|
default void send(T packet) {
|
||||||
ServerPlayNetworking.send(recipient, getId(), packet.toBuffer());
|
Preconditions.checkState(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT, "Client packet send called by the server");
|
||||||
}
|
ClientPlayNetworking.send(getId(), packet.toBuffer());
|
||||||
|
|
||||||
default net.minecraft.network.Packet<?> toPacket(T packet) {
|
|
||||||
return ServerPlayNetworking.createS2CPacket(getId(), packet.toBuffer());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,21 +1,21 @@
|
||||||
package com.minelittlepony.unicopia.util.network;
|
package com.minelittlepony.unicopia.util.network;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
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.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.util.Identifier;
|
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();
|
Identifier getId();
|
||||||
|
|
||||||
default void send(T packet) {
|
default void send(ServerPlayerEntity recipient, T packet) {
|
||||||
Preconditions.checkState(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT, "Client packet send called by the server");
|
ServerPlayNetworking.send(recipient, getId(), packet.toBuffer());
|
||||||
ClientPlayNetworking.send(getId(), packet.toBuffer());
|
}
|
||||||
|
|
||||||
|
default net.minecraft.network.Packet<?> toPacket(T packet) {
|
||||||
|
return ServerPlayNetworking.createS2CPacket(getId(), packet.toBuffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -23,7 +23,7 @@ import net.minecraft.util.Identifier;
|
||||||
* All of the above is handled in a black-box style by this class.
|
* All of the above is handled in a black-box style by this class.
|
||||||
* <p>
|
* <p>
|
||||||
* <ul>
|
* <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>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>
|
* <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
|
* @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) -> {
|
ServerPlayNetworking.registerGlobalReceiver(id, (server, player, handler, buffer, responder) -> {
|
||||||
T packet = factory.apply(buffer);
|
T packet = factory.apply(buffer);
|
||||||
server.execute(() -> packet.handle(player));
|
server.execute(() -> packet.handle(player));
|
||||||
|
@ -59,7 +59,7 @@ public final class SimpleNetworking {
|
||||||
*
|
*
|
||||||
* @return A registered PacketType
|
* @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) {
|
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||||
ClientProxy.register(id, factory);
|
ClientProxy.register(id, factory);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue