Search in sources :

Example 1 with ForgeEventBridge_Forge

use of org.spongepowered.forge.launch.bridge.event.ForgeEventBridge_Forge in project SpongeCommon by SpongePowered.

the class ForgeEventManager method post.

@Override
public boolean post(final Event event, final IEventBusInvokeDispatcher wrapper) {
    if (event instanceof ForgeEventBridge_Forge) {
        // intercept!
        final ForgeEventBridge_Forge forgeEvent = (ForgeEventBridge_Forge) event;
        final org.spongepowered.api.event.@Nullable Event spongeEvent = forgeEvent.bridge$createSpongeEvent();
        if (spongeEvent != null) {
            return this.postDualBus(spongeEvent, Collections.singleton(event), wrapper);
        }
    }
    // Do as Forge does - SpongeVanilla has no role to play here.
    return this.wrappedEventBus.post(event, wrapper);
}
Also used : ForgeEventBridge_Forge(org.spongepowered.forge.launch.bridge.event.ForgeEventBridge_Forge) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 2 with ForgeEventBridge_Forge

use of org.spongepowered.forge.launch.bridge.event.ForgeEventBridge_Forge in project SpongeCommon by SpongePowered.

the class ForgeEventManager method postDualBus.

// Implementation
private boolean postDualBus(final org.spongepowered.api.event.Event spongeEvent, final Collection<? extends Event> forgeEvents, final IEventBusInvokeDispatcher dispatcher) {
    try (final NoExceptionClosable ignored = this.preparePost(spongeEvent)) {
        final RegisteredListener.Cache listeners = this.getHandlerCache(spongeEvent);
        final List<RegisteredListener<?>> beforeModifications = listeners.beforeModifications();
        if (!beforeModifications.isEmpty()) {
            // First, we fire the Sponge beforeModifications on the Sponge event
            this.post(spongeEvent, beforeModifications);
            // Then we sync to the Forge events
            for (final Event forgeEvent : forgeEvents) {
                ((ForgeEventBridge_Forge) forgeEvent).bridge$syncFrom(spongeEvent);
            }
        }
        // Then, we fire all our Forge events
        for (final Event forgeEvent : forgeEvents) {
            this.wrappedEventBus.post(forgeEvent, dispatcher);
            // We must sync back the event's changes, if there are any.
            // For complex events, this will be a partial sync.
            ((ForgeEventBridge_Forge) forgeEvent).bridge$syncTo(spongeEvent);
        }
        // and now we do our standard event listener stuff.
        return this.post(spongeEvent, listeners.afterModifications());
    }
}
Also used : Event(net.minecraftforge.eventbus.api.Event) GenericEvent(net.minecraftforge.eventbus.api.GenericEvent) RegisteredListener(org.spongepowered.common.event.manager.RegisteredListener) ForgeEventBridge_Forge(org.spongepowered.forge.launch.bridge.event.ForgeEventBridge_Forge)

Aggregations

ForgeEventBridge_Forge (org.spongepowered.forge.launch.bridge.event.ForgeEventBridge_Forge)2 Event (net.minecraftforge.eventbus.api.Event)1 GenericEvent (net.minecraftforge.eventbus.api.GenericEvent)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 RegisteredListener (org.spongepowered.common.event.manager.RegisteredListener)1