Search in sources :

Example 71 with ReceiveEvent

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);
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 72 with ReceiveEvent

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;
    });
}
Also used : DisplayNameComponent(org.terasology.engine.logic.common.DisplayNameComponent) ColorComponent(org.terasology.engine.network.ColorComponent) Color(org.terasology.nui.Color) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 73 with ReceiveEvent

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);
    }
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBoxShape(com.badlogic.gdx.physics.bullet.collision.btBoxShape) Vector3f(org.joml.Vector3f) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 74 with ReceiveEvent

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());
                }
            }
        }
    }
}
Also used : BlockItemComponent(org.terasology.engine.world.block.items.BlockItemComponent) GiveItemEvent(org.terasology.engine.logic.inventory.events.GiveItemEvent) Component(org.terasology.gestalt.entitysystem.component.Component) RigidBodyComponent(org.terasology.engine.physics.components.RigidBodyComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) OnAddedComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.OnAddedComponent) BlockItemComponent(org.terasology.engine.world.block.items.BlockItemComponent) BoxShapeComponent(org.terasology.engine.physics.components.shapes.BoxShapeComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 75 with ReceiveEvent

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);
    }
}
Also used : ScaleToRequest(org.terasology.engine.logic.characters.events.ScaleToRequest) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)83 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)27 Vector3f (org.joml.Vector3f)18 LocationComponent (org.terasology.engine.logic.location.LocationComponent)12 Vector3i (org.joml.Vector3i)10 StaticSound (org.terasology.engine.audio.StaticSound)10 Vector3ic (org.joml.Vector3ic)9 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)9 ClientComponent (org.terasology.engine.network.ClientComponent)8 Quaternionf (org.joml.Quaternionf)6 BlockComponent (org.terasology.engine.world.block.BlockComponent)6 OnItemUseEvent (org.terasology.engine.logic.characters.events.OnItemUseEvent)5 Block (org.terasology.engine.world.block.Block)5 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)4 BlockRegion (org.terasology.engine.world.block.BlockRegion)4 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)3 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)3 Component (org.terasology.gestalt.entitysystem.component.Component)3 Method (java.lang.reflect.Method)2 Vector3fc (org.joml.Vector3fc)2