Backport networking v1 fixes from 1.16 to 1.15 (#1235)

* Fix registry sync being applied when its not supposed to be.

Fixes #1217
Fixes #1216

* Check channels the server can receive, not channels the client can (#1224)

* Fix v0 deprecation javadoc error (#1209)

Co-authored-by: modmuss50 <modmuss50@gmail.com>
This commit is contained in:
i509VCB 2020-12-23 08:19:21 -06:00 committed by GitHub
parent 463fa90e22
commit 7f3984e3f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 4 deletions

View file

@ -24,6 +24,7 @@ import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.client.networking.v1.C2SPlayChannelEvents;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.fabricmc.fabric.api.networking.v1.S2CPlayChannelEvents;
/**
* Event for listening to packet type registration and unregistration notifications
@ -32,7 +33,7 @@ import net.fabricmc.fabric.api.event.EventFactory;
* <p>Registrations received will be for <em>server -&gt; client</em> packets
* that the sending client can understand.
*
* @deprecated Please migrate to {@link C2SPlayChannelEvents}.
* @deprecated Please migrate to {@link S2CPlayChannelEvents} since this was incorrectly named.
*/
@Deprecated
public interface C2SPacketTypeCallback {

View file

@ -20,6 +20,7 @@ import java.util.Collection;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.client.networking.v1.C2SPlayChannelEvents;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.fabricmc.fabric.api.networking.v1.S2CPlayChannelEvents;
@ -31,7 +32,7 @@ import net.fabricmc.fabric.api.networking.v1.S2CPlayChannelEvents;
* <p>Registrations received will be for <em>client -&gt; server</em> packets
* that the sending server can understand.
*
* @deprecated Please migrate to {@link S2CPlayChannelEvents}.
* @deprecated Please migrate to {@link C2SPlayChannelEvents} since this was incorrectly named.
*/
@Deprecated
public interface S2CPacketTypeCallback {

View file

@ -38,7 +38,7 @@ import net.fabricmc.fabric.api.network.PacketRegistry;
public class ClientSidePacketRegistryImpl implements ClientSidePacketRegistry, PacketRegistry {
@Override
public boolean canServerReceive(Identifier id) {
return ClientPlayNetworking.getReceived().contains(id);
return ClientPlayNetworking.getSendable().contains(id);
}
@Override

View file

@ -31,7 +31,7 @@ public class FabricRegistryClientInit implements ClientModInitializer {
public void onInitializeClient() {
ClientPlayNetworking.registerGlobalReceiver(RegistrySyncManager.ID, (client, handler, buf, responseSender) -> {
// if not hosting server, apply packet
RegistrySyncManager.receivePacket(client, buf, RegistrySyncManager.DEBUG || client.isInSingleplayer(), (e) -> {
RegistrySyncManager.receivePacket(client, buf, RegistrySyncManager.DEBUG || !client.isInSingleplayer(), (e) -> {
LOGGER.error("Registry remapping failed!", e);
client.execute(() -> {