Skip to content

Commit

Permalink
Add core:networking
Browse files Browse the repository at this point in the history
  • Loading branch information
OroArmor committed Sep 2, 2024
1 parent ccf05f6 commit a6473c3
Show file tree
Hide file tree
Showing 87 changed files with 869 additions and 4,936 deletions.
4 changes: 4 additions & 0 deletions fabric-networking-api-v1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ testDependencies(project, [
loom {
accessWidenerPath = file('src/main/resources/fabric-networking-api-v1.accesswidener')
}

dependencies {
modApi getQslModule("core", "networking")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
* Copyright 2024 The Quilt Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,32 +24,40 @@
import net.minecraft.util.Identifier;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.impl.base.event.QuiltCompatEvent;
import net.fabricmc.fabric.impl.networking.QuiltUtil;

/**
* Offers access to events related to the indication of a connected server's ability to receive packets in certain channels.
*
* @deprecated see {@link org.quiltmc.qsl.networking.api.client.C2SConfigurationChannelEvents C2SConfigurationChannelEvents}
*/
@Deprecated
public final class C2SConfigurationChannelEvents {
/**
* 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.
*
* @deprecated see {@link org.quiltmc.qsl.networking.api.client.C2SConfigurationChannelEvents#REGISTER REGISTER}
*/
public static final Event<Register> REGISTER = EventFactory.createArrayBacked(Register.class, callbacks -> (handler, sender, client, channels) -> {
for (Register callback : callbacks) {
callback.onChannelRegister(handler, sender, client, channels);
}
});
@Deprecated
public static final Event<Register> REGISTER = QuiltCompatEvent.fromQuilt(org.quiltmc.qsl.networking.api.client.C2SConfigurationChannelEvents.REGISTER,
register -> (handler, sender, client, channels) -> register.onChannelRegister(handler, QuiltUtil.toFabricSender(sender), client, QuiltUtil.toIdentifiers(channels)),
invokerGetter -> (handler, sender, client, channels) -> invokerGetter.get().onChannelRegister(handler, QuiltUtil.toQuiltSender(sender), client, QuiltUtil.toPayloadIds(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.
*
* @deprecated see {@link org.quiltmc.qsl.networking.api.client.C2SConfigurationChannelEvents#UNREGISTER UNREGISTER}
*/
public static final Event<Unregister> UNREGISTER = EventFactory.createArrayBacked(Unregister.class, callbacks -> (handler, sender, client, channels) -> {
for (Unregister callback : callbacks) {
callback.onChannelUnregister(handler, sender, client, channels);
}
});
@Deprecated
public static final Event<Unregister> UNREGISTER = QuiltCompatEvent.fromQuilt(org.quiltmc.qsl.networking.api.client.C2SConfigurationChannelEvents.UNREGISTER,
register -> (handler, sender, client, channels) -> register.onChannelUnregister(handler, QuiltUtil.toFabricSender(sender), client, QuiltUtil.toIdentifiers(channels)),
invokerGetter -> (handler, sender, client, channels) -> invokerGetter.get().onChannelUnregister(handler, QuiltUtil.toQuiltSender(sender), client, QuiltUtil.toPayloadIds(channels))
);

private C2SConfigurationChannelEvents() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
* Copyright 2022 The Quilt Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,30 +26,39 @@
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.impl.base.event.QuiltCompatEvent;
import net.fabricmc.fabric.impl.networking.QuiltUtil;

/**
* Offers access to events related to the indication of a connected server's ability to receive packets in certain channels.
*
* @deprecated see {@link org.quiltmc.qsl.networking.api.client.C2SPlayChannelEvents C2SPlayChannelEvents}
*/
@Deprecated
public final class C2SPlayChannelEvents {
/**
* 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.
*
* @deprecated see {@link org.quiltmc.qsl.networking.api.client.C2SPlayChannelEvents#REGISTER REGISTER}
*/
public static final Event<Register> REGISTER = EventFactory.createArrayBacked(Register.class, callbacks -> (handler, sender, client, channels) -> {
for (Register callback : callbacks) {
callback.onChannelRegister(handler, sender, client, channels);
}
});
@Deprecated
public static final Event<Register> REGISTER = QuiltCompatEvent.fromQuilt(org.quiltmc.qsl.networking.api.client.C2SPlayChannelEvents.REGISTER,
register -> (handler, sender, client, channels) -> register.onChannelRegister(handler, QuiltUtil.toFabricSender(sender), client, QuiltUtil.toIdentifiers(channels)),
invokerGetter -> (handler, sender, client, channels) -> invokerGetter.get().onChannelRegister(handler, QuiltUtil.toQuiltSender(sender), client, QuiltUtil.toPayloadIds(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.
*
* @deprecated see {@link org.quiltmc.qsl.networking.api.client.C2SPlayChannelEvents#REGISTER REGISTER}
*/
public static final Event<Unregister> UNREGISTER = EventFactory.createArrayBacked(Unregister.class, callbacks -> (handler, sender, client, channels) -> {
for (Unregister callback : callbacks) {
callback.onChannelUnregister(handler, sender, client, channels);
}
});
@Deprecated
public static final Event<Unregister> UNREGISTER = QuiltCompatEvent.fromQuilt(org.quiltmc.qsl.networking.api.client.C2SPlayChannelEvents.UNREGISTER,
register -> (handler, sender, client, channels) -> register.onChannelUnregister(handler, QuiltUtil.toFabricSender(sender), client, QuiltUtil.toIdentifiers(channels)),
invokerGetter -> (handler, sender, client, channels) -> invokerGetter.get().onChannelUnregister(handler, QuiltUtil.toQuiltSender(sender), client, QuiltUtil.toPayloadIds(channels))
);

private C2SPlayChannelEvents() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
* Copyright 2024 The Quilt Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,62 +17,77 @@

package net.fabricmc.fabric.api.client.networking.v1;

import org.quiltmc.qsl.networking.impl.AbstractChanneledNetworkAddon;
import org.quiltmc.qsl.networking.impl.NetworkHandlerExtensions;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientConfigurationNetworkHandler;
import net.minecraft.network.packet.CustomPayload;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.fabricmc.fabric.impl.base.event.QuiltCompatEvent;

/**
* Offers access to events related to the configuration connection to a server on a logical client.
*
* @deprecated see {@link org.quiltmc.qsl.networking.api.client.ClientConfigurationConnectionEvents ClientConfigurationConnectionEvents}
*/
@Deprecated
public final class ClientConfigurationConnectionEvents {
/**
* 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)
*
* @deprecated see {@link org.quiltmc.qsl.networking.api.client.ClientConfigurationConnectionEvents#INIT INIT}
*/
public static final Event<ClientConfigurationConnectionEvents.Init> INIT = EventFactory.createArrayBacked(ClientConfigurationConnectionEvents.Init.class, callbacks -> (handler, client) -> {
for (ClientConfigurationConnectionEvents.Init callback : callbacks) {
callback.onConfigurationInit(handler, client);
}
});
@Deprecated
public static final Event<ClientConfigurationConnectionEvents.Init> INIT = QuiltCompatEvent.fromQuilt(org.quiltmc.qsl.networking.api.client.ClientConfigurationConnectionEvents.INIT,
init -> init::onConfigurationInit,
invokerGetter -> invokerGetter.get()::onConfigurationInit
);

/**
* 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.
*
* @deprecated see {@link org.quiltmc.qsl.networking.api.client.ClientConfigurationConnectionEvents#START START}
*/
public static final Event<ClientConfigurationConnectionEvents.Start> START = EventFactory.createArrayBacked(ClientConfigurationConnectionEvents.Start.class, callbacks -> (handler, client) -> {
for (ClientConfigurationConnectionEvents.Start callback : callbacks) {
callback.onConfigurationStart(handler, client);
}
});
@Deprecated
public static final Event<ClientConfigurationConnectionEvents.Start> START = QuiltCompatEvent.fromQuilt(org.quiltmc.qsl.networking.api.client.ClientConfigurationConnectionEvents.START,
init -> (handler, sender, client) -> init.onConfigurationStart(handler, client),
invokerGetter -> (handler, client) -> invokerGetter.get().onConfigurationStart(handler, ((AbstractChanneledNetworkAddon<?>) ((NetworkHandlerExtensions) handler).getAddon()), 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.
*
* @deprecated see {@link org.quiltmc.qsl.networking.api.client.ClientConfigurationConnectionEvents#CONFIGURED CONFIGURED}
*/
public static final Event<ClientConfigurationConnectionEvents.Complete> COMPLETE = EventFactory.createArrayBacked(ClientConfigurationConnectionEvents.Complete.class, callbacks -> (handler, client) -> {
for (ClientConfigurationConnectionEvents.Complete callback : callbacks) {
callback.onConfigurationComplete(handler, client);
}
});
@Deprecated
public static final Event<ClientConfigurationConnectionEvents.Complete> COMPLETE = QuiltCompatEvent.fromQuilt(org.quiltmc.qsl.networking.api.client.ClientConfigurationConnectionEvents.CONFIGURED,
init -> init::onConfigurationComplete,
invokerGetter -> invokerGetter.get()::onConfigured
);

/**
* An event for the disconnection of the client configuration network handler.
*
* <p>No packets should be sent when this event is invoked.
*
* @deprecated see {@link org.quiltmc.qsl.networking.api.client.ClientConfigurationConnectionEvents#DISCONNECT DISCONNECT}
*/
public static final Event<ClientConfigurationConnectionEvents.Disconnect> DISCONNECT = EventFactory.createArrayBacked(ClientConfigurationConnectionEvents.Disconnect.class, callbacks -> (handler, client) -> {
for (ClientConfigurationConnectionEvents.Disconnect callback : callbacks) {
callback.onConfigurationDisconnect(handler, client);
}
});
@Deprecated
public static final Event<ClientConfigurationConnectionEvents.Disconnect> DISCONNECT = QuiltCompatEvent.fromQuilt(org.quiltmc.qsl.networking.api.client.ClientConfigurationConnectionEvents.DISCONNECT,
init -> init::onConfigurationDisconnect,
invokerGetter -> invokerGetter.get()::onConfigurationDisconnect
);

private ClientConfigurationConnectionEvents() {
}
Expand Down
Loading

0 comments on commit a6473c3

Please sign in to comment.