use of org.terasology.engine.network.ColorComponent in project Terasology by MovingBlocks.
the class NetClient method setColor.
public void setColor(Color color) {
this.color = color;
ClientComponent client = getEntity().getComponent(ClientComponent.class);
if (client != null) {
ColorComponent colorInfo = client.clientInfo.getComponent(ColorComponent.class);
if (colorInfo != null) {
colorInfo.color = color;
client.clientInfo.saveComponent(colorInfo);
}
}
}
use of org.terasology.engine.network.ColorComponent in project Terasology by MovingBlocks.
the class PlayerUtil method getColoredPlayerName.
public static String getColoredPlayerName(EntityRef from) {
DisplayNameComponent displayInfo = from.getComponent(DisplayNameComponent.class);
ColorComponent colorInfo = from.getComponent(ColorComponent.class);
String playerName = (displayInfo != null) ? displayInfo.name : "Unknown";
if (colorInfo != null) {
playerName = FontColor.getColored(playerName, colorInfo.color);
}
return playerName;
}
use of org.terasology.engine.network.ColorComponent in project Terasology by MovingBlocks.
the class AbstractClient method addOrSetColorComponent.
/**
* Used to change or add a color to the client entity.
* @param clientInfo
* @param color Used to change the clients color to this
*/
private void addOrSetColorComponent(EntityRef clientInfo, Color color) {
ColorComponent colorComp = clientInfo.getComponent(ColorComponent.class);
if (colorComp != null) {
colorComp.color = color;
clientInfo.saveComponent(colorComp);
} else {
colorComp = new ColorComponent();
colorComp.color = color;
clientInfo.addComponent(colorComp);
}
}
use of org.terasology.engine.network.ColorComponent in project Terasology by MovingBlocks.
the class WorldCommands method simulate.
@Command(shortDescription = "Random", runOnServer = true)
public String simulate(@Sender EntityRef sender) {
EntityRef simulatedEntity = entityManager.create("engine:multiWorldSim");
DisplayNameComponent displayNameComponent = simulatedEntity.getComponent(DisplayNameComponent.class);
displayNameComponent.name = "I-Travel-Worlds-" + simulatedEntity.getId();
simulatedEntity.saveComponent(displayNameComponent);
ColorComponent colorComponent = simulatedEntity.getComponent(ColorComponent.class);
colorComponent.color = Color.RED;
simulatedEntity.saveComponent(colorComponent);
sender.send(new ChatMessageEvent("yay", simulatedEntity));
return "done";
}
use of org.terasology.engine.network.ColorComponent in project Terasology by MovingBlocks.
the class PlayerNameTagSystem method onCharacterActivation.
/**
* Listening for {@link OnPlayerSpawnedEvent} does not work, as it is an
* authority event that does not get processed at clients. That is why we listen for the activation.
*/
@ReceiveEvent(components = CharacterComponent.class)
public void onCharacterActivation(OnActivatedComponent event, EntityRef characterEntity, CharacterComponent characterComponent) {
EntityRef ownerEntity = networkSystem.getOwnerEntity(characterEntity);
if (ownerEntity == null) {
// NPC
return;
}
ClientComponent clientComponent = ownerEntity.getComponent(ClientComponent.class);
if (clientComponent == null) {
// the character is not owned by a client (no other player)
return;
}
if (clientComponent.local) {
// the character belongs to the local player and does not need a name tag
return;
}
EntityRef clientInfoEntity = clientComponent.clientInfo;
DisplayNameComponent displayNameComponent = clientInfoEntity.getComponent(DisplayNameComponent.class);
if (displayNameComponent == null) {
logger.debug("Cannot create name tag for client without DisplayNameComponent");
return;
}
String name = displayNameComponent.name;
float yOffset = characterComponent.nameTagOffset;
ColorComponent colorComponent = clientInfoEntity.getComponent(ColorComponent.class);
final Color color = colorComponent != null ? colorComponent.color : Color.WHITE;
characterEntity.upsertComponent(NameTagComponent.class, maybeNameTag -> {
NameTagComponent nameTagComponent = maybeNameTag.orElse(new NameTagComponent());
nameTagComponent.text = name;
nameTagComponent.textColor = color;
nameTagComponent.yOffset = yOffset;
return nameTagComponent;
});
}
Aggregations