Search in sources :

Example 46 with ReceiveEvent

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

the class SkeletalAuthoritySystem method onBoneDamage.

@ReceiveEvent
public void onBoneDamage(AnatomyPartImpactedEvent event, EntityRef entityRef, AnatomyComponent anatomyComponent, BoneComponent boneComponent) {
    PartSkeletalDetails partDetails = boneComponent.parts.get(event.getTargetPart().id);
    // Check if the part contains bone.
    int damageAmount = event.getAmount();
    if (partDetails != null) {
        if (event.getDamageType().getName().equals("Equipment:bluntDamage")) {
            damageAmount *= bluntDamageMultiplier;
        }
        partDetails.health -= damageAmount;
        if (partDetails.health < 0) {
            partDetails.health = 0;
        }
        partDetails.nextRegenTick = time.getGameTimeInMs() + TeraMath.floorToInt(partDetails.waitBeforeRegen * 1000);
        entityRef.saveComponent(boneComponent);
        entityRef.send(new BoneHealthChangedEvent(event.getTargetPart().id));
    }
}
Also used : BoneHealthChangedEvent(org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent) PartSkeletalDetails(org.terasology.anatomy.component.PartSkeletalDetails) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 47 with ReceiveEvent

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

the class AnatomySystem method onDamage.

@ReceiveEvent
public void onDamage(OnDamagedEvent event, EntityRef entity, AnatomyComponent comp) {
    if (comp != null) {
        List<String> keys = new ArrayList<>(comp.parts.keySet());
        // Randomly assign damage to a part, until positional damage is introduced.
        AnatomyPartTag partTag = comp.parts.get(keys.get(random.nextInt(0, keys.size() - 1)));
        entity.send(new AnatomyPartImpactedEvent(event.getDamageAmount(), partTag, event.getType(), event.getInstigator()));
    }
}
Also used : AnatomyPartTag(org.terasology.anatomy.component.AnatomyPartTag) ArrayList(java.util.ArrayList) AnatomyPartImpactedEvent(org.terasology.anatomy.event.AnatomyPartImpactedEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 48 with ReceiveEvent

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

the class SkeletonRenderer method newSkeleton.

@ReceiveEvent(components = { SkeletalMeshComponent.class, LocationComponent.class })
public void newSkeleton(OnActivatedComponent event, EntityRef entity) {
    SkeletalMeshComponent skeleton = entity.getComponent(SkeletalMeshComponent.class);
    if (skeleton.mesh == null) {
        return;
    }
    if (skeleton.boneEntities == null) {
        skeleton.boneEntities = Maps.newHashMap();
        for (Bone bone : skeleton.mesh.getBones()) {
            LocationComponent loc = new LocationComponent();
            EntityRef parent = (bone.getParent() != null) ? skeleton.boneEntities.get(bone.getParent().getName()) : entity;
            EntityRef boneEntity = entityManager.create(loc);
            Location.attachChild(parent, boneEntity);
            loc.setLocalPosition(bone.getLocalPosition());
            loc.setLocalRotation(bone.getLocalRotation());
            if (bone.getParent() == null) {
                skeleton.rootBone = boneEntity;
            }
            skeleton.boneEntities.put(bone.getName(), boneEntity);
        }
        entity.saveComponent(skeleton);
    }
}
Also used : Bone(org.terasology.rendering.assets.skeletalmesh.Bone) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 49 with ReceiveEvent

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

the class BlockEntitySystem method defaultDropsHandling.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void defaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, ActAsBlockComponent blockComponent) {
    if (blockComponent.block != null) {
        if (entity.hasComponent(BlockRegionComponent.class)) {
            BlockRegionComponent blockRegion = entity.getComponent(BlockRegionComponent.class);
            if (blockComponent.dropBlocksInRegion) {
                // loop through all the blocks in this region and drop them
                for (Vector3i location : blockRegion.region) {
                    Block blockInWorld = worldProvider.getBlock(location);
                    commonDefaultDropsHandling(event, entity, location, blockInWorld.getBlockFamily().getArchetypeBlock());
                }
            } else {
                // just drop the ActAsBlock block
                Vector3i location = new Vector3i(blockRegion.region.center(), RoundingMode.HALF_UP);
                commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
            }
        } else if (entity.hasComponent(LocationComponent.class)) {
            LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
            Vector3i location = new Vector3i(locationComponent.getWorldPosition(), RoundingMode.HALF_UP);
            commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
        }
    }
}
Also used : BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 50 with ReceiveEvent

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

the class NeighbourBlockFamilyUpdateSystem method blockUpdate.

@ReceiveEvent(components = { BlockComponent.class })
public void blockUpdate(OnChangedBlock event, EntityRef blockEntity) {
    if (largeBlockUpdateCount > 0) {
        blocksUpdatedInLargeBlockUpdate.add(event.getBlockPosition());
    } else {
        Vector3i blockLocation = event.getBlockPosition();
        processUpdateForBlockLocation(blockLocation);
    }
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) 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