-
Notifications
You must be signed in to change notification settings - Fork 500
Add ScreenEvents.Open
#4692
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: 1.21.6
Are you sure you want to change the base?
Add ScreenEvents.Open
#4692
Conversation
|
Id add this to the existing ScreenEvents class as |
|
Also I'd like to have something like an The current implementation follows the design established by other events, so that's why it's like that for now. |
ScreenOpeningCallbackScreenEvents$Open
modmuss50
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not sure about this, as the existing screen before/after init events provide a lot. As far as I can tell out of your use cases the only one that isnt possible now is Keeping the old screen, preventing the new screen from opening.
Id argue that this would be better done by stopping it at the source (e.g preventing the click) rarther than this late on.
|
|
||
| if (screen != newScreen) { | ||
| return screen; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had a similar pattern with canceling the chat events, where mods would not get notified of chat messages if a previous one had already cancled it. Is there a similar concern here? Does the event also fire again for the replaced screen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's how it is supposed to be here; first come first serve. That's how most Fabric events work that have a return value. After all there is no concept of receiving "cancelled" events (which is essentially what this is) like there is in NeoForge.
If you prefer we can wrap the newScreen parameter in a MutableObject, so the event is able to run for all listeners and those receive modifications done by others. I do think this is very niche though and do think the current implementation is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of our events have a canceled counterpart that are invoked when the main one has been cancled. Im not sure how useful that is here.
Will the event be fired again for the new screen or not? I think it would make sense to?
Is it worth deferring the call to remove until after the event? |
|
the more I think about this, the more it feels like two separate events. |
The idea is to have every screen that opens go through this, no matter where it opens from. Intercepting at the source is not always possible and far more complicated compared to how simple this callback and its implementation are. You are right for init though, it is possible to replace a new screen with that like vanilla does when opening the creative mode screen. This is not as clean though and has no way of preventing the original new screen from initializing which could be an issue. |
I think there should probably be an earlier (keep the old screen, prevent the new screen from open event) and then make this one a (replace the currently opening screen, where you can pass null to prevent it from opening) |
Im not sure that opening a screen from within init is really that bad, would a more specific event such as |
|
Something along the lines of So implementing that would require delaying the Regarding using init events; I do have a use case that doesn't really work for: https://github.com/Fuzss/deathfinder/blob/57acee09fa6c0933aebad44aa614463fe37b100e/1.21.5/Common/src/main/java/fuzs/deathfinder/client/handler/DeathScreenHandler.java#L37 |
|
I had an idea for actually deferring that removed call without copying vanilla code, but unfortunately it requires mass mixin. |
|
I do think the cleanest thing would be two events. I'll sketch it out and show what I think it would look like later |
This adds a simple callback that runs inside of
MinecraftClient::setScreen, allowing for the replacement of the new screen.This allows for a couple of things:
Implementation details:
The old screen has already been removed by calling
Screen#removed(), and the new screen will always be initialized viaScreen#init(MinecraftClient, int, int).I see no issue with that though, even when keeping the old screen.
This includes a test mod.