forked from FabricMC/fabric
No longer allow unused registry ids when syncing. (#3792)
* No longer allow unused registry ids when syncing. * Freeze registries much sooner after mod init
This commit is contained in:
parent
6573ed8ccc
commit
b9828ba31a
5 changed files with 29 additions and 30 deletions
fabric-registry-sync-v0/src
client/java/net/fabricmc/fabric/mixin/registry/sync/client
main
java/net/fabricmc/fabric
resources
|
@ -17,9 +17,9 @@
|
|||
package net.fabricmc.fabric.mixin.registry.sync.client;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
@ -35,8 +35,9 @@ import net.fabricmc.fabric.impl.registry.sync.trackers.vanilla.BlockInitTracker;
|
|||
|
||||
@Mixin(MinecraftClient.class)
|
||||
public class MinecraftClientMixin {
|
||||
@Unique
|
||||
private static Logger FABRIC_LOGGER = LoggerFactory.getLogger(MinecraftClientMixin.class);
|
||||
@Shadow
|
||||
@Final
|
||||
private static Logger LOGGER;
|
||||
|
||||
// Unmap the registry before loading a new SP/MP setup.
|
||||
@Inject(at = @At("RETURN"), method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;Z)V")
|
||||
|
@ -44,14 +45,14 @@ public class MinecraftClientMixin {
|
|||
try {
|
||||
RegistrySyncManager.unmap();
|
||||
} catch (RemapException e) {
|
||||
FABRIC_LOGGER.warn("Failed to unmap Fabric registries!", e);
|
||||
LOGGER.warn("Failed to unmap Fabric registries!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;thread:Ljava/lang/Thread;", shift = At.Shift.AFTER, ordinal = 0), method = "run")
|
||||
private void onStart(CallbackInfo ci) {
|
||||
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/lang/Thread;currentThread()Ljava/lang/Thread;"))
|
||||
private void afterModInit(CallbackInfo ci) {
|
||||
// Freeze the registries on the client
|
||||
FABRIC_LOGGER.debug("Freezing registries");
|
||||
LOGGER.debug("Freezing registries");
|
||||
Registries.bootstrap();
|
||||
BlockInitTracker.postFreeze();
|
||||
ItemGroups.collect();
|
||||
|
|
|
@ -36,7 +36,6 @@ import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
|||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.VisibleForTesting;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -277,14 +276,10 @@ public final class RegistrySyncManager {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (registry instanceof RemappableRegistry) {
|
||||
Object2IntMap<Identifier> idMap = new Object2IntOpenHashMap<>();
|
||||
|
||||
for (Identifier key : registryMap.keySet()) {
|
||||
idMap.put(key, registryMap.getInt(key));
|
||||
}
|
||||
|
||||
((RemappableRegistry) registry).remap(registryId.toString(), idMap, mode);
|
||||
if (registry instanceof RemappableRegistry remappableRegistry) {
|
||||
remappableRegistry.remap(registryId.toString(), registryMap, mode);
|
||||
} else {
|
||||
throw new RemapException("Registry " + registryId + " is not remappable");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,31 +17,32 @@
|
|||
package net.fabricmc.fabric.mixin.registry.sync;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.Main;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.fabric.impl.registry.sync.trackers.vanilla.BlockInitTracker;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class MinecraftServerMixin {
|
||||
@Unique
|
||||
private static final Logger FABRIC_LOGGER = LoggerFactory.getLogger(MinecraftServerMixin.class);
|
||||
@Mixin(Main.class)
|
||||
public class MainMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private static Logger LOGGER;
|
||||
|
||||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;setupServer()Z"), method = "runServer")
|
||||
private void beforeSetupServer(CallbackInfo info) {
|
||||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Util;startTimerHack()V"), method = "main")
|
||||
private static void afterModInit(CallbackInfo info) {
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) {
|
||||
// Freeze the registries on the server
|
||||
FABRIC_LOGGER.debug("Freezing registries");
|
||||
LOGGER.debug("Freezing registries");
|
||||
|
||||
Registries.bootstrap();
|
||||
BlockInitTracker.postFreeze();
|
|
@ -299,8 +299,10 @@ public abstract class SimpleRegistryMixin<T> implements MutableRegistry<T>, Rema
|
|||
for (int i = 0; i < rawIdToEntry.size(); i++) {
|
||||
RegistryEntry.Reference<T> reference = rawIdToEntry.get(i);
|
||||
|
||||
// Unused id, skip
|
||||
if (reference == null) continue;
|
||||
// Unused id, can happen if there are holes in the registry.
|
||||
if (reference == null) {
|
||||
throw new RemapException("Unused id " + i + " in registry " + getKey().getValue());
|
||||
}
|
||||
|
||||
Identifier id = reference.registryKey().getValue();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"DebugChunkGeneratorAccessor",
|
||||
"ExperimentalRegistriesValidatorMixin",
|
||||
"IdListMixin",
|
||||
"MinecraftServerMixin",
|
||||
"MainMixin",
|
||||
"RegistriesAccessor",
|
||||
"RegistriesMixin",
|
||||
"RegistryLoaderMixin",
|
||||
|
|
Loading…
Add table
Reference in a new issue