Skip to content

Commit

Permalink
Ugly workaround for neoforged/FancyModLoader#110
Browse files Browse the repository at this point in the history
Changed finalization logic for all loaders for consistent behaviour.

Will look into a better alternative later
  • Loading branch information
Elec332 committed Apr 16, 2024
1 parent 937adf0 commit 50320b5
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum AnnotationDataHandler {

AnnotationDataHandler() {
asmLoaderMap = Maps.newHashMap();
validStates = ImmutableList.copyOf(ModLoadingStage.values());
validStates = ImmutableList.copyOf(EnumSet.complementOf(EnumSet.of(ModLoadingStage.PRE_CONSTRUCT)));
sideOnlyCache = Maps.newHashMap();
}

Expand Down Expand Up @@ -314,18 +314,7 @@ void preProcess() {
void process(ModLoadingStage state) {
if (validStates.contains(state)) {
Multimap<IModContainer, IAnnotationDataProcessor> dataProcessors = asmLoaderMap.get(state);
dataProcessors.forEach((mc, dataProcessor) -> {
Runnable exec = () -> dataProcessor.processASMData(asmDataHelper, state);;
if (state != ModLoadingStage.PRE_CONSTRUCT) {
IModLoaderEventHandler.INSTANCE.enqueueDeferredWork(state, mc, exec);
} else {
try {
exec.run();
} catch (Throwable e) {
throw new RuntimeException("Failed to do pre-construct annotation processing work for mod: " + mc.getModId(), e);
}
}
});
dataProcessors.forEach((mc, dataProcessor) -> IModLoaderEventHandler.INSTANCE.enqueueDeferredWork(state, mc, () -> dataProcessor.processASMData(asmDataHelper, state)));
asmLoaderMap.remove(state);
} else {
throw new IllegalArgumentException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public MappingType getMappingTarget() {
@Nullable
@Override
public IModContainer getModContainer(String id) {
if (!LoaderInitializer.INSTANCE.completedModList()) {
throw new IllegalStateException();
}
return realModLoader.getModContainer(id);
}

Expand All @@ -98,6 +101,9 @@ public IModContainer getModContainer(String id) {

@Override
public Set<IModContainer> getMods() {
if (!LoaderInitializer.INSTANCE.completedModList()) {
throw new IllegalStateException();
}
return realModLoader.getMods();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ private void onEventFailed(IEventBus iEventBus, Event event, EventListener[] iEv
}

private void constructMod() {
if (!LoaderInitializer.INSTANCE.completedModList()) {
throw new IllegalStateException("ModList hasn't been finalized before instantiation!");
synchronized (ElecModContainer.class) {
if (!LoaderInitializer.INSTANCE.completedModList()) {
LoaderInitializer.INSTANCE.finalizeLoading();
}
}
try {
LOGGER.trace(LOADING, "Loading mod instance {} of type {}", getModId(), modClass.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public void finalizeLoading() {
getModLoader().finalizeLoading();
AnnotationDataHandler.INSTANCE.preProcess();
finalized = true;
AnnotationDataHandler.INSTANCE.process(ModLoadingStage.PRE_CONSTRUCT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public final class FabricModStages {

public static void discover() {
ElecModLoader.getModLoader().useDiscoveredMods((meta, type) -> new ElecModContainer(meta, type.getClassName(), Class::forName, (e, c) -> new RuntimeException("Failed to " + e.getKey() + " mod " + meta.getModId(), e.getValue())));
LoaderInitializer.INSTANCE.finalizeLoading();
IModLoaderEventHandler.INSTANCE.postModEvent(ConstructModEvent::new);
processQueue(ModLoadingStage.CONSTRUCT);
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 50320b5

Please sign in to comment.