Skip to content

Commit

Permalink
Add access to ClientConfigurationNetworkHandler in context (#4097)
Browse files Browse the repository at this point in the history
(cherry picked from commit c7469b2)
  • Loading branch information
Earthcomputer authored and modmuss50 committed Sep 23, 2024
1 parent 6de299b commit d3cf6d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jetbrains.annotations.Nullable;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientConfigurationNetworkHandler;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;
import net.minecraft.util.thread.ThreadExecutor;
Expand Down Expand Up @@ -280,6 +281,11 @@ public interface Context {
*/
MinecraftClient client();

/**
* @return The ClientConfigurationNetworkHandler instance
*/
ClientConfigurationNetworkHandler networkHandler();

/**
* @return The packet sender
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class ClientConfigurationNetworkAddon extends ClientCommonNetworkAd

public ClientConfigurationNetworkAddon(ClientConfigurationNetworkHandler handler, MinecraftClient client) {
super(ClientNetworkingImpl.CONFIGURATION, ((ClientCommonNetworkHandlerAccessor) handler).getConnection(), "ClientPlayNetworkAddon for " + ((ClientConfigurationNetworkHandlerAccessor) handler).getProfile().getName(), handler, client);
this.context = new ContextImpl(client, this);
this.context = new ContextImpl(client, handler, this);

// Must register pending channels via lateinit
this.registerPendingChannels((ChannelInfoHolder) this.connection, NetworkPhase.CONFIGURATION);
Expand Down Expand Up @@ -128,9 +128,10 @@ public ChannelInfoHolder getChannelInfoHolder() {
return (ChannelInfoHolder) ((ClientCommonNetworkHandlerAccessor) handler).getConnection();
}

private record ContextImpl(MinecraftClient client, PacketSender responseSender) implements ClientConfigurationNetworking.Context {
private record ContextImpl(MinecraftClient client, ClientConfigurationNetworkHandler networkHandler, PacketSender responseSender) implements ClientConfigurationNetworking.Context {
private ContextImpl {
Objects.requireNonNull(client, "client");
Objects.requireNonNull(networkHandler, "networkHandler");
Objects.requireNonNull(responseSender, "responseSender");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public MinecraftClient client() {
return null;
}

@Override
public ClientConfigurationNetworkHandler networkHandler() {
return clientNetworkHandler;
}

@Override
public PacketSender responseSender() {
return packetSender;
Expand Down

0 comments on commit d3cf6d4

Please sign in to comment.