net.minecraft.network.ClientConnection Java Examples

The following examples show how to use net.minecraft.network.ClientConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThrownEnderpearlEntity_fakePlayersMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method =  "onCollision", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/network/ClientConnection;isOpen()Z"
))
private boolean isConnectionGood(ClientConnection clientConnection)
{
    return clientConnection.isOpen() || getOwner() instanceof EntityPlayerMPFake;
}
 
Example #2
Source File: PlayerManager_fakePlayersMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "onPlayerConnect", at = @At(value = "NEW", target = "net/minecraft/server/network/ServerPlayNetworkHandler"))
private ServerPlayNetworkHandler replaceNetworkHandler(MinecraftServer server, ClientConnection clientConnection, ServerPlayerEntity playerIn)
{
    boolean isServerPlayerEntity = playerIn instanceof EntityPlayerMPFake;
    if (isServerPlayerEntity)
    {
        return new NetHandlerPlayServerFake(this.server, clientConnection, playerIn);
    }
    else
    {
        return new ServerPlayNetworkHandler(this.server, clientConnection, playerIn);
    }
}
 
Example #3
Source File: ConnectionHandler.java    From multiconnect with MIT License 5 votes vote down vote up
public static void onSendHandshake(ClientConnection connect, Packet<?> handshakePacket) {
    if (ConnectionMode.isSupportedProtocol(ConnectionInfo.protocolVersion)) {
        ((HandshakePacketAccessor) handshakePacket).setProtocolVersion(ConnectionInfo.protocolVersion);
        ConnectionInfo.protocol = ProtocolRegistry.get(ConnectionInfo.protocolVersion);
        ConnectionInfo.protocol.setup(false);
    }
}
 
Example #4
Source File: MixinConnectScreen.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "tick", at = @At("HEAD"))
private void onTick(CallbackInfo ci) {
    ClientConnection versionRequestConnection = this.versionRequestConnection.get();
    if (versionRequestConnection != null) {
        if (versionRequestConnection.isOpen())
            versionRequestConnection.tick();
        else
            versionRequestConnection.handleDisconnection();
    }
}
 
Example #5
Source File: SimpleChannel.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public <M> void sendTo(M message, ClientConnection connection, NetworkDirection direction) {
	connection.send(toVanillaPacket(message, direction));
}
 
Example #6
Source File: PlayerManager_coreMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Inject(method = "onPlayerConnect", at = @At("RETURN"))
private void onPlayerConnected(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci)
{
    CarpetServer.onPlayerLoggedIn(player);
    PLAYER_CONNECTS.onPlayerEvent(player);
}
 
Example #7
Source File: NetHandlerPlayServerFake.java    From fabric-carpet with MIT License 4 votes vote down vote up
public NetHandlerPlayServerFake(MinecraftServer server, ClientConnection cc, ServerPlayerEntity playerIn)
{
    super(server, cc, playerIn);
}
 
Example #8
Source File: MixinPlayerManager.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Inject(method = "onPlayerConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendWorldInfo(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/server/world/ServerWorld;)V"), cancellable = true)
public void tick(ClientConnection clientConnection_1, ServerPlayerEntity serverPlayerEntity_1, CallbackInfo info) {
    NetworkManager.sendTo(SandboxServer.INSTANCE.createAddonSyncPacket(), serverPlayerEntity_1);
}
 
Example #9
Source File: ConnectionScreen.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void connect(final String string_1, final int int_1) {
    Log.info("Connecting to {}, {}", string_1, int_1);
    Thread thread_1 = new Thread("Server Connector #" + CONNECTOR_THREADS_COUNT.incrementAndGet()) {
        public void run() {
            InetAddress inetAddress_1 = null;

            try {
                if (ConnectionScreen.this.connectingCancelled) {
                    return;
                }

                inetAddress_1 = InetAddress.getByName(string_1);
                ConnectionScreen.this.connection = ClientConnection.connect(inetAddress_1, int_1, ConnectionScreen.this.minecraft.options.shouldUseNativeTransport());
                ConnectionScreen.this.connection.setPacketListener(new ClientLoginNetworkHandler(ConnectionScreen.this.connection, ConnectionScreen.this.minecraft, ConnectionScreen.this.parent, ConnectionScreen.this::setStatus));
                ConnectionScreen.this.connection.send(new HandshakeC2SPacket(string_1, int_1, NetworkState.LOGIN));
                ConnectionScreen.this.connection.send(new LoginHelloC2SPacket(ConnectionScreen.this.minecraft.getSession().getProfile()));
            } catch (UnknownHostException var4) {
                if (ConnectionScreen.this.connectingCancelled) {
                    return;
                }

                Log.error("Couldn't connect to server", var4);
                ConnectionScreen.this.minecraft.execute(() -> {
                    ConnectionScreen.this.minecraft.openScreen(new DisconnectedScreen(ConnectionScreen.this.parent, "connect.failed", new TranslatableText("disconnect.genericReason", new Object[]{"Unknown host"})));
                });
            } catch (Exception var5) {
                if (ConnectionScreen.this.connectingCancelled) {
                    return;
                }

                Log.error("Couldn't connect to server", var5);
                String string_1x = inetAddress_1 == null ? var5.toString() : var5.toString().replaceAll(inetAddress_1 + ":" + int_1, "");
                ConnectionScreen.this.minecraft.execute(() -> {
                    ConnectionScreen.this.minecraft.openScreen(new DisconnectedScreen(ConnectionScreen.this.parent, "connect.failed", new TranslatableText("disconnect.genericReason", new Object[]{string_1x})));
                });
            }

        }
    };
    thread_1.setUncaughtExceptionHandler(new UncaughtExceptionLogger(Log.LOG));
    thread_1.start();
}
 
