Java 类net.minecraftforge.fml.common.event.FMLStateEvent 实例源码

项目:FoodCraft-Reloaded    文件:LoaderManager.java   
public void addLoader(Class<?> loaderClass) {
    try {
        for (Method method : loaderClass.getMethods())
            for (Annotation annotation : method.getDeclaredAnnotations())
                if (annotation.annotationType().equals(Load.class))
                    if (method.getParameterCount() == 0 || (FMLStateEvent.class.isAssignableFrom(method.getParameterTypes()[0]) && method.getParameterTypes()[0].equals(((Load) annotation).value().getEvent().getClass()))) {
                        Collection<Method> methods = stateLoaderMap.getOrDefault(((Load) annotation).value(), new ArrayList<>());
                        if (!methods.contains(method))
                            methods.add(method);
                        stateLoaderMap.put(((Load) annotation).value(), methods);
                    }
        loaderInstanceMap.put(loaderClass, loaderClass.newInstance());
    } catch (Exception e) {
        FoodCraftReloaded.getLogger().warn("Un-able to register loader " + loaderClass.getName(), e);
    }
}
项目:morecommands    文件:PatchManager.java   
/**
 * Fires an {@link FMLStateEvent} and applies all patches associated with it
 * 
 * @param event the {@link FMLStateEvent}
 */
