Search in sources :

Example 86 with ReceiveEvent

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

the class ArrowAction method onActivate.

@ReceiveEvent
public void onActivate(ActivateEvent event, EntityRef entity, ArrowActionComponent arrowActionComponent) {
    if (time.getGameTime() > lastTime + 1.0f / arrowActionComponent.arrowsPerSecond) {
        Vector3f target = event.getHitNormal();
        Vector3i blockPos = new Vector3i(target);
        Vector3f position = new Vector3f(event.getOrigin());
        Vector3f dir = new Vector3f(event.getDirection());
        HitResult result;
        result = physicsRenderer.rayTrace(position, dir, arrowActionComponent.maxDistance, filter);
        Block currentBlock = worldProvider.getBlock(blockPos);
        if (currentBlock.isDestructible()) {
            EntityBuilder builder = entityManager.newBuilder("Core:defaultBlockParticles");
            builder.getComponent(LocationComponent.class).setWorldPosition(target);
            builder.build();
        }
        EntityRef blockEntity = result.getEntity();
        blockEntity.send(new DoDamageEvent(arrowActionComponent.damageAmount, arrowActionComponent.damageType));
        lastTime = time.getGameTime();
    }
}
Also used : HitResult(org.terasology.physics.HitResult) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) DoDamageEvent(org.terasology.logic.health.DoDamageEvent) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 87 with ReceiveEvent

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

the class BlockDamageAuthoritySystem method beforeDamagedEnsureHealthPresent.

@ReceiveEvent
public void beforeDamagedEnsureHealthPresent(BeforeDamagedEvent event, EntityRef blockEntity, BlockComponent blockComponent) {
    if (!blockEntity.hasComponent(HealthComponent.class)) {
        Block type = blockComponent.getBlock();
        if (type.isDestructible()) {
            HealthComponent healthComponent = new HealthComponent(type.getHardness(), type.getHardness() / BLOCK_REGEN_SECONDS, 1.0f);
            healthComponent.destroyEntityOnNoHealth = true;
            blockEntity.addComponent(healthComponent);
        }
    }
}
Also used : Block(org.terasology.world.block.Block) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 88 with ReceiveEvent

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

the class HealthAuthoritySystem method onCrash.

@ReceiveEvent(components = { HealthComponent.class })
public void onCrash(HorizontalCollisionEvent event, EntityRef entity) {
    HealthComponent health = entity.getComponent(HealthComponent.class);
    Vector3f vel = new Vector3f(event.getVelocity());
    vel.y = 0;
    float speed = vel.length();
    if (speed > health.horizontalDamageSpeedThreshold) {
        int damage = (int) ((speed - health.horizontalDamageSpeedThreshold) * health.excessSpeedDamageMultiplier);
        if (damage > 0) {
            checkDamage(entity, damage, EngineDamageTypes.PHYSICAL.get(), EntityRef.NULL, EntityRef.NULL);
        }
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 89 with ReceiveEvent

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

the class HealthAuthoritySystem method onCrash.

@ReceiveEvent
public void onCrash(HorizontalCollisionEvent event, EntityRef entity, CharacterSoundComponent characterSounds, HealthComponent healthComponent) {
    Vector3f horizVelocity = new Vector3f(event.getVelocity());
    horizVelocity.y = 0;
    float velocity = horizVelocity.length();
    if (velocity > healthComponent.horizontalDamageSpeedThreshold) {
        if (characterSounds.lastSoundTime + CharacterSoundSystem.MIN_TIME < time.getGameTimeInMs()) {
            StaticSound sound = random.nextItem(characterSounds.landingSounds);
            if (sound != null) {
                entity.send(new PlaySoundEvent(sound, characterSounds.landingVolume));
                characterSounds.lastSoundTime = time.getGameTimeInMs();
                entity.saveComponent(characterSounds);
            }
        }
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) Vector3f(org.terasology.math.geom.Vector3f) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 90 with ReceiveEvent

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

the class CharacterInventorySystem method onNextItem.

@ReceiveEvent(components = { CharacterComponent.class }, netFilter = RegisterMode.CLIENT)
public void onNextItem(ToolbarNextButton event, EntityRef entity, SelectedInventorySlotComponent selectedInventorySlotComponent) {
    int nextSlot = (selectedInventorySlotComponent.slot + 1) % 10;
    localPlayer.getCharacterEntity().send(new ChangeSelectedInventorySlotRequest(nextSlot));
    event.consume();
}
Also used : ChangeSelectedInventorySlotRequest(org.terasology.logic.inventory.events.ChangeSelectedInventorySlotRequest) 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