Search in sources :

Example 1 with FMLStateEvent

use of net.minecraftforge.fml.common.event.FMLStateEvent in project MinecraftForge by MinecraftForge.

the class LoadController method sendEventToModContainer.

private void sendEventToModContainer(FMLEvent stateEvent, ModContainer mc) {
    String modId = mc.getModId();
    Collection<String> requirements = Collections2.transform(mc.getRequirements(), new ArtifactVersionNameFunction());
    for (ArtifactVersion av : mc.getDependencies()) {
        if (av.getLabel() != null && requirements.contains(av.getLabel()) && modStates.containsEntry(av.getLabel(), ModState.ERRORED)) {
            FMLLog.log(modId, Level.ERROR, "Skipping event %s and marking errored mod %s since required dependency %s has errored", stateEvent.getEventType(), modId, av.getLabel());
            modStates.put(modId, ModState.ERRORED);
            return;
        }
    }
    activeContainer = mc;
    stateEvent.applyModContainer(mc);
    ThreadContext.put("mod", modId);
    FMLLog.log(modId, Level.TRACE, "Sending event %s to mod %s", stateEvent.getEventType(), modId);
    eventChannels.get(modId).post(stateEvent);
    FMLLog.log(modId, Level.TRACE, "Sent event %s to mod %s", stateEvent.getEventType(), modId);
    ThreadContext.remove("mod");
    activeContainer = null;
    if (stateEvent instanceof FMLStateEvent) {
        if (!errors.containsKey(modId)) {
            modStates.put(modId, ((FMLStateEvent) stateEvent).getModState());
        } else {
            modStates.put(modId, ModState.ERRORED);
        }
    }
}
Also used : ArtifactVersion(net.minecraftforge.fml.common.versioning.ArtifactVersion) FMLStateEvent(net.minecraftforge.fml.common.event.FMLStateEvent) ArtifactVersionNameFunction(net.minecraftforge.fml.common.functions.ArtifactVersionNameFunction)

Aggregations

FMLStateEvent (net.minecraftforge.fml.common.event.FMLStateEvent)1 ArtifactVersionNameFunction (net.minecraftforge.fml.common.functions.ArtifactVersionNameFunction)1 ArtifactVersion (net.minecraftforge.fml.common.versioning.ArtifactVersion)1