use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class PlayerNameTagSystem method onDisplayNameChange.
@ReceiveEvent
public void onDisplayNameChange(OnChangedComponent event, EntityRef clientInfoEntity, DisplayNameComponent displayNameComponent, ClientInfoComponent clientInfoComp) {
EntityRef clientEntity = clientInfoComp.client;
if (!clientEntity.exists()) {
// offline players aren't visible: nothing to do
return;
}
ClientComponent clientComponent = clientEntity.getComponent(ClientComponent.class);
if (clientComponent == null) {
// the character is not owned by a client (no other player)
return;
}
EntityRef characterEntity = clientComponent.character;
if (characterEntity == null || !characterEntity.exists()) {
// player has no character, nothing to do
return;
}
NameTagComponent nameTagComponent = characterEntity.getComponent(NameTagComponent.class);
if (nameTagComponent == null) {
// local players don't have a name tag
return;
}
nameTagComponent.text = displayNameComponent.name;
characterEntity.saveComponent(nameTagComponent);
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent 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;
});
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ItemPickupAuthoritySystem method updateExtentsOnBlockItemBoxShape.
@ReceiveEvent
public void updateExtentsOnBlockItemBoxShape(OnAddedComponent event, EntityRef itemEntity, BlockItemComponent blockItemComponent, BoxShapeComponent boxShapeComponent) {
BlockFamily blockFamily = blockItemComponent.blockFamily;
if (blockFamily == null) {
LOGGER.warn("Prefab " + itemEntity.getParentPrefab().getName() + " does not have a block family");
return;
}
if (blockFamily.getArchetypeBlock().getCollisionShape() instanceof btBoxShape) {
Vector3f extents = ((btBoxShape) blockFamily.getArchetypeBlock().getCollisionShape()).getHalfExtentsWithoutMargin();
extents.x = Math.max(extents.x, 0.5f);
extents.y = Math.max(extents.y, 0.5f);
extents.z = Math.max(extents.z, 0.5f);
boxShapeComponent.extents.set(extents);
itemEntity.saveComponent(boxShapeComponent);
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ItemPickupAuthoritySystem method onBumpGiveItemToEntity.
@ReceiveEvent
public void onBumpGiveItemToEntity(CollideEvent event, EntityRef entity, PickupComponent pickupComponent) {
if (pickupComponent.timeDropped + pickupComponent.timeToPickUp < time.getGameTimeInMs()) {
GiveItemEvent giveItemEvent = new GiveItemEvent(event.getOtherEntity());
entity.send(giveItemEvent);
if (giveItemEvent.isHandled()) {
// remove all the components added from the pickup prefab
ItemComponent itemComponent = entity.getComponent(ItemComponent.class);
if (itemComponent != null) {
for (Component component : itemComponent.pickupPrefab.iterateComponents()) {
entity.removeComponent(component.getClass());
}
}
}
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class LocalPlayerSystem method onPlayerSpawn.
@ReceiveEvent
public void onPlayerSpawn(OnPlayerSpawnedEvent event, EntityRef character) {
if (character.equals(localPlayer.getCharacterEntity())) {
// update character height as given in player settings
ScaleToRequest scaleRequest = new ScaleToRequest(playerConfig.height.get());
localPlayer.getCharacterEntity().send(scaleRequest);
// Trigger updating the player camera position as soon as the local player is spawned.
// This is not done while the game is still loading, since systems are not updated.
// RenderableWorldImpl pre-generates chunks around the player camera and therefore needs
// the correct location.
lookYaw = 0f;
lookPitch = 0f;
update(0);
}
}
Aggregations