Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement auto bus detection in EBS #152

Closed
wants to merge 1 commit into from

Conversation

Matyrobbrt
Copy link
Member

Closes #140

@Matyrobbrt Matyrobbrt added the enhancement New feature or request label Jun 1, 2024
@neoforged-pr-publishing
Copy link

  • Publish PR to GitHub Packages

}
}

if (hasGame && hasMod) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I understand the idea, but why do we limit this to one bus per listener?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a "limitation" imposed by event bus' class, where all listeners must be of the correct marker interface. And given that game and mod events are fired during different parts of the runtime, I think the limitation makes sense

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oke perfect, was just curious. Thanks for the explanation. Nice work!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach does not provide meaningful separation (there is no reason that these must be separated at the class level, aside from the current EBS implementation), and unifying these events in the same class can readily be achieved via IEventBus#addListener.

Despite the explained "limitation", leaving a class level separation here does not fix #140's main expectations.

Moving further to change the EBS implementation would be better than an incomplete solution imo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no raw variant of addListener that would support that use case, and reflection based consumers on the neo side is not acceptable, both because of performance concerns and because it will make unregistering those listeners impossible. In any case, I've decided to not proceed with this PR further because more magic will increase confusion.

Instead, we should make the bus parameter required and the mod id default to first in the file (instead of all).

Comment on lines +179 to +181
.withModsToml(builder -> {
builder.unlicensedJavaMod().addMod("testmod", "1.0");
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a shorthand for the testmod mods toml .withTestmodModsToml()

Comment on lines +88 to +89
// Simulates NeoForge's game event bus
private final Supplier<IEventBus> gameBus = Suppliers.memoize(() -> BusBuilder.builder().build());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, you are putting this here because it's usually in the NeoForge jar?

@Technici4n Technici4n self-requested a review June 1, 2024 16:52
Copy link
Member

@Technici4n Technici4n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this. It doesn't make life easier for beginners because they still need to understand the difference between the two kinds of busses. And it doesn't really make life easier for more experienced developers because typing the kind of bus you want is already trivial. This just add another way of doing the same thing, which is generally a sign of incoherent design.

@Matyrobbrt Matyrobbrt closed this Jun 2, 2024
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.

Make EventBusSubscriber automatically look up and dispatch mod bus events as necessary
5 participants