Search in sources :

Example 1 with Connection

use of net.minecraft.network.Connection in project MinecraftForge by MinecraftForge.

the class HandshakeHandler method handleRegistryLoading.

private boolean handleRegistryLoading(final Supplier<NetworkEvent.Context> contextSupplier) {
    // We use a countdown latch to suspend the impl thread pending the client thread processing the registry data
    AtomicBoolean successfulConnection = new AtomicBoolean(false);
    CountDownLatch block = new CountDownLatch(1);
    contextSupplier.get().enqueueWork(() -> {
        LOGGER.debug(FMLHSMARKER, "Injecting registry snapshot from server.");
        final Multimap<ResourceLocation, ResourceLocation> missingData = GameData.injectSnapshot(registrySnapshots, false, false);
        LOGGER.debug(FMLHSMARKER, "Snapshot injected.");
        if (!missingData.isEmpty()) {
            LOGGER.error(FMLHSMARKER, "Missing registry data for impl connection:\n{}", LogMessageAdapter.adapt(sb -> missingData.forEach((reg, entry) -> sb.append("\t").append(reg).append(": ").append(entry).append('\n'))));
        }
        successfulConnection.set(missingData.isEmpty());
        block.countDown();
    });
    LOGGER.debug(FMLHSMARKER, "Waiting for registries to load.");
    try {
        block.await();
    } catch (InterruptedException e) {
        Thread.interrupted();
    }
    if (successfulConnection.get()) {
        LOGGER.debug(FMLHSMARKER, "Registry load complete, continuing handshake.");
    } else {
        LOGGER.error(FMLHSMARKER, "Failed to load registry, closing connection.");
        this.manager.disconnect(new TextComponent("Failed to synchronize registry data from server, closing connection"));
    }
    return successfulConnection.get();
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) java.util(java.util) ForgeRegistry(net.minecraftforge.registries.ForgeRegistry) ServerLoginPacketListenerImpl(net.minecraft.server.network.ServerLoginPacketListenerImpl) ServerboundCustomQueryPacket(net.minecraft.network.protocol.login.ServerboundCustomQueryPacket) Connection(net.minecraft.network.Connection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Multimap(com.google.common.collect.Multimap) LogMessageAdapter(net.minecraftforge.common.util.LogMessageAdapter) REGISTRIES(net.minecraftforge.registries.ForgeRegistry.REGISTRIES) Maps(com.google.common.collect.Maps) Supplier(java.util.function.Supplier) CountDownLatch(java.util.concurrent.CountDownLatch) TextComponent(net.minecraft.network.chat.TextComponent) MarkerManager(org.apache.logging.log4j.MarkerManager) Logger(org.apache.logging.log4j.Logger) GameData(net.minecraftforge.registries.GameData) SimpleChannel(net.minecraftforge.network.simple.SimpleChannel) BiConsumer(java.util.function.BiConsumer) ClientIntentionPacket(net.minecraft.network.protocol.handshake.ClientIntentionPacket) LogManager(org.apache.logging.log4j.LogManager) Marker(org.apache.logging.log4j.Marker) IntSupplier(java.util.function.IntSupplier) ClientboundCustomQueryPacket(net.minecraft.network.protocol.login.ClientboundCustomQueryPacket) TextComponent(net.minecraft.network.chat.TextComponent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResourceLocation(net.minecraft.resources.ResourceLocation) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 java.util (java.util)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BiConsumer (java.util.function.BiConsumer)1 IntSupplier (java.util.function.IntSupplier)1 Supplier (java.util.function.Supplier)1 Connection (net.minecraft.network.Connection)1 TextComponent (net.minecraft.network.chat.TextComponent)1 ClientIntentionPacket (net.minecraft.network.protocol.handshake.ClientIntentionPacket)1 ClientboundCustomQueryPacket (net.minecraft.network.protocol.login.ClientboundCustomQueryPacket)1 ServerboundCustomQueryPacket (net.minecraft.network.protocol.login.ServerboundCustomQueryPacket)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 ServerLoginPacketListenerImpl (net.minecraft.server.network.ServerLoginPacketListenerImpl)1 LogMessageAdapter (net.minecraftforge.common.util.LogMessageAdapter)1 SimpleChannel (net.minecraftforge.network.simple.SimpleChannel)1 ForgeRegistry (net.minecraftforge.registries.ForgeRegistry)1 REGISTRIES (net.minecraftforge.registries.ForgeRegistry.REGISTRIES)1 GameData (net.minecraftforge.registries.GameData)1