mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 18:45:09 +00:00
Allow using DeferredRegisters for vanilla registries (#8527)
Catch and aggregate exceptions when applying object holders
This commit is contained in:
1 parent
8f0d3da1e4
commit
1f031ad2c3
13 files changed
+550
-142
No files matched your search
@@ -10,6 +10,7 @@ import com.mojang.serialization.Lifecycle;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.world.level.block.AirBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
@@ -55,6 +56,7 @@ import net.minecraftforge.common.util.LogMessageAdapter;
|
||||
import net.minecraftforge.common.world.ForgeWorldPreset;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.event.RegistryEvent.MissingMappings;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.IModStateTransition;
|
||||
import net.minecraftforge.fml.StartupMessageManager;
|
||||
@@ -372,12 +374,17 @@ public class GameData
|
||||
final ResourceLocation rl = event.getName();
|
||||
ForgeRegistry<?> fr = (ForgeRegistry<?>) event.getRegistry();
|
||||
fr.freeze();
|
||||
LOGGER.debug(REGISTRIES, "Applying holder lookups: {}", rl.toString());
|
||||
ObjectHolderRegistry.applyObjectHolders(rl::equals);
|
||||
LOGGER.debug(REGISTRIES, "Holder lookups applied: {}", rl.toString());
|
||||
applyHolderLookups(rl);
|
||||
}, executor).handle((v, t)->t != null ? Collections.singletonList(t): Collections.emptyList());
|
||||
}
|
||||
|
||||
private static void applyHolderLookups(ResourceLocation registryName)
|
||||
{
|
||||
LOGGER.debug(REGISTRIES, "Applying holder lookups: {}", registryName);
|
||||
ObjectHolderRegistry.applyObjectHolders(registryName::equals);
|
||||
LOGGER.debug(REGISTRIES, "Holder lookups applied: {}", registryName);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static CompletableFuture<List<Throwable>> checkForRevertToVanilla(final Executor executor, final CompletableFuture<List<Throwable>> listCompletableFuture) {
|
||||
return listCompletableFuture.whenCompleteAsync((errors, except) -> {
|
||||
@@ -386,11 +393,28 @@ public class GameData
|
||||
revertTo(RegistryManager.VANILLA, false);
|
||||
LOGGER.fatal("Detected errors during registry event dispatch, roll back to VANILLA complete");
|
||||
} else {
|
||||
RegistryManager.getVanillaRegistryKeys().forEach(registryName -> {
|
||||
Registry<?> registry = Registry.REGISTRY.get(registryName);
|
||||
if (registry == null)
|
||||
return;
|
||||
postVanillaRegisterEvent(registry);
|
||||
});
|
||||
BuiltinRegistries.REGISTRY.forEach(GameData::postVanillaRegisterEvent);
|
||||
net.minecraftforge.common.ForgeHooks.modifyAttributes();
|
||||
}
|
||||
}, executor);
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private static void postVanillaRegisterEvent(Registry<?> registry)
|
||||
{
|
||||
if (RegistryManager.ACTIVE.getRegistry(registry.key().location()) != null)
|
||||
return;
|
||||
|
||||
ModLoader.get().postEvent(new VanillaRegisterEvent(registry));
|
||||
applyHolderLookups(registry.key().location());
|
||||
}
|
||||
|
||||
//Lets us clear the map so we can rebuild it.
|
||||
private static class ClearableObjectIntIdentityMap<I> extends IdMapper<I>
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user