Skip to content

feat: Support nameTagVisibility option of teams #373

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

Merged
merged 8 commits into from
Jul 3, 2025

Conversation

Phoenix616
Copy link

@Phoenix616 Phoenix616 commented Jun 18, 2025

This adds support for the nameTagVisibility option which teams have to hide the names of players in certain situations.

Summary by CodeRabbit

  • New Features

    • Name tags for player entities are now explicitly managed and displayed based on team visibility settings.
    • Player name tags update dynamically when team membership changes.
    • Player team affiliation is now tracked and reflected in entity displays and player state.
  • Bug Fixes

    • Ensured name tag visibility is always updated, preventing outdated or incorrect display when teams change.

Copy link

codesandbox bot commented Jun 18, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

coderabbitai bot commented Jun 18, 2025

Walkthrough

The changes introduce explicit management of player name tag visibility based on team settings. A new method handles name tag visibility updates according to team rules, and event listeners ensure player entities are refreshed when team membership changes occur. The code now responds to team-related events to keep name tag displays accurate. Additionally, player state tracking and entity event emissions were extended to include team affiliation data.

Changes

Files / Areas Change Summary
renderer/viewer/three/entities.ts Added explicit naming for player name tag mesh; introduced updateNameTagVisibility method to control name tag visibility based on team settings; updated entity update logic to always call this method.
src/entities.ts Added event listeners for team updates and member changes; introduced helper functions to refresh player entities when team membership changes.
renderer/viewer/lib/basePlayerState.ts Extended player state with a new team property typed as `Team
renderer/viewer/lib/worldDataEmitter.ts Added team property to emitted entity data, sourced from bot's teamMap.
src/mineflayer/playerState.ts Added event listener on 'gameLoaded' to update reactive player state team from bot's team map.

Sequence Diagram(s)

sequenceDiagram
    participant Bot
    participant Entities
    participant PlayerEntity

    Bot->>Entities: teamUpdated / teamMemberAdded / teamMemberRemoved event
    Entities->>Entities: updateAllEntitiesInTeams(team)
    loop For each PlayerEntity in team
        Entities->>Entities: emit entityUpdate(PlayerEntity)
        Entities->>PlayerEntity: updateNameTagVisibility()
        PlayerEntity->>PlayerEntity: Set name tag visibility based on team rules
    end
Loading

Suggested labels

Review effort 4/5

Poem

In the warren of code, a name tag appears,
Hopping with teams, it now reappears.
When teammates arrive or quietly go,
The rabbit ensures their names always show.
With a twitch of the nose and a flick of the ear,
Team spirit and names are now crystal clear!
🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c838bb and f16d801.

📒 Files selected for processing (2)
  • renderer/viewer/three/entities.ts (5 hunks)
  • src/entities.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • renderer/viewer/three/entities.ts
  • src/entities.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-and-deploy
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
renderer/viewer/three/entities.ts (2)

811-812: Duplicate name = 'nametag' assignment (minor)

addNametag already sets nameTag.name = 'nametag' (line 165).
The extra assignment here is harmless but redundant. Feel free to drop it.


1043-1052: Missing updateNameTagVisibility call for non-player models

The visibility logic is invoked only when the entity is both a player and e.playerObject exists.
If a remote player is for some reason shown with the generic fallback mesh (e.g. skin load failure), their tag will never be updated.
Consider calling updateNameTagVisibility unconditionally for entity.type === 'player'.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5269ad2 and 98e2a63.

📒 Files selected for processing (2)
  • renderer/viewer/three/entities.ts (3 hunks)
  • src/entities.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-and-deploy

@zardoy
Copy link
Owner

zardoy commented Jun 26, 2025

By code everything seems fine, let me know when if can be merged

@Phoenix616
Copy link
Author

Added some more improvements now to only update necessary entities and also fix that team-removal would not update the name tags. (Needs the new changes in mineflayer to work of course)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/entities.ts (1)

200-208: Fix loose equality operators.

The function logic is correct, but please use strict equality operators for consistency and type safety.

-      if ((entityTeam?.nameTagVisibility === 'hideForOwnTeam' && entityTeam.name == team.name)
-        || (entityTeam?.nameTagVisibility === 'hideForOtherTeams' && entityTeam.name != team.name)) {
+      if ((entityTeam?.nameTagVisibility === 'hideForOwnTeam' && entityTeam.name === team.name)
+        || (entityTeam?.nameTagVisibility === 'hideForOtherTeams' && entityTeam.name !== team.name)) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0048a51 and 0c18ee0.

📒 Files selected for processing (1)
  • src/entities.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`src/**/*.ts`: You may use the global variable `bot` directly in any file under ...

src/**/*.ts: You may use the global variable bot directly in any file under the src/ directory.
In src/ code, you may use the global variable appViewer from src/appViewer.ts directly. Do not import appViewer or use window.appViewer; use the global appViewer variable as-is.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/vars-usage.mdc)

List of files the instruction was applied to:

  • src/entities.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: zardoy
PR: zardoy/minecraft-web-client#373
File: renderer/viewer/three/entities.ts:1120-1120
Timestamp: 2025-06-23T13:33:14.776Z
Learning: In the minecraft-web-client project, files under renderer/ directory must not access the global `bot` variable directly according to .cursor/rules/vars-usage.mdc. The updateNameTagVisibility method in renderer/viewer/three/entities.ts currently violates this rule by accessing bot.teamMap and bot.username. Team information should be passed through entity update events from the world data emitter instead.
Learnt from: Phoenix616
PR: zardoy/minecraft-web-client#373
File: src/entities.ts:204-211
Timestamp: 2025-06-23T17:04:16.004Z
Learning: In mineflayer, the `teamMemberRemoved` event only provides the team object as a parameter, not the username of the removed player. Therefore, when handling this event, it's necessary to update all player entities because there's no way to identify which specific player was removed from the team.
Learnt from: zardoy
PR: zardoy/minecraft-web-client#373
File: renderer/viewer/three/entities.ts:1120-1120
Timestamp: 2025-06-23T13:33:14.776Z
Learning: In the minecraft-web-client project, team information for entities should be inlined into entity update events from the world data emitter rather than accessing the global bot object from renderer code. This maintains better separation of concerns between the data layer and renderer.
Learnt from: Phoenix616
PR: zardoy/minecraft-web-client#373
File: src/entities.ts:204-211
Timestamp: 2025-06-23T17:04:16.004Z
Learning: In mineflayer, the `teamMemberRemoved` event does not provide the removed username as a parameter, so when handling this event, you need to update all player entities because there's no way to identify which specific player was removed from the team.
Learnt from: Phoenix616
PR: zardoy/minecraft-web-client#373
File: src/entities.ts:192-199
Timestamp: 2025-06-23T17:04:53.409Z
Learning: The mineflayer `teamMemberAdded` event is emitted with only one argument: the team object, not with both team and username parameters.
src/entities.ts (7)
Learnt from: zardoy
PR: zardoy/minecraft-web-client#373
File: renderer/viewer/three/entities.ts:1120-1120
Timestamp: 2025-06-23T13:33:14.776Z
Learning: In the minecraft-web-client project, files under renderer/ directory must not access the global `bot` variable directly according to .cursor/rules/vars-usage.mdc. The updateNameTagVisibility method in renderer/viewer/three/entities.ts currently violates this rule by accessing bot.teamMap and bot.username. Team information should be passed through entity update events from the world data emitter instead.
Learnt from: zardoy
PR: zardoy/minecraft-web-client#373
File: renderer/viewer/three/entities.ts:1120-1120
Timestamp: 2025-06-23T13:33:14.776Z
Learning: In the minecraft-web-client project, team information for entities should be inlined into entity update events from the world data emitter rather than accessing the global bot object from renderer code. This maintains better separation of concerns between the data layer and renderer.
Learnt from: Phoenix616
PR: zardoy/minecraft-web-client#373
File: src/entities.ts:204-211
Timestamp: 2025-06-23T17:04:16.004Z
Learning: In mineflayer, the `teamMemberRemoved` event only provides the team object as a parameter, not the username of the removed player. Therefore, when handling this event, it's necessary to update all player entities because there's no way to identify which specific player was removed from the team.
Learnt from: Phoenix616
PR: zardoy/minecraft-web-client#373
File: src/entities.ts:204-211
Timestamp: 2025-06-23T17:04:16.004Z
Learning: In mineflayer, the `teamMemberRemoved` event does not provide the removed username as a parameter, so when handling this event, you need to update all player entities because there's no way to identify which specific player was removed from the team.
Learnt from: Phoenix616
PR: zardoy/minecraft-web-client#373
File: src/entities.ts:192-199
Timestamp: 2025-06-23T17:04:53.409Z
Learning: The mineflayer `teamMemberAdded` event is emitted with only one argument: the team object, not with both team and username parameters.
Learnt from: CR
PR: zardoy/minecraft-web-client#0
File: .cursor/rules/vars-usage.mdc:0-0
Timestamp: 2025-06-23T17:08:19.477Z
Learning: In the Mineflayer codebase, maintain a strict separation between game logic (in `src/`) and renderer/view logic (in `renderer/`). The renderer must never access the Mineflayer `bot` global directly; instead, it should interact with game state via explicit interfaces or state managers, such as the `playerState` property.
Learnt from: CR
PR: zardoy/minecraft-web-client#0
File: .cursor/rules/vars-usage.mdc:0-0
Timestamp: 2025-06-23T17:08:19.477Z
Learning: Global variables defined for use in `src/` (such as `appViewer` from `src/appViewer.ts`) should be accessed directly as globals, not imported or accessed via `window`, to ensure consistency and avoid ambiguity.
🧬 Code Graph Analysis (1)
src/entities.ts (2)
src/mineflayer/plugins/mouse.ts (1)
  • bot (47-54)
src/appViewer.ts (1)
  • appViewer (277-277)
🪛 ESLint
src/entities.ts

[error] 203-203: Expected '===' and instead saw '=='.

(eqeqeq)


[error] 204-204: Expected '!==' and instead saw '!='.

(eqeqeq)

🔇 Additional comments (6)
src/entities.ts (6)

7-7: LGTM!

Clean import addition for the Team type needed for the new functionality.


192-198: LGTM!

The team update handler correctly identifies affected player entities and triggers updates to reflect name tag visibility changes.


210-214: LGTM!

The logic correctly determines when entity updates are needed based on name tag visibility rules and the player's team membership.


216-229: LGTM!

Excellent implementation that efficiently handles team member additions by utilizing the updated mineflayer event signature with the members parameter. The reactive state management and conditional updates are well-designed.


231-244: LGTM!

The team member removal handler correctly mirrors the addition logic and efficiently handles bot team state cleanup and selective entity updates.


246-252: LGTM!

The team removal handler correctly manages the bot's reactive state and triggers appropriate entity updates when teams are completely removed.

@Phoenix616 Phoenix616 force-pushed the pr/team-nametagvisibility branch from 0c18ee0 to f8f84ed Compare June 27, 2025 11:36
@Phoenix616
Copy link
Author

Is there anything still required to get this merged?

@@ -99,6 +99,10 @@ export class PlayerStateControllerMain {
})
this.reactive.gameMode = bot.game?.gameMode

customEvents.on('gameLoaded', () => {
this.reactive.team = bot.teamMap[bot.username]
Copy link
Owner

Choose a reason for hiding this comment

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

@Phoenix616 I'm not sure, but shouldn't team be updated whenever the team is actually updated in (teamUpdated event above)?

Copy link
Author

@Phoenix616 Phoenix616 Jul 3, 2025

Choose a reason for hiding this comment

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

teamUpdated only updates the values of that team object, I might be wrong but I'm pretty sure Typescript/Javascript is pass by reference and doesn't copy the object on variable assignment (pass by value) so any change to the team object itself should be reflected in this variable no?

Copy link
Owner

@zardoy zardoy Jul 3, 2025

Choose a reason for hiding this comment

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

I will re-check.

@zardoy zardoy merged commit 4277c3a into zardoy:next Jul 3, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants