Skip to content

Add compile-time validation for effectively always cancelling listeners#112

Merged
PaintNinja merged 1 commit intoMinecraftForge:masterfrom
PaintNinja:7.0-comp-time-validation-for-effectively-always-cancelling-listeners
Apr 6, 2026
Merged

Add compile-time validation for effectively always cancelling listeners#112
PaintNinja merged 1 commit intoMinecraftForge:masterfrom
PaintNinja:7.0-comp-time-validation-for-effectively-always-cancelling-listeners

Conversation

@PaintNinja
Copy link
Copy Markdown
Contributor

Suggests changing code that always returns true inside a possibly cancelling listener into a void return always cancelling listener, as the latter allows EventBus to know at listener registration time and can perform additional optimisations based on that knowledge.

Closes #110.

For example:

// Before
@SubscribeEvent
static boolean alwaysCancellingListener(ExampleCancellableEvent event) {
    return true;
}

// After suggested change:
@SubscribeEvent(alwaysCancelling = true)
static void alwaysCancellingListener(ExampleCancellableEvent event) {}

Suggests changing code that always returns true inside a possibly cancelling listener into a void return always cancelling listener, as the latter allows EventBus to know at listener registration time and can perform additional optimisations based on that knowledge.
@PaintNinja PaintNinja added the enhancement New feature or request label Apr 6, 2026
@PaintNinja PaintNinja merged commit 31b323b into MinecraftForge:master Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add compile-time validation for effectively always cancelling listeners

2 participants