Skip to content

[1.16.5] Add Entity Visibility API#5993

Closed
Janmm14 wants to merge 6 commits into
PaperMC:ver/1.16.5from
Janmm14:ver-1.16.5-feature-entity-visibility-api
Closed

[1.16.5] Add Entity Visibility API#5993
Janmm14 wants to merge 6 commits into
PaperMC:ver/1.16.5from
Janmm14:ver-1.16.5-feature-entity-visibility-api

Conversation

@Janmm14
Copy link
Copy Markdown

@Janmm14 Janmm14 commented Jun 24, 2021

Closes #5973

This PR adds Entity Visibility API by injecting itself into the tracker logic roughly similar to how things were done for showPlayer/hidePlayer by upstream.

When the new methods are called with a Player as argument, they redirect to the existing showPlayer/hidePlayer/canSee methods.

Some sound effects are not using Entity#playSound method.
I decided that changing that it out of scope for this PR/patch, a followup patch / PR can easily change that, playSound and sendPacketNearby methods are prepared.
Now in this PR/patch as well

Feedback appreciated

Edit: Once I tested this, I'll open another PR to also add the feature to 1.17
PR for 1.17: #6000

Copy link
Copy Markdown
Member

@JRoy JRoy left a comment

Choose a reason for hiding this comment

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

didn't look at server changes yet, just a few API things

+ * @param entity the entity to check
+ * @return True if this player can see the given entity
+ */
+ boolean canSee(@NotNull org.bukkit.entity.Entity entity);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will require explicit casts for people who want Player#canSee(Player). Should call this method canSeeEntity to avoid this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The implementation redirects

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

And no, this does not require explicit casts to call the method with the Player argument.

+ * Resets to which players this entity is shown and updates the default shown or hidden state
+ * @param shownByDefault True if entity should not be visible to players by default
+ */
+ void resetAndSetShownByDefault(boolean shownByDefault);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

holy fuck I hate this name, maybe don't bundle these operations?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The implementation only saves the players per entity which differ from the default state.
This combination saves us from iterating through all players to toggle their existence in the impl WeakHashSet (potentially twice).
I'd prefer to just change the name to something less ugly.

@Janmm14
Copy link
Copy Markdown
Author

Janmm14 commented Jun 25, 2021

Currently testing.
I've found some bugs in the code and I missed some places to check canSee. Update coming soon.

@Janmm14 Janmm14 marked this pull request as ready for review June 25, 2021 19:53
@Janmm14 Janmm14 requested review from a team as code owners June 25, 2021 19:53
@Janmm14 Janmm14 requested a review from JRoy June 25, 2021 19:54
@Janmm14
Copy link
Copy Markdown
Author

Janmm14 commented Jun 29, 2021

Must've accidentally forgotten to test after the latest changes I did

@Machine-Maker
Copy link
Copy Markdown
Member

I'm not sure if new API is going to be merged into 1.16.5. I see you've created a PR for 1.17 which is good. Once a new version is out, usually only bug fixes are backported, and even those only for a short while until the new version has been out for a couple months.

@Janmm14
Copy link
Copy Markdown
Author

Janmm14 commented Jul 12, 2021

bump

@stale
Copy link
Copy Markdown

stale Bot commented Sep 10, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@Janmm14
Copy link
Copy Markdown
Author

Janmm14 commented Sep 10, 2021

.

@stale stale Bot removed the resolution: stale label Sep 10, 2021
@stale
Copy link
Copy Markdown

stale Bot commented Nov 9, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@Proximyst
Copy link
Copy Markdown
Contributor

1.16.5 is EOL.

@Proximyst Proximyst closed this Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants