diff --git a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/SimpleRegistryAccessor.java b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/SimpleRegistryAccessor.java new file mode 100644 index 0000000000..319657c181 --- /dev/null +++ b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/SimpleRegistryAccessor.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.mixin.registry.sync; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.registry.SimpleRegistry; + +@Mixin(SimpleRegistry.class) +public interface SimpleRegistryAccessor { + @Accessor + boolean isFrozen(); +} 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 7dbde1ddb2..26bea44ac4 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 @@ -48,6 +48,7 @@ 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; @@ -55,6 +56,7 @@ 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; @@ -66,6 +68,7 @@ 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 { @@ -74,6 +77,9 @@ public abstract class SimpleRegistryMixin implements MutableRegistry, Rema @Unique private static final Set VANILLA_NAMESPACES = Set.of("minecraft", "brigadier"); + @Unique + private static final Logger LOGGER = LoggerFactory.getLogger("FabricRegistrySync"); + @Shadow @Final private ObjectList> rawIdToEntry; @@ -381,9 +387,16 @@ public void unmap(String name) throws RemapException { } } - // Actually throw the exception when a duplicate is found. @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().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; } } diff --git a/fabric-registry-sync-v0/src/main/resources/fabric-registry-sync-v0.mixins.json b/fabric-registry-sync-v0/src/main/resources/fabric-registry-sync-v0.mixins.json index 4e7e0480f2..42b08f0ccd 100644 --- a/fabric-registry-sync-v0/src/main/resources/fabric-registry-sync-v0.mixins.json +++ b/fabric-registry-sync-v0/src/main/resources/fabric-registry-sync-v0.mixins.json @@ -15,6 +15,7 @@ "RegistryLoaderMixin", "SaveLoadingMixin", "SerializableRegistriesMixin", + "SimpleRegistryAccessor", "SimpleRegistryMixin" ], "injectors": {