Skip to content

Commit

Permalink
Start on (hopefully) final networking API cleanup and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Aug 14, 2023
1 parent 11da534 commit 4ecd34d
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import net.fabricmc.fabric.impl.networking.payload.PacketByteBufPayload;
import net.fabricmc.fabric.mixin.networking.client.accessor.ClientCommonNetworkHandlerAccessor;
import net.fabricmc.fabric.mixin.networking.client.accessor.ClientConfigurationNetworkHandlerAccessor;
import net.fabricmc.fabric.mixin.networking.client.accessor.ClientLoginNetworkHandlerAccessor;

public final class ClientConfigurationNetworkAddon extends AbstractChanneledNetworkAddon<ClientConfigurationNetworking.ConfigurationChannelHandler> {
private final ClientConfigurationNetworkHandler handler;
Expand Down Expand Up @@ -167,6 +166,6 @@ protected boolean isReservedChannel(Identifier channelName) {
}

public ChannelInfoHolder getChannelInfoHolder() {
return (ChannelInfoHolder) ((ClientLoginNetworkHandlerAccessor) handler).getConnection();
return (ChannelInfoHolder) ((ClientCommonNetworkHandlerAccessor) handler).getConnection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import net.fabricmc.fabric.impl.networking.GlobalReceiverRegistry;
import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions;
import net.fabricmc.fabric.impl.networking.NetworkingImpl;
import net.fabricmc.fabric.impl.networking.payload.FabricPacketPayload;
import net.fabricmc.fabric.impl.networking.payload.PacketByteBufPayload;
import net.fabricmc.fabric.mixin.networking.client.accessor.ConnectScreenAccessor;
import net.fabricmc.fabric.mixin.networking.client.accessor.MinecraftClientAccessor;
Expand Down Expand Up @@ -79,13 +78,9 @@ public static Packet<ServerCommonPacketListener> createC2SPacket(FabricPacket pa
Objects.requireNonNull(packet, "Packet cannot be null");
Objects.requireNonNull(packet.getType(), "Packet#getType cannot return null");

if (NetworkingImpl.WRITE_FABRIC_PACKET_CALLING_THREAD) {
PacketByteBuf buf = PacketByteBufs.create();
packet.write(buf);
return createC2SPacket(packet.getType().getId(), buf);
}

return new CustomPayloadC2SPacket(new FabricPacketPayload(packet));
PacketByteBuf buf = PacketByteBufs.create();
packet.write(buf);
return createC2SPacket(packet.getType().getId(), buf);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ public final class NetworkingImpl {
public static final String MOD_ID = "fabric-networking-api-v1";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

/**
* When enabled the fabric packet is written to the {@link net.minecraft.network.PacketByteBuf} on the calling thread.
* This is not enabled by default as it currently causes issues in single player.
*/
public static final boolean WRITE_FABRIC_PACKET_CALLING_THREAD = Boolean.parseBoolean(System.getProperty("fabric-api.networking.write-fabric-packet-calling-thread", "true"));

/**
* Id of packet used to register supported channels.
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import net.fabricmc.fabric.impl.networking.NetworkingImpl;
import net.fabricmc.fabric.impl.networking.payload.PacketByteBufPayload;
import net.fabricmc.fabric.mixin.networking.accessor.ServerCommonNetworkHandlerAccessor;
import net.fabricmc.fabric.mixin.networking.accessor.ServerLoginNetworkHandlerAccessor;

public final class ServerConfigurationNetworkAddon extends AbstractChanneledNetworkAddon<ServerConfigurationNetworking.ConfigurationChannelHandler> {
private final ServerConfigurationNetworkHandler handler;
Expand Down Expand Up @@ -199,6 +198,6 @@ private enum RegisterState {
}

public ChannelInfoHolder getChannelInfoHolder() {
return (ChannelInfoHolder) ((ServerLoginNetworkHandlerAccessor) handler).getConnection();
return (ChannelInfoHolder) ((ServerCommonNetworkHandlerAccessor) handler).getConnection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.impl.networking.GlobalReceiverRegistry;
import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions;
import net.fabricmc.fabric.impl.networking.NetworkingImpl;
import net.fabricmc.fabric.impl.networking.payload.FabricPacketPayload;
import net.fabricmc.fabric.impl.networking.payload.PacketByteBufPayload;

public final class ServerNetworkingImpl {
Expand Down Expand Up @@ -64,12 +62,8 @@ public static Packet<ClientCommonPacketListener> createC2SPacket(FabricPacket pa
Objects.requireNonNull(packet, "Packet cannot be null");
Objects.requireNonNull(packet.getType(), "Packet#getType cannot return null");

if (NetworkingImpl.WRITE_FABRIC_PACKET_CALLING_THREAD) {
PacketByteBuf buf = PacketByteBufs.create();
packet.write(buf);
return createC2SPacket(packet.getType().getId(), buf);
}

return new CustomPayloadS2CPacket(new FabricPacketPayload(packet));
PacketByteBuf buf = PacketByteBufs.create();
packet.write(buf);
return createC2SPacket(packet.getType().getId(), buf);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.s2c.login.LoginQueryRequestPayload;
import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket;
import net.minecraft.network.packet.s2c.login.UnknownLoginQueryRequestPayload;
import net.minecraft.util.Identifier;

import net.fabricmc.fabric.impl.networking.payload.PacketByteBufLoginQueryRequestPayload;
import net.fabricmc.fabric.impl.networking.payload.PayloadHelper;

@Mixin(LoginQueryRequestS2CPacket.class)
public class LoginQueryRequestS2CPacketMixin {
@Inject(method = "readPayload", at = @At("HEAD"))
private static void readPayload(Identifier id, PacketByteBuf buf, CallbackInfoReturnable<UnknownLoginQueryRequestPayload> cir) {
throw new IllegalStateException("Must use LoginQueryRequestS2CPacketFactory");
@Inject(method = "readPayload", at = @At("HEAD"), cancellable = true)
private static void readPayload(Identifier id, PacketByteBuf buf, CallbackInfoReturnable<LoginQueryRequestPayload> cir) {
cir.setReturnValue(new PacketByteBufLoginQueryRequestPayload(id, PayloadHelper.read(buf)));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"EntityTrackerEntryMixin",
"LoginQueryRequestS2CPacketMixin",
"LoginQueryResponseC2SPacketMixin",
"NetworkStateInternalPacketHandlerMixin",
"PlayerManagerMixin",
"ServerCommonNetworkHandlerMixin",
"ServerConfigurationNetworkHandlerMixin",
Expand Down

0 comments on commit 4ecd34d

Please sign in to comment.