From 60c3209bf5016e32ef0564317dcff86d7f1e156e Mon Sep 17 00:00:00 2001 From: modmuss Date: Mon, 5 Aug 2024 10:51:31 +0100 Subject: [PATCH] Revert registry sync changes. Allowing duplicate entries and vanilla clients on servers with modded registries. (#3999) * Revert "Prevent vanilla clients from joining servers that require modded registry entries. (#3992)" This reverts commit 8759e7555a93fb6f3bdcebc0e788eff194289098. * Revert "Throw the exception when a duplicate registry entry is found. (#3991)" * Keep javadoc fix --- .../ServerConfigurationNetworkAddon.java | 19 --------------- .../registry/sync/RegistrySyncManager.java | 24 +++++-------------- .../registry/sync/SimpleRegistryMixin.java | 18 -------------- 3 files changed, 6 insertions(+), 55 deletions(-) diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerConfigurationNetworkAddon.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerConfigurationNetworkAddon.java index e3179cba0..c70e7dbdc 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerConfigurationNetworkAddon.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerConfigurationNetworkAddon.java @@ -20,11 +20,8 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -import org.jetbrains.annotations.Nullable; - import net.minecraft.network.NetworkPhase; import net.minecraft.network.PacketCallbacks; -import net.minecraft.network.packet.BrandCustomPayload; import net.minecraft.network.packet.CustomPayload; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.s2c.common.CommonPingS2CPacket; @@ -47,8 +44,6 @@ public final class ServerConfigurationNetworkAddon extends AbstractChanneledNetw private final MinecraftServer server; private final ServerConfigurationNetworking.Context context; private RegisterState registerState = RegisterState.NOT_SENT; - @Nullable - private String clientBrand = null; public ServerConfigurationNetworkAddon(ServerConfigurationNetworkHandler handler, MinecraftServer server) { super(ServerNetworkingImpl.CONFIGURATION, ((ServerCommonNetworkHandlerAccessor) handler).getConnection(), "ServerConfigurationNetworkAddon for " + handler.getDebugProfile().getName()); @@ -60,16 +55,6 @@ public final class ServerConfigurationNetworkAddon extends AbstractChanneledNetw this.registerPendingChannels((ChannelInfoHolder) this.connection, NetworkPhase.CONFIGURATION); } - @Override - public boolean handle(CustomPayload payload) { - if (payload instanceof BrandCustomPayload brandCustomPayload) { - clientBrand = brandCustomPayload.brand(); - return false; - } - - return super.handle(payload); - } - @Override protected void invokeInitEvent() { } @@ -184,10 +169,6 @@ public final class ServerConfigurationNetworkAddon extends AbstractChanneledNetw handler.send(packet, callback); } - public @Nullable String getClientBrand() { - return clientBrand; - } - private enum RegisterState { NOT_SENT, SENT, diff --git a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/RegistrySyncManager.java b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/RegistrySyncManager.java index 37f8e964a..345cb71ce 100644 --- a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/RegistrySyncManager.java +++ b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/RegistrySyncManager.java @@ -58,7 +58,6 @@ import net.minecraft.util.thread.ThreadExecutor; import net.fabricmc.fabric.api.event.registry.RegistryAttribute; import net.fabricmc.fabric.api.event.registry.RegistryAttributeHolder; import net.fabricmc.fabric.api.networking.v1.ServerConfigurationNetworking; -import net.fabricmc.fabric.impl.networking.server.ServerNetworkingImpl; import net.fabricmc.fabric.impl.registry.sync.packet.DirectRegistryPacketHandler; import net.fabricmc.fabric.impl.registry.sync.packet.RegistryPacketHandler; @@ -66,14 +65,9 @@ public final class RegistrySyncManager { public static final boolean DEBUG = Boolean.getBoolean("fabric.registry.debug"); public static final DirectRegistryPacketHandler DIRECT_PACKET_HANDLER = new DirectRegistryPacketHandler(); + private static final Logger LOGGER = LoggerFactory.getLogger("FabricRegistrySync"); private static final boolean DEBUG_WRITE_REGISTRY_DATA = Boolean.getBoolean("fabric.registry.debug.writeContentsAsCsv"); - private static final Text INCOMPATIBLE_FABRIC_CLIENT_TEXT = Text.literal("This server requires ").append(Text.literal("Fabric API").formatted(Formatting.GREEN)) - .append(" installed on your client!").formatted(Formatting.YELLOW) - .append(Text.literal("\nContact server's administrator for more information!").formatted(Formatting.GOLD)); - private static final Text INCOMPATIBLE_VANILLA_CLIENT_TEXT = Text.literal("This server requires ").append(Text.literal("Fabric Loader and Fabric API").formatted(Formatting.GREEN)) - .append(" installed on your client!").formatted(Formatting.YELLOW) - .append(Text.literal("\nContact server's administrator for more information!").formatted(Formatting.GOLD)); //Set to true after vanilla's bootstrap has completed public static boolean postBootstrap = false; @@ -86,6 +80,11 @@ public final class RegistrySyncManager { return; } + if (!ServerConfigurationNetworking.canSend(handler, DIRECT_PACKET_HANDLER.getPacketId())) { + // Don't send if the client cannot receive + return; + } + final Map> map = RegistrySyncManager.createAndPopulateRegistryMap(); if (map == null) { @@ -93,17 +92,6 @@ public final class RegistrySyncManager { return; } - if (!ServerConfigurationNetworking.canSend(handler, DIRECT_PACKET_HANDLER.getPacketId())) { - // Disconnect incompatible clients - Text message = switch (ServerNetworkingImpl.getAddon(handler).getClientBrand()) { - case "fabric" -> INCOMPATIBLE_FABRIC_CLIENT_TEXT; - case null, default -> INCOMPATIBLE_VANILLA_CLIENT_TEXT; - }; - - handler.disconnect(message); - return; - } - handler.addTask(new SyncConfigurationTask(handler, map)); } diff --git a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/SimpleRegistryMixin.java b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/SimpleRegistryMixin.java index 68665992d..0d59e39b8 100644 --- a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/SimpleRegistryMixin.java +++ b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/SimpleRegistryMixin.java @@ -25,7 +25,6 @@ import java.util.Set; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; -import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.mojang.serialization.Lifecycle; import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; @@ -48,7 +47,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.minecraft.registry.MutableRegistry; -import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.SimpleRegistry; @@ -56,7 +54,6 @@ import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.entry.RegistryEntryInfo; import net.minecraft.util.Identifier; -import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; import net.fabricmc.fabric.api.event.registry.RegistryAttribute; @@ -68,7 +65,6 @@ import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager; import net.fabricmc.fabric.impl.registry.sync.RemapException; import net.fabricmc.fabric.impl.registry.sync.RemapStateImpl; import net.fabricmc.fabric.impl.registry.sync.RemappableRegistry; -import net.fabricmc.loader.api.FabricLoader; @Mixin(SimpleRegistry.class) public abstract class SimpleRegistryMixin implements MutableRegistry, RemappableRegistry, ListenableRegistry { @@ -386,18 +382,4 @@ public abstract class SimpleRegistryMixin implements MutableRegistry, Rema fabric_prevEntries = null; } } - - @ModifyExpressionValue(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Util;throwOrPause(Ljava/lang/Throwable;)Ljava/lang/Throwable;")) - private E throwOnDuplicate(E t) throws E { - // I hate this as much as you do, blame Hypixel for sending duplicate entries to the client via dynamic registries. - if (!FabricLoader.getInstance().isDevelopmentEnvironment() - && FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT - && ((SimpleRegistryAccessor) Registries.REGISTRIES).isFrozen()) { - LOGGER.error("Exception caught when adding entry to registry. This is likely a server or mod issue.", t); - return t; - } - - // Actually throw the exception when a duplicate is found, before the registries are frozen - throw t; - } }