|
| 1 | +package band.kessoku.lib.api.networking.client; |
| 2 | + |
| 3 | +import net.minecraft.client.MinecraftClient; |
| 4 | +import net.minecraft.client.network.ClientConfigurationNetworkHandler; |
| 5 | +import net.minecraft.network.packet.CustomPayload; |
| 6 | + |
| 7 | +import band.kessoku.lib.event.api.Event; |
| 8 | + |
| 9 | +/** |
| 10 | + * Offers access to events related to the configuration connection to a server on a logical client. |
| 11 | + */ |
| 12 | +public final class ClientConfigurationConnectionEvent { |
| 13 | + /** |
| 14 | + * Event indicating a connection entering the CONFIGURATION state, ready for registering channel handlers. |
| 15 | + * |
| 16 | + * <p>No packets should be sent when this event is invoked. |
| 17 | + * |
| 18 | + * @see ClientConfigurationNetworking#registerReceiver(CustomPayload.Id, ClientConfigurationNetworking.ConfigurationPayloadHandler) |
| 19 | + */ |
| 20 | + public static final Event<Init> INIT = Event.of(inits -> (handler, client) -> { |
| 21 | + for (ClientConfigurationConnectionEvent.Init callback : inits) { |
| 22 | + callback.onConfigurationInit(handler, client); |
| 23 | + } |
| 24 | + }); |
| 25 | + |
| 26 | + /** |
| 27 | + * An event called after the connection has been initialized and is ready to start sending and receiving configuration packets. |
| 28 | + * |
| 29 | + * <p>Packets may be sent during this event. |
| 30 | + */ |
| 31 | + public static final Event<Start> START = Event.of(starts -> (handler, client) -> { |
| 32 | + for (ClientConfigurationConnectionEvent.Start callback : starts) { |
| 33 | + callback.onConfigurationStart(handler, client); |
| 34 | + } |
| 35 | + }); |
| 36 | + |
| 37 | + /** |
| 38 | + * An event called after the ReadyS2CPacket has been received, just before switching to the PLAY state. |
| 39 | + * |
| 40 | + * <p>No packets should be sent when this event is invoked. |
| 41 | + */ |
| 42 | + public static final Event<Complete> COMPLETE = Event.of(completes -> (handler, client) -> { |
| 43 | + for (ClientConfigurationConnectionEvent.Complete callback : completes) { |
| 44 | + callback.onConfigurationComplete(handler, client); |
| 45 | + } |
| 46 | + }); |
| 47 | + |
| 48 | + /** |
| 49 | + * An event for the disconnection of the client configuration network handler. |
| 50 | + * |
| 51 | + * <p>No packets should be sent when this event is invoked. |
| 52 | + */ |
| 53 | + public static final Event<Disconnect> DISCONNECT = Event.of(disconnects -> (handler, client) -> { |
| 54 | + for (ClientConfigurationConnectionEvent.Disconnect callback : disconnects) { |
| 55 | + callback.onConfigurationDisconnect(handler, client); |
| 56 | + } |
| 57 | + }); |
| 58 | + |
| 59 | + @FunctionalInterface |
| 60 | + public interface Init { |
| 61 | + void onConfigurationInit(ClientConfigurationNetworkHandler handler, MinecraftClient client); |
| 62 | + } |
| 63 | + |
| 64 | + @FunctionalInterface |
| 65 | + public interface Start { |
| 66 | + void onConfigurationStart(ClientConfigurationNetworkHandler handler, MinecraftClient client); |
| 67 | + } |
| 68 | + |
| 69 | + @FunctionalInterface |
| 70 | + public interface Complete { |
| 71 | + void onConfigurationComplete(ClientConfigurationNetworkHandler handler, MinecraftClient client); |
| 72 | + } |
| 73 | + |
| 74 | + @FunctionalInterface |
| 75 | + public interface Disconnect { |
| 76 | + void onConfigurationDisconnect(ClientConfigurationNetworkHandler handler, MinecraftClient client); |
| 77 | + } |
| 78 | +} |
0 commit comments