-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
89 changed files
with
5,756 additions
and
83 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...lib/api/networking/KessokuNetworking.java → ...nd/kessoku/lib/api/KessokuNetworking.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
networking/common/src/main/java/band/kessoku/lib/api/networking/LoginPacketSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package band.kessoku.lib.api.networking; | ||
|
||
import java.util.Objects; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.network.PacketCallbacks; | ||
import net.minecraft.network.packet.Packet; | ||
import net.minecraft.util.Identifier; | ||
|
||
/** | ||
* Represents something that supports sending packets to login channels. | ||
* @see PacketSender | ||
*/ | ||
@ApiStatus.NonExtendable | ||
public interface LoginPacketSender extends PacketSender { | ||
/** | ||
* Creates a packet for sending to a login channel. | ||
* | ||
* @param channelName the id of the channel | ||
* @param buf the content of the packet | ||
* @return the created packet | ||
*/ | ||
Packet<?> createPacket(Identifier channelName, PacketByteBuf buf); | ||
|
||
/** | ||
* Sends a packet to a channel. | ||
* | ||
* @param channel the id of the channel | ||
* @param buf the content of the packet | ||
*/ | ||
default void sendPacket(Identifier channel, PacketByteBuf buf) { | ||
Objects.requireNonNull(channel, "Channel cannot be null"); | ||
Objects.requireNonNull(buf, "Payload cannot be null"); | ||
|
||
this.sendPacket(this.createPacket(channel, buf)); | ||
} | ||
|
||
/** | ||
* Sends a packet to a channel. | ||
* | ||
* @param channel the id of the channel | ||
* @param buf the content of the packet | ||
* @param callback an optional callback to execute after the packet is sent, may be {@code null} | ||
*/ | ||
default void sendPacket(Identifier channel, PacketByteBuf buf, @Nullable PacketCallbacks callback) { | ||
Objects.requireNonNull(channel, "Channel cannot be null"); | ||
Objects.requireNonNull(buf, "Payload cannot be null"); | ||
|
||
this.sendPacket(this.createPacket(channel, buf), callback); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../networking/util/PacketByteBufHelper.java → ...b/api/networking/PacketByteBufHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
networking/common/src/main/java/band/kessoku/lib/api/networking/PacketSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package band.kessoku.lib.api.networking; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import net.minecraft.network.PacketCallbacks; | ||
import net.minecraft.network.packet.CustomPayload; | ||
import net.minecraft.network.packet.Packet; | ||
import net.minecraft.text.Text; | ||
|
||
/** | ||
* Represents something that supports sending packets to channels. | ||
* Any packets sent must be {@linkplain PayloadTypeRegistry registered} in the appropriate registry. | ||
*/ | ||
@ApiStatus.NonExtendable | ||
public interface PacketSender { | ||
/** | ||
* Creates a packet from a packet payload. | ||
* | ||
* @param payload the packet payload | ||
*/ | ||
Packet<?> createPacket(CustomPayload payload); | ||
|
||
/** | ||
* Sends a packet. | ||
* | ||
* @param packet the packet | ||
*/ | ||
default void sendPacket(Packet<?> packet) { | ||
sendPacket(packet, null); | ||
} | ||
|
||
/** | ||
* Sends a packet. | ||
* @param payload the payload | ||
*/ | ||
default void sendPacket(CustomPayload payload) { | ||
sendPacket(createPacket(payload)); | ||
} | ||
|
||
/** | ||
* Sends a packet. | ||
* | ||
* @param packet the packet | ||
* @param callback an optional callback to execute after the packet is sent, may be {@code null}. | ||
*/ | ||
void sendPacket(Packet<?> packet, @Nullable PacketCallbacks callback); | ||
|
||
/** | ||
* Sends a packet. | ||
* | ||
* @param payload the payload | ||
* @param callback an optional callback to execute after the packet is sent, may be {@code null}. | ||
*/ | ||
default void sendPacket(CustomPayload payload, @Nullable PacketCallbacks callback) { | ||
sendPacket(createPacket(payload), callback); | ||
} | ||
|
||
/** | ||
* Disconnects the player. | ||
* @param disconnectReason the reason for disconnection | ||
*/ | ||
void disconnect(Text disconnectReason); | ||
} |
56 changes: 56 additions & 0 deletions
56
networking/common/src/main/java/band/kessoku/lib/api/networking/PayloadTypeRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package band.kessoku.lib.api.networking; | ||
|
||
import band.kessoku.lib.impl.networking.PayloadTypeRegistryImpl; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.network.RegistryByteBuf; | ||
import net.minecraft.network.codec.PacketCodec; | ||
import net.minecraft.network.packet.CustomPayload; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
/** | ||
* A registry for payload types. | ||
*/ | ||
@ApiStatus.NonExtendable | ||
public interface PayloadTypeRegistry<B extends PacketByteBuf> { | ||
|
||
/** | ||
* Registers a custom payload type. | ||
* | ||
* <p>This must be done on both the sending and receiving side, usually during mod initialization | ||
* and <strong>before registering a packet handler</strong>. | ||
* | ||
* @param id the id of the payload type | ||
* @param codec the codec for the payload type | ||
* @param <T> the payload type | ||
* @return the registered payload type | ||
*/ | ||
<T extends CustomPayload> CustomPayload.Type<? super B, T> register(CustomPayload.Id<T> id, PacketCodec<? super B, T> codec); | ||
|
||
/** | ||
* @return the {@link PayloadTypeRegistry} instance for the client to server configuration channel. | ||
*/ | ||
static PayloadTypeRegistry<PacketByteBuf> configC2S() { | ||
return PayloadTypeRegistryImpl.CONFIG_C2S; | ||
} | ||
|
||
/** | ||
* @return the {@link PayloadTypeRegistry} instance for the server to client configuration channel. | ||
*/ | ||
static PayloadTypeRegistry<PacketByteBuf> configS2C() { | ||
return PayloadTypeRegistryImpl.CONFIG_S2C; | ||
} | ||
|
||
/** | ||
* @return the {@link PayloadTypeRegistry} instance for the client to server play channel. | ||
*/ | ||
static PayloadTypeRegistry<RegistryByteBuf> playC2S() { | ||
return PayloadTypeRegistryImpl.PLAY_C2S; | ||
} | ||
|
||
/** | ||
* @return the {@link PayloadTypeRegistry} instance for the server to client play channel. | ||
*/ | ||
static PayloadTypeRegistry<RegistryByteBuf> playS2C() { | ||
return PayloadTypeRegistryImpl.PLAY_S2C; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ConfigurationNetworkHandlerExtension.java → ...ConfigurationNetworkHandlerExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...on/src/main/java/band/kessoku/lib/api/networking/client/C2SConfigurationChannelEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package band.kessoku.lib.api.networking.client; | ||
|
||
import java.util.List; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientConfigurationNetworkHandler; | ||
import net.minecraft.util.Identifier; | ||
|
||
import band.kessoku.lib.event.api.Event; | ||
import band.kessoku.lib.api.networking.PacketSender; | ||
|
||
/** | ||
* Offers access to events related to the indication of a connected server's ability to receive packets in certain channels. | ||
*/ | ||
public final class C2SConfigurationChannelEvent { | ||
/** | ||
* An event for the client configuration network handler receiving an update indicating the connected server's ability to receive packets in certain channels. | ||
* This event may be invoked at any time after login and up to disconnection. | ||
*/ | ||
public static final Event<Register> REGISTER = Event.of(registers -> (handler, sender, client, channels) -> { | ||
for (Register callback : registers) { | ||
callback.onChannelRegister(handler, sender, client, channels); | ||
} | ||
}); | ||
|
||
/** | ||
* An event for the client configuration network handler receiving an update indicating the connected server's lack of ability to receive packets in certain channels. | ||
* This event may be invoked at any time after login and up to disconnection. | ||
*/ | ||
public static final Event<Unregister> UNREGISTER = Event.of(unregisters -> (handler, sender, client, channels) -> { | ||
for (Unregister callback : unregisters) { | ||
callback.onChannelUnregister(handler, sender, client, channels); | ||
} | ||
}); | ||
|
||
/** | ||
* @see C2SConfigurationChannelEvent#REGISTER | ||
*/ | ||
@FunctionalInterface | ||
public interface Register { | ||
void onChannelRegister(ClientConfigurationNetworkHandler handler, PacketSender sender, MinecraftClient client, List<Identifier> channels); | ||
} | ||
|
||
/** | ||
* @see C2SConfigurationChannelEvent#UNREGISTER | ||
*/ | ||
@FunctionalInterface | ||
public interface Unregister { | ||
void onChannelUnregister(ClientConfigurationNetworkHandler handler, PacketSender sender, MinecraftClient client, List<Identifier> channels); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...king/common/src/main/java/band/kessoku/lib/api/networking/client/C2SPlayChannelEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package band.kessoku.lib.api.networking.client; | ||
|
||
import java.util.List; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientPlayNetworkHandler; | ||
import net.minecraft.util.Identifier; | ||
|
||
import band.kessoku.lib.event.api.Event; | ||
import band.kessoku.lib.api.networking.PacketSender; | ||
|
||
/** | ||
* Offers access to events related to the indication of a connected server's ability to receive packets in certain channels. | ||
*/ | ||
public final class C2SPlayChannelEvent { | ||
/** | ||
* An event for the client play network handler receiving an update indicating the connected server's ability to receive packets in certain channels. | ||
* This event may be invoked at any time after login and up to disconnection. | ||
*/ | ||
public static final Event<Register> REGISTER = Event.of(registers -> (handler, sender, client, channels) -> { | ||
for (Register callback : registers) { | ||
callback.onChannelRegister(handler, sender, client, channels); | ||
} | ||
}); | ||
|
||
/** | ||
* An event for the client play network handler receiving an update indicating the connected server's lack of ability to receive packets in certain channels. | ||
* This event may be invoked at any time after login and up to disconnection. | ||
*/ | ||
public static final Event<Unregister> UNREGISTER = Event.of(unregisters -> (handler, sender, client, channels) -> { | ||
for (Unregister callback : unregisters) { | ||
callback.onChannelUnregister(handler, sender, client, channels); | ||
} | ||
}); | ||
|
||
/** | ||
* @see C2SPlayChannelEvent#REGISTER | ||
*/ | ||
@FunctionalInterface | ||
public interface Register { | ||
void onChannelRegister(ClientPlayNetworkHandler handler, PacketSender sender, MinecraftClient client, List<Identifier> channels); | ||
} | ||
|
||
/** | ||
* @see C2SPlayChannelEvent#UNREGISTER | ||
*/ | ||
@FunctionalInterface | ||
public interface Unregister { | ||
void onChannelUnregister(ClientPlayNetworkHandler handler, PacketSender sender, MinecraftClient client, List<Identifier> channels); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
.../main/java/band/kessoku/lib/api/networking/client/ClientConfigurationConnectionEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package band.kessoku.lib.api.networking.client; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientConfigurationNetworkHandler; | ||
import net.minecraft.network.packet.CustomPayload; | ||
|
||
import band.kessoku.lib.event.api.Event; | ||
|
||
/** | ||
* Offers access to events related to the configuration connection to a server on a logical client. | ||
*/ | ||
public final class ClientConfigurationConnectionEvent { | ||
/** | ||
* Event indicating a connection entering the CONFIGURATION state, ready for registering channel handlers. | ||
* | ||
* <p>No packets should be sent when this event is invoked. | ||
* | ||
* @see ClientConfigurationNetworking#registerReceiver(CustomPayload.Id, ClientConfigurationNetworking.ConfigurationPayloadHandler) | ||
*/ | ||
public static final Event<Init> INIT = Event.of(inits -> (handler, client) -> { | ||
for (ClientConfigurationConnectionEvent.Init callback : inits) { | ||
callback.onConfigurationInit(handler, client); | ||
} | ||
}); | ||
|
||
/** | ||
* An event called after the connection has been initialized and is ready to start sending and receiving configuration packets. | ||
* | ||
* <p>Packets may be sent during this event. | ||
*/ | ||
public static final Event<Start> START = Event.of(starts -> (handler, client) -> { | ||
for (ClientConfigurationConnectionEvent.Start callback : starts) { | ||
callback.onConfigurationStart(handler, client); | ||
} | ||
}); | ||
|
||
/** | ||
* An event called after the ReadyS2CPacket has been received, just before switching to the PLAY state. | ||
* | ||
* <p>No packets should be sent when this event is invoked. | ||
*/ | ||
public static final Event<Complete> COMPLETE = Event.of(completes -> (handler, client) -> { | ||
for (ClientConfigurationConnectionEvent.Complete callback : completes) { | ||
callback.onConfigurationComplete(handler, client); | ||
} | ||
}); | ||
|
||
/** | ||
* An event for the disconnection of the client configuration network handler. | ||
* | ||
* <p>No packets should be sent when this event is invoked. | ||
*/ | ||
public static final Event<Disconnect> DISCONNECT = Event.of(disconnects -> (handler, client) -> { | ||
for (ClientConfigurationConnectionEvent.Disconnect callback : disconnects) { | ||
callback.onConfigurationDisconnect(handler, client); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface Init { | ||
void onConfigurationInit(ClientConfigurationNetworkHandler handler, MinecraftClient client); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface Start { | ||
void onConfigurationStart(ClientConfigurationNetworkHandler handler, MinecraftClient client); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface Complete { | ||
void onConfigurationComplete(ClientConfigurationNetworkHandler handler, MinecraftClient client); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface Disconnect { | ||
void onConfigurationDisconnect(ClientConfigurationNetworkHandler handler, MinecraftClient client); | ||
} | ||
} |
Oops, something went wrong.