Move @EventBusSubscriber application to just after construction instead of pre-init.

This commit is contained in:
LexManos 2019-01-11 12:28:06 -08:00
parent 849bc00b46
commit 3765d912a5
2 changed files with 5 additions and 4 deletions

View file

@ -44,12 +44,13 @@ import static net.minecraftforge.fml.Logging.LOADING;
public class AutomaticEventSubscriber public class AutomaticEventSubscriber
{ {
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
private static final Type AUTO_SUBSCRIBER = Type.getType(Mod.EventBusSubscriber.class);
public static void inject(final ModContainer mod, final ModFileScanData scanData, final ClassLoader loader) public static void inject(final ModContainer mod, final ModFileScanData scanData, final ClassLoader loader)
{ {
if (scanData == null) return; if (scanData == null) return;
LOGGER.debug(LOADING,"Attempting to inject @EventBusSubscriber classes into the eventbus for {}", mod.getModId()); LOGGER.debug(LOADING,"Attempting to inject @EventBusSubscriber classes into the eventbus for {}", mod.getModId());
List<ModFileScanData.AnnotationData> ebsTargets = scanData.getAnnotations().stream(). List<ModFileScanData.AnnotationData> ebsTargets = scanData.getAnnotations().stream().
filter(annotationData -> Objects.equals(annotationData.getAnnotationType(), Type.getType(Mod.EventBusSubscriber.class))). filter(annotationData -> AUTO_SUBSCRIBER.equals(annotationData.getAnnotationType())).
collect(Collectors.toList()); collect(Collectors.toList());
ebsTargets.forEach(ad -> { ebsTargets.forEach(ad -> {

View file

@ -120,9 +120,6 @@ public class FMLModContainer extends ModContainer
private void preinitMod(LifecycleEventProvider.LifecycleEvent lifecycleEvent) private void preinitMod(LifecycleEventProvider.LifecycleEvent lifecycleEvent)
{ {
LOGGER.debug(LOADING, "Injecting Automatic event subscribers for {}", getModId());
AutomaticEventSubscriber.inject(this, this.scanResults, this.modClass.getClassLoader());
LOGGER.debug(LOADING, "Completed Automatic event subscribers for {}", getModId());
} }
private void constructMod(LifecycleEventProvider.LifecycleEvent event) private void constructMod(LifecycleEventProvider.LifecycleEvent event)
@ -138,6 +135,9 @@ public class FMLModContainer extends ModContainer
LOGGER.error(LOADING,"Failed to create mod instance. ModID: {}, class {}", getModId(), modClass.getName(), e); LOGGER.error(LOADING,"Failed to create mod instance. ModID: {}, class {}", getModId(), modClass.getName(), e);
throw new ModLoadingException(modInfo, event.fromStage(), "fml.modloading.failedtoloadmod", e, modClass); throw new ModLoadingException(modInfo, event.fromStage(), "fml.modloading.failedtoloadmod", e, modClass);
} }
LOGGER.debug(LOADING, "Injecting Automatic event subscribers for {}", getModId());
AutomaticEventSubscriber.inject(this, this.scanResults, this.modClass.getClassLoader());
LOGGER.debug(LOADING, "Completed Automatic event subscribers for {}", getModId());
} }
@Override @Override