Example #10
Source File: MixinPlayerManager.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Inject(method = "onPlayerConnect", at = @At("RETURN"))
private void hookPlayerLogin(ClientConnection connection, ServerPlayerEntity player, CallbackInfo callback) {
	EntityEvents.onPlayerLoggedIn(player);
}
 
Example #11
Source File: MixinClientPlayNetworkHandler.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Shadow
public abstract ClientConnection getConnection();
 
Example #12
Source File: MixinClientLoginNetworkHandler.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Shadow
public abstract ClientConnection getConnection();
 
Example #13
Source File: MixinServerPlayNetworkHandler.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Shadow
public abstract ClientConnection getConnection();
 
Example #14
Source File: MixinServerLoginNetworkHandler.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Shadow
public abstract ClientConnection getConnection();
 
Example #15
Source File: PacketDistributor.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Consumer<Packet<?>> connectionList(final Supplier<List<ClientConnection>> connections) {
	return packet -> connections.get().forEach(connection -> connection.send(packet));
}
 
Example #16
Source File: ClientPlayNetworkHandlerMixin.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
@Shadow
@Override
public ClientConnection getConnection()
{
	return null;
}
 
Example #17
Source File: NetworkEvent.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ClientConnection getNetworkManager() {
	return clientConnection;
}
 
Example #18
Source File: NetworkEvent.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
Context(ClientConnection clientConnection, NetworkDirection networkDirection, PacketDispatcher dispatcher) {
	this.clientConnection = clientConnection;
	this.networkDirection = networkDirection;
	this.packetDispatcher = dispatcher;
}
 
Example #19
Source File: NetworkEvent.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
Context(ClientConnection connection, NetworkDirection networkDirection, int index) {
	this(connection, networkDirection, new PacketDispatcher.ClientConnectionDispatcher(connection, index, networkDirection.reply()));
}
 
Example #20
Source File: PacketDispatcher.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
ClientConnectionDispatcher(ClientConnection connection, int packetIndex, NetworkDirection direction) {
	super();
	this.connection = connection;
	this.packetIndex = packetIndex;
	this.direction = direction;
}
 
Example #21
Source File: MixinConnectScreen.java    From multiconnect with MIT License 4 votes vote down vote up
@Override
public void multiconnect_setVersionRequestConnection(ClientConnection connection) {
    versionRequestConnection.set(connection);
}
 
Example #22
Source File: MixinConnectScreen1.java    From multiconnect with MIT License 4 votes vote down vote up
@Redirect(method = "run()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/Packet;)V", ordinal = 0))
public void sendHandshake(ClientConnection connect, Packet<?> packet) {
    ConnectionHandler.onSendHandshake(connect, packet);
    connect.send(packet);
}
 
Example #23
Source File: GetProtocolPacketListener.java    From multiconnect with MIT License 4 votes vote down vote up
@Override
public ClientConnection getConnection() {
    return connection;
}
 
Example #24
Source File: GetProtocolPacketListener.java    From multiconnect with MIT License 4 votes vote down vote up
public GetProtocolPacketListener(ClientConnection connection) {
    this.connection = connection;
}
 
Example #25
Source File: NetworkHooks.java    From patchwork-api with GNU Lesser General Public License v2.1 3 votes vote down vote up
public static boolean onCustomPayload(final ICustomPacket<?> packet, final ClientConnection connection) {
	ListenableChannel target = NetworkRegistry.findListener(packet.getName());

	if (target == null) {
		return false;
	}

	final NetworkEvent.Context context = new NetworkEvent.Context(connection, packet.getDirection(), packet.getIndex());

	target.onPacket(packet, context);

	return context.getPacketHandled();
}
 
Example #26
Source File: IConnectScreen.java    From multiconnect with MIT License votes vote down vote up
void multiconnect_setVersionRequestConnection(ClientConnection connection);