public <T extends FMLStateEvent> void fireStateEvent(T event) {
    synchronized (this.stateEventBasedPatches) {
        Iterator<StateEventBasedPatch> itr = this.stateEventBasedPatches.get(event.getClass()).iterator();

        while (itr.hasNext()) {
            StateEventBasedPatch patch = itr.next();
            if (!patch.needsToBeApplied(event)) continue;

            if (patch.printLogFor(event)) {
                if (!patch.applyStateEventPatch(event))
                    handleApplyFailure(patch);
                else
                    handlyApplySuccess(patch);
            }
            else patch.applyStateEventPatch(event);
        }
    }
}
项目:morecommands    文件:PatchServerCommandManager.java   
@Override
public <T extends FMLStateEvent> boolean applyStateEventPatch(T e) {
    FMLServerAboutToStartEvent event = (FMLServerAboutToStartEvent) e;
    Field commandManager = ReflectionHelper.getField(ObfuscatedField.MinecraftServer_commandManager);

    if (commandManager != null) {
        try {
            commandManager.set(event.getServer(), new ServerCommandManager(event.getServer(), event.getServer().getCommandManager()));

            PatchManager.instance().getGlobalAppliedPatches().setPatchSuccessfullyApplied(this.displayName, true);
            return true;
        }
        catch (Exception ex) {
            PatchManager.instance().getGlobalAppliedPatches().setPatchSuccessfullyApplied(this.displayName, false);
            return false;
        }
    }
    else {
        PatchManager.instance().getGlobalAppliedPatches().setPatchSuccessfullyApplied(this.displayName, false);
        return false;
    }
}
项目:morecommands    文件:PatchRenderGlobal.java   
@Override
public <T extends FMLStateEvent> boolean applyStateEventPatch(T event) {
    try {
        SimpleReloadableResourceManager resourceManager = (SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
        Field reloadListenerList = ReflectionHelper.getField(ObfuscatedField.SimpleReloadableResourceManager_reloadListeners);

        List<?> reloadListeners = (List<?>) reloadListenerList.get(resourceManager);
        reloadListeners.remove(Minecraft.getMinecraft().renderGlobal);

        Minecraft.getMinecraft().renderGlobal = new RenderGlobal(Minecraft.getMinecraft());
        resourceManager.registerReloadListener(Minecraft.getMinecraft().renderGlobal);

        PatchManager.instance().getGlobalAppliedPatches().setPatchSuccessfullyApplied(this.displayName, true);
        return true;
    }
    catch (Exception ex) {
        PatchManager.instance().getGlobalAppliedPatches().setPatchSuccessfullyApplied(this.displayName, false);
        return false;
    }
}
项目:morecommands    文件:PatchClientCommandManager.java   
@Override
public <T extends FMLStateEvent> boolean applyStateEventPatch(T event) {
    Field instance = ReflectionHelper.getField(ObfuscatedField.ClientCommandHandler_instance);
    Field modifiers = ReflectionHelper.getField(ObfuscatedField.Field_modifiers);

    try {
        modifiers.setInt(instance, instance.getModifiers() & ~Modifier.FINAL);
        instance.set(null, new ClientCommandManager((ClientCommandHandler) instance.get(null)));

        PatchManager.instance().getGlobalAppliedPatches().setPatchSuccessfullyApplied(this.displayName, true);
        return true;
    }
    catch (Exception ex)  {
        PatchManager.instance().getGlobalAppliedPatches().setPatchSuccessfullyApplied(this.displayName, false);
        return false;
    }
}
项目:CustomWorldGen    文件:LoadController.java   
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(activeContainer());
    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);
        }
    }
}
项目:InspiringWorld    文件:CommonProxy.java   
public void preInit(FMLPreInitializationEvent event) {
    CommonProxy.event = new WeakReference<FMLStateEvent>(event);

    IWTechConfig.preInit();
    IWTechCapablilties.preInit();
    IWTechItems.preInit();
    IWTechBlocks.preInit();
    IWTechCreativeTabs.preInit();
    IWTechEntities.preInit();
    IWTechTileEntities.preInit();
    IWTechWorldGenerators.preInit();
}
项目:morecommands    文件:PatchEntityPlayerMP.java   
@Override
public <T extends FMLStateEvent> boolean applyStateEventPatch(T e) {
    FMLServerAboutToStartEvent event = (FMLServerAboutToStartEvent) e;

    try {
        Constructor<PlayerList> ctor;

        if (event.getServer().isDedicatedServer())
            ctor = (Constructor<PlayerList>) (Constructor<?>) DedicatedPlayerList.class.getDeclaredConstructor(DedicatedServer.class);
        else
            ctor = (Constructor<PlayerList>) (Constructor<?>) IntegratedPlayerList.class.getDeclaredConstructor(IntegratedServer.class);

        ctor.setAccessible(true);

        if (event.getServer().isDedicatedServer())
            event.getServer().setPlayerList(ctor.newInstance((DedicatedServer) event.getServer()));
        else
            event.getServer().setPlayerList(ctor.newInstance((IntegratedServer) event.getServer()));

        PatchManager.instance().getGlobalAppliedPatches().setPatchSuccessfullyApplied(this.displayName, true);
        return true;
    }
    catch (Exception ex) {
        PatchManager.instance().getGlobalAppliedPatches().setPatchSuccessfullyApplied(this.displayName, false);
        return false;
    }
}
项目:morecommands    文件:PatchEntityPlayerSP.java   
@Override
public boolean applyStateEventPatch(FMLStateEvent event) {
    if (event instanceof FMLPostInitializationEvent)
        return applyPostInitPatches((FMLPostInitializationEvent) event);
    else if (event instanceof FMLServerAboutToStartEvent)
        return applyServerStartPatches((FMLServerAboutToStartEvent) event);
    else
        throw new IllegalArgumentException("Invalid Event");
}
项目:InspiringWorld    文件:ClientProxy.java   
public static <T extends FMLStateEvent> T event() {
    return CommonProxy.event();
}
项目:InspiringWorld    文件:CommonProxy.java   
public void init(FMLInitializationEvent event) {
    CommonProxy.event = new WeakReference<FMLStateEvent>(event);

    IWTechCrafting.init();
    IWTechGuiElements.init();
}
项目:InspiringWorld    文件:CommonProxy.java   
public void postInit(FMLPostInitializationEvent event) {
    CommonProxy.event = new WeakReference<FMLStateEvent>(event);
}
项目:InspiringWorld    文件:CommonProxy.java   
public static <T extends FMLStateEvent> T event() {
    @SuppressWarnings("unchecked")
    T result = (T) CommonProxy.event.get();
    return result;
}
项目:morecommands    文件:PatchEntityPlayerMP.java   
@Override
public Collection<Class<? extends FMLStateEvent>> stateEventClasses() {
    return Sets.<Class<? extends FMLStateEvent>>newHashSet(FMLServerAboutToStartEvent.class);
}
项目:morecommands    文件:PatchEntityPlayerMP.java   
@Override
public <T extends FMLStateEvent> boolean needsToBeApplied(T event) {
    return true;
}
项目:morecommands    文件:PatchEntityPlayerMP.java   
@Override
public <T extends FMLStateEvent> boolean printLogFor(T event) {
    return true;
}
项目:morecommands    文件:PatchServerCommandManager.java   
@Override
public <T extends FMLStateEvent> boolean needsToBeApplied(T event) {
    return true;
}
项目:morecommands    文件:PatchServerCommandManager.java   
@Override
public <T extends FMLStateEvent> boolean printLogFor(T event) {
    return true;
}
项目:morecommands    文件:PatchServerCommandManager.java   
@Override
public Collection<Class<? extends FMLStateEvent>> stateEventClasses() {
    return Sets.<Class<? extends FMLStateEvent>>newHashSet(FMLServerAboutToStartEvent.class);
}
项目:morecommands    文件:PatchRenderGlobal.java   
@Override
public Collection<Class<? extends FMLStateEvent>> stateEventClasses() {
    return Sets.<Class<? extends FMLStateEvent>>newHashSet(FMLInitializationEvent.class);
}
项目:morecommands    文件:PatchRenderGlobal.java   
@Override
public <T extends FMLStateEvent> boolean needsToBeApplied(T event) {
    return true;
}
项目:morecommands    文件:PatchRenderGlobal.java   
@Override
public <T extends FMLStateEvent> boolean printLogFor(T event) {
    return true;
}
项目:morecommands    文件:PatchClientCommandManager.java   
@Override
public Collection<Class<? extends FMLStateEvent>> stateEventClasses() {
    return Sets.<Class<? extends FMLStateEvent>>newHashSet(FMLPostInitializationEvent.class);
}
项目:morecommands    文件:PatchClientCommandManager.java   
@Override
public <T extends FMLStateEvent> boolean needsToBeApplied(T event) {
    return true;
}
项目:morecommands    文件:PatchClientCommandManager.java   
@Override
public <T extends FMLStateEvent> boolean printLogFor(T event) {
    return true;
}
项目:morecommands    文件:PatchEntityPlayerSP.java   
@Override
public <T extends FMLStateEvent> boolean needsToBeApplied(T event) {
    return event instanceof FMLServerAboutToStartEvent ? !((FMLServerAboutToStartEvent) event).getServer().isDedicatedServer() : true;
}
项目:morecommands    文件:PatchEntityPlayerSP.java   
@Override
public <T extends FMLStateEvent> boolean printLogFor(T event) {
    return !(event instanceof FMLPostInitializationEvent);
}
项目:morecommands    文件:PatchEntityPlayerSP.java   
@Override
public Collection<Class<? extends FMLStateEvent>> stateEventClasses() {
    return Sets.<Class<? extends FMLStateEvent>>newHashSet(FMLPostInitializationEvent.class, FMLServerAboutToStartEvent.class);
}
项目:morecommands    文件:CommonHandler.java   
public void onStateEvent(FMLStateEvent event) {
    PatchManager.instance().fireStateEvent(event);
}
项目:morecommands    文件:PatchManager.java   
/**
 * @return the {@link FMLStateEvent} subclasses for which the apply method if this patch should be invoked
 */
Collection<Class<? extends FMLStateEvent>> stateEventClasses();
项目:morecommands    文件:PatchManager.java   
/**
 * Invoked to apply the patch
 * 
 * @param event an event of one of the types of {@link #stateEventClasses()}
 * @return whether the patch could successfully be applied
 */
<T extends FMLStateEvent> boolean applyStateEventPatch(T event);
项目:morecommands    文件:PatchManager.java   
/**
 * Returns whether this patch needs to be applied.
 * 
 * @param event the {@link FMLStateEvent} which would be used to invoke the apply method
 * @return whether this patch needs to be applied.
 */
<T extends FMLStateEvent> boolean needsToBeApplied(T event);
项目:morecommands    文件:PatchManager.java   
/**
 * Returns whether the PatchManager should automatically print a log message
 * 
 * @param event the {@link FMLStateEvent} which would be used to invoke the apply method
 * @return whether to print a log message
 */
<T extends FMLStateEvent> boolean printLogFor(T event);