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 <cpw+github@weeksfamily.ca>
This commit is contained in:
parent
74f9ef838a
commit
6ff6277efa
5 changed files with 47 additions and 18 deletions
|
@ -1,14 +1,15 @@
|
||||||
--- a/net/minecraft/util/registry/Bootstrap.java
|
--- a/net/minecraft/util/registry/Bootstrap.java
|
||||||
+++ b/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();
|
IDispenseItemBehavior.func_218401_c();
|
||||||
ArgumentTypes.func_197483_a();
|
ArgumentTypes.func_197483_a();
|
||||||
TagRegistryManager.func_242197_b();
|
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
|
+ if (false) // skip redirectOutputToLog, Forge already redirects stdout and stderr output to log so that they print with more context
|
||||||
func_179868_d();
|
func_179868_d();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,7 +104,6 @@
|
@@ -103,7 +105,6 @@
|
||||||
Commands.func_242986_b();
|
Commands.func_242986_b();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package net.minecraftforge.fml.loading;
|
package net.minecraftforge.fml.loading;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
@ -35,5 +36,13 @@ public class BackgroundWaiter {
|
||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
}
|
}
|
||||||
} while (!work.isDone());
|
} while (!work.isDone());
|
||||||
|
try {
|
||||||
|
runner.shutdown();
|
||||||
|
work.get();
|
||||||
|
} catch (ExecutionException ee) {
|
||||||
|
throw new RuntimeException(ee.getCause());
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,11 @@ public abstract class AbstractJarFileLocator implements IModLocator {
|
||||||
{
|
{
|
||||||
try (JarFile jf = new JarFile(file.toFile()))
|
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)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,7 +52,7 @@ public enum ModLoadingStage
|
||||||
VALIDATE(),
|
VALIDATE(),
|
||||||
CONSTRUCT(FMLConstructModEvent.class),
|
CONSTRUCT(FMLConstructModEvent.class),
|
||||||
CREATE_REGISTRIES(()->Stream.of(EventGenerator.fromFunction(RegistryEvent.NewRegistry::new))),
|
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),
|
COMMON_SETUP(FMLCommonSetupEvent.class),
|
||||||
SIDED_SETUP(DistExecutor.unsafeRunForDist(()->()->FMLClientSetupEvent.class, ()->()->FMLDedicatedServerSetupEvent.class)),
|
SIDED_SETUP(DistExecutor.unsafeRunForDist(()->()->FMLClientSetupEvent.class, ()->()->FMLDedicatedServerSetupEvent.class)),
|
||||||
ENQUEUE_IMC(InterModEnqueueEvent.class),
|
ENQUEUE_IMC(InterModEnqueueEvent.class),
|
||||||
|
@ -83,16 +83,16 @@ public enum ModLoadingStage
|
||||||
}
|
}
|
||||||
|
|
||||||
ModLoadingStage(Supplier<Stream<EventGenerator<?>>> eventStream) {
|
ModLoadingStage(Supplier<Stream<EventGenerator<?>>> 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")
|
|
||||||
<T extends Event & IModBusEvent> ModLoadingStage(Supplier<Stream<EventGenerator<?>>> eventStream, final BiFunction<Executor, ? extends EventGenerator<T>, CompletableFuture<List<Throwable>>> preDispatchHook, final BiFunction<Executor, ? extends EventGenerator<T>, CompletableFuture<List<Throwable>>> postDispatchHook) {
|
<T extends Event & IModBusEvent> ModLoadingStage(Supplier<Stream<EventGenerator<?>>> eventStream, final BiFunction<Executor, ? extends EventGenerator<T>, CompletableFuture<List<Throwable>>> preDispatchHook, final BiFunction<Executor, ? extends EventGenerator<T>, CompletableFuture<List<Throwable>>> postDispatchHook, final BiFunction<Executor, CompletableFuture<List<Throwable>>, CompletableFuture<List<Throwable>>> finalActivityGenerator) {
|
||||||
this.eventFunctionStream = eventStream;
|
this.eventFunctionStream = eventStream;
|
||||||
this.parallelEventClass = Optional.empty();
|
this.parallelEventClass = Optional.empty();
|
||||||
this.threadSelector = ThreadSelector.SYNC;
|
this.threadSelector = ThreadSelector.SYNC;
|
||||||
this.preDispatchHook = preDispatchHook;
|
this.preDispatchHook = preDispatchHook;
|
||||||
this.postDispatchHook = postDispatchHook;
|
this.postDispatchHook = postDispatchHook;
|
||||||
this.finalActivityGenerator = (e, prev) ->prev.thenApplyAsync(Function.identity(), e);
|
this.finalActivityGenerator = finalActivityGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModLoadingStage() {
|
ModLoadingStage() {
|
||||||
|
|
|
@ -296,29 +296,34 @@ public class GameData
|
||||||
LOGGER.debug(REGISTRIES, "All registries frozen");
|
LOGGER.debug(REGISTRIES, "All registries frozen");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void revertToFrozen() {
|
||||||
|
revertTo(RegistryManager.FROZEN, true);
|
||||||
|
}
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@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;
|
return;
|
||||||
}
|
}
|
||||||
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.resetDelegates());
|
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<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
|
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
|
||||||
{
|
{
|
||||||
final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(r.getKey());
|
final Class<? extends IForgeRegistryEntry> 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());
|
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.bake());
|
||||||
// the id mapping has reverted, fire remap events for those that care about id changes
|
// 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
|
// 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" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
@ -365,7 +370,16 @@ public class GameData
|
||||||
LOGGER.debug(REGISTRIES, "Applying holder lookups: {}", rl.toString());
|
LOGGER.debug(REGISTRIES, "Applying holder lookups: {}", rl.toString());
|
||||||
ObjectHolderRegistry.applyObjectHolders(rl::equals);
|
ObjectHolderRegistry.applyObjectHolders(rl::equals);
|
||||||
LOGGER.debug(REGISTRIES, "Holder lookups applied: {}", rl.toString());
|
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<List<Throwable>> checkForRevertToVanilla(final Executor executor, final CompletableFuture<List<Throwable>> listCompletableFuture) {
|
||||||
|
return listCompletableFuture.thenApplyAsync(errors -> {
|
||||||
|
if (!errors.isEmpty()) {
|
||||||
|
revertTo(RegistryManager.VANILLA, false);
|
||||||
|
}
|
||||||
|
return errors;
|
||||||
|
}, executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setCustomTagTypesFromRegistries()
|
public static void setCustomTagTypesFromRegistries()
|
||||||
|
@ -550,7 +564,8 @@ public class GameData
|
||||||
@Override
|
@Override
|
||||||
public void onValidate(IForgeRegistryInternal<Attribute> owner, RegistryManager stage, int id, ResourceLocation key, Attribute obj)
|
public void onValidate(IForgeRegistryInternal<Attribute> 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_();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue