Allow duplicate entries after being frozen on the client in prod. ()

* Allow duplicate entries after being frozen on the client.

* Only apply work around to prod
This commit is contained in:
modmuss 2024-08-04 19:44:12 +01:00 committed by GitHub
parent eccb723f8b
commit 0a3a005780
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 1 deletions
fabric-registry-sync-v0/src/main

View file

@ -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();
}

View file

@ -48,6 +48,7 @@ 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;
@ -55,6 +56,7 @@ 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;
@ -66,6 +68,7 @@ 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<T> implements MutableRegistry<T>, RemappableRegistry, ListenableRegistry<T> {
@ -74,6 +77,9 @@ public abstract class SimpleRegistryMixin<T> implements MutableRegistry<T>, Rema
@Unique
private static final Set<String> VANILLA_NAMESPACES = Set.of("minecraft", "brigadier");
@Unique
private static final Logger LOGGER = LoggerFactory.getLogger("FabricRegistrySync");
@Shadow
@Final
private ObjectList<RegistryEntry.Reference<T>> rawIdToEntry;
@ -381,9 +387,17 @@ public abstract class SimpleRegistryMixin<T> implements MutableRegistry<T>, Rema
}
}
// 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 extends Throwable> 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;
}
}

View file

@ -15,6 +15,7 @@
"RegistryLoaderMixin",
"SaveLoadingMixin",
"SerializableRegistriesMixin",
"SimpleRegistryAccessor",
"SimpleRegistryMixin"
],
"injectors": {