Skip to content

Commit 2f80e8f

Browse files
committed
Don't show a tags over the character that the player is controlling.
1 parent ed2ce24 commit 2f80e8f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

engine/src/main/java/org/terasology/logic/nameTags/PlayerNameTagSystem.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public void onCharacterActivation(OnActivatedComponent event, EntityRef characte
6565
logger.warn("Can't create player based name tag for character as owner has no client component");
6666
return;
6767
}
68+
if (clientComponent.local) {
69+
return; // the character belongs to the local player and does not need a name tag
70+
}
71+
6872
EntityRef clientInfoEntity = clientComponent.clientInfo;
6973

7074
DisplayNameComponent displayNameComponent = clientInfoEntity.getComponent(DisplayNameComponent.class);
@@ -98,6 +102,22 @@ public void onCharacterActivation(OnActivatedComponent event, EntityRef characte
98102

99103
}
100104

105+
/**
106+
* The player entity may currently become "local" afterh the player has been activated.
107+
*
108+
* To address this issue the name tag component will be removed again when a client turns out to be local
109+
* afterwards.
110+
*/
111+
@ReceiveEvent
112+
public void onClientComponentChange(OnChangedComponent event, EntityRef clientEntity,
113+
ClientComponent clientComponent) {
114+
if (clientComponent.local) {
115+
EntityRef character = clientComponent.character;
116+
if (character.exists() && character.hasComponent(NameTagComponent.class)) {
117+
character.removeComponent(NameTagComponent.class);
118+
}
119+
}
120+
}
101121

102122
@ReceiveEvent
103123
public void onDisplayNameChange(OnChangedComponent event, EntityRef clientInfoEntity,
@@ -125,8 +145,7 @@ public void onDisplayNameChange(OnChangedComponent event, EntityRef clientInfoEn
125145

126146
NameTagComponent nameTagComponent = characterEntity.getComponent(NameTagComponent.class);
127147
if (nameTagComponent == null) {
128-
logger.warn("Tried to update the name tag component with a new player name but it was missing");
129-
148+
return; // local players don't have a name tag
130149
}
131150

132151
nameTagComponent.text = displayNameComponent.name;

0 commit comments

Comments
 (0)