Search in sources :

Example 1 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Anatomy by Terasology.

the class SkeletalAuthoritySystem method onRegen.

@ReceiveEvent
public void onRegen(DelayedActionTriggeredEvent event, EntityRef entityRef) {
    BoneComponent boneComponent = entityRef.getComponent(BoneComponent.class);
    String partID = event.getActionId().substring(SKELETAL_REGEN_PREFIX.length());
    PartSkeletalDetails partDetails = boneComponent.parts.get(partID);
    if (partDetails.health >= 0 && partDetails.health != partDetails.maxHealth && partDetails.regenRate != 0) {
        int healAmount = 0;
        healAmount = regenerateHealth(partDetails, healAmount);
        partDetails.health += healAmount;
        entityRef.saveComponent(boneComponent);
        entityRef.send(new BoneHealthChangedEvent(partID));
    }
    delayManager.addDelayedAction(entityRef, SKELETAL_REGEN_PREFIX + partID, (long) (1000 / partDetails.regenRate));
}
Also used : BoneHealthChangedEvent(org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent) BoneComponent(org.terasology.anatomy.AnatomySkeleton.component.BoneComponent) PartSkeletalDetails(org.terasology.anatomy.component.PartSkeletalDetails) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 2 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class ServerViewDistanceSystem method onChangeViewDistanceChanged.

@ReceiveEvent(components = ClientComponent.class)
public void onChangeViewDistanceChanged(ViewDistanceChangedEvent request, EntityRef entity) {
    Client client = networkSystem.getOwner(entity);
    if (client != null) {
        client.setViewDistanceMode(request.getNewViewRange());
        chunkProvider.updateRelevanceEntity(entity, client.getViewDistance().getChunkDistance());
    }
}
Also used : Client(org.terasology.network.Client) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 3 with ReceiveEvent

use of org.terasology.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.world.block.items.BlockItemComponent) GiveItemEvent(org.terasology.logic.inventory.events.GiveItemEvent) LocationComponent(org.terasology.logic.location.LocationComponent) RigidBodyComponent(org.terasology.physics.components.RigidBodyComponent) OnAddedComponent(org.terasology.entitySystem.entity.lifecycleEvents.OnAddedComponent) Component(org.terasology.entitySystem.Component) BoxShapeComponent(org.terasology.physics.components.shapes.BoxShapeComponent) BlockItemComponent(org.terasology.world.block.items.BlockItemComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 4 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class PlayerNameTagSystem method onCharacterActivation.

/**
 * Listening for {@link org.terasology.logic.players.event.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) {
        logger.warn("Can't create player based name tag for character as owner has no client component");
        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.error("Can't create player based name tag for character as client info has no DisplayNameComponent");
        return;
    }
    String name = displayNameComponent.name;
    float yOffset = characterComponent.nameTagOffset;
    Color color = Color.WHITE;
    ColorComponent colorComponent = clientInfoEntity.getComponent(ColorComponent.class);
    if (colorComponent != null) {
        color = colorComponent.color;
    }
    NameTagComponent nameTagComponent = characterEntity.getComponent(NameTagComponent.class);
    boolean newComponent = nameTagComponent == null;
    if (nameTagComponent == null) {
        nameTagComponent = new NameTagComponent();
    }
    nameTagComponent.text = name;
    nameTagComponent.textColor = color;
    nameTagComponent.yOffset = yOffset;
    if (newComponent) {
        characterEntity.addComponent(nameTagComponent);
    } else {
        characterEntity.saveComponent(nameTagComponent);
    }
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) ColorComponent(org.terasology.network.ColorComponent) Color(org.terasology.rendering.nui.Color) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 5 with ReceiveEvent

use of org.terasology.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 = clientInfoEntity.getComponent(ClientInfoComponent.class);
    if (clientInfoComp == null) {
        // not a client info object
        return;
    }
    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) {
        logger.warn("Can't update name tag as client entity lacks ClietnComponent");
        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 : ClientInfoComponent(org.terasology.network.ClientInfoComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)98 EntityRef (org.terasology.entitySystem.entity.EntityRef)36 Vector3f (org.terasology.math.geom.Vector3f)26 LocationComponent (org.terasology.logic.location.LocationComponent)17 Vector3i (org.terasology.math.geom.Vector3i)17 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)15 StaticSound (org.terasology.audio.StaticSound)13 Block (org.terasology.world.block.Block)11 ClientComponent (org.terasology.network.ClientComponent)7 BlockComponent (org.terasology.world.block.BlockComponent)7 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)7 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 CharacterComponent (org.terasology.logic.characters.CharacterComponent)4 OnItemUseEvent (org.terasology.logic.characters.events.OnItemUseEvent)4 ResourceUrn (org.terasology.assets.ResourceUrn)3 Component (org.terasology.entitySystem.Component)3 ItemComponent (org.terasology.logic.inventory.ItemComponent)3 Side (org.terasology.math.Side)3 BoneHealthChangedEvent (org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent)2 PartSkeletalDetails (org.terasology.anatomy.component.PartSkeletalDetails)2