-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
EventBusSubscriber
to top-level and cleanup Bindings suppliers (…
…#118) * Move EventBusSubscriber to top-level and cleanup Bindings suppliers * Inline I18nParser into IBindingsProvider * Rename FORGE bus to GAME bus * Add EBS snippet in javadoc
- Loading branch information
1 parent
4b4447a
commit fa57788
Showing
9 changed files
with
113 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
loader/src/main/java/net/neoforged/fml/common/EventBusSubscriber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) Forge Development LLC and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.fml.common; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.ModContainer; | ||
|
||
// @formatter:off - spotless doesn't like @ | ||
/** | ||
* Annotate a class which will be subscribed to an Event Bus at mod construction time. Defaults to subscribing the current modid to the {@code NeoForge#EVENT_BUS} on both sides. | ||
* | ||
* <p>Annotated classes will be scanned for <b>static</b> methods that have the {@link SubscribeEvent} annotation. | ||
* For example: | ||
* | ||
* {@snippet : | ||
* @EventBusSubscriber | ||
* public class MyEventHandler { | ||
* @SubscribeEvent | ||
* private static void onSomeEvent(SomeEvent event) { | ||
* // SomeEvent handler here | ||
* } | ||
* | ||
* @SubscribeEvent | ||
* private static void onAnotherEvent(AnotherEvent event) { | ||
* // AnotherEvent handler here | ||
* } | ||
* } | ||
* } | ||
* | ||
* @see Bus | ||
*/ | ||
// @formatter:on | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface EventBusSubscriber { | ||
/** | ||
* Specify targets to load this event subscriber on. Can be used to avoid loading Client specific events on a dedicated server, for example. | ||
* | ||
* @return an array of Dist to load this event subscriber on | ||
*/ | ||
Dist[] value() default { Dist.CLIENT, Dist.DEDICATED_SERVER }; | ||
|
||
/** | ||
* Optional value, only necessary if this annotation is not on the same class that has a @Mod annotation. Needed to prevent early classloading of classes not owned by your mod. | ||
* | ||
* @return a modid | ||
*/ | ||
String modid() default ""; | ||
|
||
/** | ||
* Specify an alternative bus to listen to | ||
* | ||
* @return the bus you wish to listen to | ||
*/ | ||
Bus bus() default Bus.GAME; | ||
|
||
enum Bus { | ||
/** | ||
* The main NeoForge Event Bus, used after the game has started up. | ||
* | ||
* <p>See {@code NeoForge#EVENT_BUS}</p> | ||
*/ | ||
GAME, | ||
/** | ||
* The mod-specific Event bus, used during startup. | ||
* | ||
* @see ModContainer#getEventBus() | ||
*/ | ||
MOD, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters