From 6ff6277efa0e50ba969f270ebe4214c2cbfca6c5 Mon Sep 17 00:00:00 2001 From: cpw Date: Sun, 18 Oct 2020 13:37:28 -0400 Subject: [PATCH] Rollback registries to vanilla state if something happens during loading, so subsequent activities can still run and not generate false reports.. Signed-off-by: cpw --- .../util/registry/Bootstrap.java.patch | 5 +-- .../fml/loading/BackgroundWaiter.java | 9 +++++ .../moddiscovery/AbstractJarFileLocator.java | 6 +++- .../minecraftforge/fml/ModLoadingStage.java | 10 +++--- .../minecraftforge/registries/GameData.java | 35 +++++++++++++------ 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/patches/minecraft/net/minecraft/util/registry/Bootstrap.java.patch b/patches/minecraft/net/minecraft/util/registry/Bootstrap.java.patch index aba583108..279d3f133 100644 --- a/patches/minecraft/net/minecraft/util/registry/Bootstrap.java.patch +++ b/patches/minecraft/net/minecraft/util/registry/Bootstrap.java.patch @@ -1,14 +1,15 @@ --- a/net/minecraft/util/registry/Bootstrap.java +++ b/net/minecraft/util/registry/Bootstrap.java -@@ -48,6 +48,7 @@ +@@ -48,6 +48,8 @@ IDispenseItemBehavior.func_218401_c(); ArgumentTypes.func_197483_a(); TagRegistryManager.func_242197_b(); ++ net.minecraftforge.registries.GameData.vanillaSnapshot(); + if (false) // skip redirectOutputToLog, Forge already redirects stdout and stderr output to log so that they print with more context func_179868_d(); } } -@@ -103,7 +104,6 @@ +@@ -103,7 +105,6 @@ Commands.func_242986_b(); } diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/BackgroundWaiter.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/BackgroundWaiter.java index 0aead4cd7..3d4fc9f62 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/BackgroundWaiter.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/BackgroundWaiter.java @@ -19,6 +19,7 @@ package net.minecraftforge.fml.loading; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -35,5 +36,13 @@ public class BackgroundWaiter { } catch (InterruptedException ignored) { } } while (!work.isDone()); + try { + runner.shutdown(); + work.get(); + } catch (ExecutionException ee) { + throw new RuntimeException(ee.getCause()); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } } diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileLocator.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileLocator.java index a850ad77c..223d34559 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileLocator.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileLocator.java @@ -84,7 +84,11 @@ public abstract class AbstractJarFileLocator implements IModLocator { { try (JarFile jf = new JarFile(file.toFile())) { - return Optional.ofNullable(jf.getManifest()); + final Manifest manifest = jf.getManifest(); + if (manifest != null) { +// injection of signing stuff here + } + return Optional.ofNullable(manifest); } catch (IOException e) { diff --git a/src/main/java/net/minecraftforge/fml/ModLoadingStage.java b/src/main/java/net/minecraftforge/fml/ModLoadingStage.java index 57c37a2c5..b8883e782 100644 --- a/src/main/java/net/minecraftforge/fml/ModLoadingStage.java +++ b/src/main/java/net/minecraftforge/fml/ModLoadingStage.java @@ -52,7 +52,7 @@ public enum ModLoadingStage VALIDATE(), CONSTRUCT(FMLConstructModEvent.class), CREATE_REGISTRIES(()->Stream.of(EventGenerator.fromFunction(RegistryEvent.NewRegistry::new))), - LOAD_REGISTRIES(GameData::generateRegistryEvents, GameData::preRegistryEventDispatch, GameData::postRegistryEventDispatch), + LOAD_REGISTRIES(GameData::generateRegistryEvents, GameData::preRegistryEventDispatch, GameData::postRegistryEventDispatch, GameData::checkForRevertToVanilla), COMMON_SETUP(FMLCommonSetupEvent.class), SIDED_SETUP(DistExecutor.unsafeRunForDist(()->()->FMLClientSetupEvent.class, ()->()->FMLDedicatedServerSetupEvent.class)), ENQUEUE_IMC(InterModEnqueueEvent.class), @@ -83,16 +83,16 @@ public enum ModLoadingStage } ModLoadingStage(Supplier>> eventStream) { - this(eventStream, (t,f)->CompletableFuture.completedFuture(Collections.emptyList()), (t,f)->CompletableFuture.completedFuture(Collections.emptyList())); + this(eventStream, (t,f)->CompletableFuture.completedFuture(Collections.emptyList()), (t,f)->CompletableFuture.completedFuture(Collections.emptyList()), (e, prev) ->prev.thenApplyAsync(Function.identity(), e)); } - @SuppressWarnings("unchecked") - ModLoadingStage(Supplier>> eventStream, final BiFunction, CompletableFuture>> preDispatchHook, final BiFunction, CompletableFuture>> postDispatchHook) { + + ModLoadingStage(Supplier>> eventStream, final BiFunction, CompletableFuture>> preDispatchHook, final BiFunction, CompletableFuture>> postDispatchHook, final BiFunction>, CompletableFuture>> finalActivityGenerator) { this.eventFunctionStream = eventStream; this.parallelEventClass = Optional.empty(); this.threadSelector = ThreadSelector.SYNC; this.preDispatchHook = preDispatchHook; this.postDispatchHook = postDispatchHook; - this.finalActivityGenerator = (e, prev) ->prev.thenApplyAsync(Function.identity(), e); + this.finalActivityGenerator = finalActivityGenerator; } ModLoadingStage() { diff --git a/src/main/java/net/minecraftforge/registries/GameData.java b/src/main/java/net/minecraftforge/registries/GameData.java index f80beb304..15cca680e 100644 --- a/src/main/java/net/minecraftforge/registries/GameData.java +++ b/src/main/java/net/minecraftforge/registries/GameData.java @@ -296,29 +296,34 @@ public class GameData LOGGER.debug(REGISTRIES, "All registries frozen"); } + public static void revertToFrozen() { + revertTo(RegistryManager.FROZEN, true); + } @SuppressWarnings({ "unchecked", "rawtypes" }) - public static void revertToFrozen() + public static void revertTo(final RegistryManager target, boolean fireEvents) { - if (RegistryManager.FROZEN.registries.isEmpty()) + if (target.registries.isEmpty()) { - LOGGER.warn(REGISTRIES, "Can't revert to frozen GameData state without freezing first."); + LOGGER.warn(REGISTRIES, "Can't revert to {} GameData state without a valid snapshot.", target.getName()); return; } RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.resetDelegates()); - LOGGER.debug(REGISTRIES, "Reverting to frozen data state."); + LOGGER.debug(REGISTRIES, "Reverting to {} data state.", target.getName()); for (Map.Entry>> r : RegistryManager.ACTIVE.registries.entrySet()) { final Class clazz = RegistryManager.ACTIVE.getSuperType(r.getKey()); - loadRegistry(r.getKey(), RegistryManager.FROZEN, RegistryManager.ACTIVE, clazz, true); + loadRegistry(r.getKey(), target, RegistryManager.ACTIVE, clazz, true); } RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.bake()); // the id mapping has reverted, fire remap events for those that care about id changes - fireRemapEvent(ImmutableMap.of(), true); + if (fireEvents) { + fireRemapEvent(ImmutableMap.of(), true); + ObjectHolderRegistry.applyObjectHolders(); + } - ObjectHolderRegistry.applyObjectHolders(); // the id mapping has reverted, ensure we sync up the object holders - LOGGER.debug(REGISTRIES, "Frozen state restored."); + LOGGER.debug(REGISTRIES, "{} state restored.", target.getName()); } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -365,7 +370,16 @@ public class GameData LOGGER.debug(REGISTRIES, "Applying holder lookups: {}", rl.toString()); ObjectHolderRegistry.applyObjectHolders(rl::equals); LOGGER.debug(REGISTRIES, "Holder lookups applied: {}", rl.toString()); - }, executor).thenApply(v->Collections.emptyList()); + }, executor).handle((v, t)->t != null ? Collections.singletonList(t): Collections.emptyList()); + } + + public static CompletableFuture> checkForRevertToVanilla(final Executor executor, final CompletableFuture> listCompletableFuture) { + return listCompletableFuture.thenApplyAsync(errors -> { + if (!errors.isEmpty()) { + revertTo(RegistryManager.VANILLA, false); + } + return errors; + }, executor); } public static void setCustomTagTypesFromRegistries() @@ -550,7 +564,8 @@ public class GameData @Override public void onValidate(IForgeRegistryInternal owner, RegistryManager stage, int id, ResourceLocation key, Attribute obj) { - GlobalEntityTypeAttributes.func_233834_a_(); + // some stuff hard patched in can cause this to derp if it's JUST vanilla, so skip + if (stage!=RegistryManager.VANILLA) GlobalEntityTypeAttributes.func_233834_a_(); } }