-
Notifications
You must be signed in to change notification settings - Fork 506
Create EventResult enum, an simpler alternative to InteractionResult #5129
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
base: 26.1
Are you sure you want to change the base?
Conversation
|
That's a really great change, thanks. Personally I'd love if this could be expanded to cover events currently using This is the approach I've been using for a long time in my own library, here is my |
|
Having more values than strictly necessary makes it all confusing. In fact this was precisely the problem back when InteractionResult was still an enum. What the boolean does should be obvious from the event name (e.g. |
|
I think Fuzzs means events that return a nullable Boolean, but I'm not sure if fabric api has those |
|
@Patbox @Technici4n Also Fabric callbacks are mostly used as lambdas so you usually don't even get to see the method name. |
|
I've also previously talked about standardizing return values for Fabric events ( This is an idea I originally got from Architectury Api, where it's also applied for all of their events. |
|
Here are a few examples for events where imo it's not intuitive how the Line 99 in a208210
Line 60 in a208210
Line 197 in a208210
<...> Also not a fan of how events that "pass through" vanilla values are handled, with some of them requiring fabric-api/fabric-loot-api-v3/src/main/java/net/fabricmc/fabric/api/loot/v3/LootTableEvents.java Line 128 in a208210
Line 85 in a208210
<...> |
|
And to anyone wondering how standardized event return values in the form of |
|
There is some merit in what you suggest but I remain skeptical of a one-size-fits-all approach. Even NeoForge moved away from |
|
I agree I dont think there a reason for having a generic |
|
A lot of events would end up with enums that would be 1:1 with this one if that was implemented, since the minimal {ALLOW, DENY, PASS} would work in most cases (like how InteractionResult was used before, even if slighly incorrectly). |
This pr creates an EventResult enum, which main usecase is to provide simple {ALLOW, DENY, PASS} options for events to use (both Fabric API and for other mods). Additionally migrate EntitySleepEvents from InteractionResult to EventResult as an example. Some events from interactions module might get the refactor in later pr (that module needs slightly more work).
Main reasoning with this change is that a lot of events don't need, use or implement full functionality of InteractionResults, which provides {SUCCESS, SUCCESS_SERVER, CONSUME, FAIL, PASS, TRY_WITH_EMPTY_HAND} values and additionally supports setting the resulting ItemStack. All of this functionality might be confusing, if event only really needs SUCCESS, PASS and FAIL (in which case the names aren't the best either).
Alternative to this would be to just use existing TriState enum, however I feel that it's names could be confusing in some contexts.