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

Add AFTER_CLIENT_WORLD_CHANGE #4173

Merged
merged 5 commits into from
Nov 12, 2024

Conversation

fishshi
Copy link
Contributor

@fishshi fishshi commented Oct 18, 2024

Add an event for the current ClientWorld being updated.
Fixes #3714

@modmuss50 modmuss50 linked an issue Oct 18, 2024 that may be closed by this pull request
@modmuss50 modmuss50 added enhancement New feature or request accepted This issue is a good idea and a PR should be made small change labels Oct 18, 2024
@modmuss50 modmuss50 added last call If you care, make yourself heard right away! and removed accepted This issue is a good idea and a PR should be made labels Oct 23, 2024
Copy link
Contributor

@haykam821 haykam821 left a comment

Choose a reason for hiding this comment

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

Make sure to add a section to the module README that describes the ClientWorldEvents class.

/**
* An event which is called after the client world has been changed.
*/
public static final Event<AfterClientWorldChange> AFTER_CLIENT_WORLD_CHANGE = EventFactory.createArrayBacked(AfterClientWorldChange.class, callbacks -> (client, world) -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this event should be named 'load' to match the corresponding event in the ServerWorldEvents class. The parameters are even similar, being a server or client and the respectively-sided world. The main difference is that the world here can be null, which is represented by an unload event in the ServerWorldEvents class instead.

/**
* An event which is called after the client world has been changed.
*/
public static final Event<AfterClientWorldChange> AFTER_CLIENT_WORLD_CHANGE = EventFactory.createArrayBacked(AfterClientWorldChange.class, callbacks -> (client, world) -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this event should be called LOAD due to these two reasons:

  1. To be consistent with the ServerWorldEvents class.
  2. This event is also called on the initial world load, and it doesn't make sense to be called AFTER_CLIENT_WORLD_CHANGE.

Also, I assume this event only fires once on world change, not once null then once with the new world?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, I have completed the modifications.

Copy link
Member

Choose a reason for hiding this comment

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

I dont think load is correct at all, when joining a server, or switching a world you arent loading (from the disk) the world at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have reverted its name now.

Comment on lines +28 to +29
private ClientWorldEvents() {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is going to pass the checkstyle? The constructor should be between the field and the interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry, but I wrote it by imitating other classes within the same package. If there are any issues, could you provide more information?

Copy link
Contributor

Choose a reason for hiding this comment

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

Try running the check task (./gradlew check). Typically GitHub Actions would provide context as well, but a maintainer would need to approve the run first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your guidance. I received a BUILD SUCCESSFUL after running the check task.

@kevinthegreat1
Copy link
Contributor

Now that I think about this, what's the difference between this event and ClientPlayConnectionEvents.JOIN?

@Octol1ttle
Copy link
Contributor

Switching dimensions changes the ClientWorld

@fishshi fishshi force-pushed the feature/AFTER_CLIENT_WORLD_CHANGE branch from 9ab01ea to 4070a1d Compare October 27, 2024 08:59
@modmuss50 modmuss50 added the merge me please Pull requests that are ready to merge label Nov 12, 2024
@modmuss50 modmuss50 merged commit 01d9a51 into FabricMC:1.21.1 Nov 12, 2024
4 checks passed
modmuss50 pushed a commit that referenced this pull request Nov 12, 2024
* add AFTER_CLIENT_WORLD_CHANGE

* fix

* move

* add description to README and change class to final with a private constructor

* revert the event name
modmuss50 pushed a commit that referenced this pull request Nov 12, 2024
* add AFTER_CLIENT_WORLD_CHANGE

* fix

* move

* add description to README and change class to final with a private constructor

* revert the event name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request last call If you care, make yourself heard right away! merge me please Pull requests that are ready to merge small change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hooks for the current client world being changed
5 participants