Search in sources :

Example 51 with ReceiveEvent

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

the class PhysicsSystem method onItemImpact.

@ReceiveEvent
public void onItemImpact(ImpactEvent event, EntityRef entity) {
    RigidBody rigidBody = physics.getRigidBody(entity);
    if (rigidBody != null) {
        Vector3f vImpactNormal = new Vector3f(event.getImpactNormal());
        Vector3f vImpactPoint = new Vector3f(event.getImpactPoint());
        Vector3f vImpactSpeed = new Vector3f(event.getImpactSpeed());
        float speedFactor = vImpactSpeed.length();
        vImpactNormal.normalize();
        vImpactSpeed.normalize();
        float dotImpactNormal = vImpactSpeed.dot(vImpactNormal);
        Vector3f impactResult = vImpactNormal.mul(dotImpactNormal);
        impactResult = vImpactSpeed.sub(impactResult.mul(2.0f));
        impactResult.normalize();
        Vector3f vNewLocationVector = (new Vector3f(impactResult)).mul(event.getTravelDistance());
        Vector3f vNewPosition = (new Vector3f(vImpactPoint)).add(vNewLocationVector);
        Vector3f vNewVelocity = (new Vector3f(impactResult)).mul(speedFactor * COLLISION_DAMPENING_MULTIPLIER);
        rigidBody.setLocation(vNewPosition);
        rigidBody.setLinearVelocity(vNewVelocity);
        rigidBody.setAngularVelocity(vNewVelocity);
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 52 with ReceiveEvent

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

the class EntityAwareWorldProvider method onBlockRegionActivated.

@ReceiveEvent(components = { BlockRegionComponent.class })
public void onBlockRegionActivated(OnActivatedComponent event, EntityRef entity) {
    BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
    blockRegions.put(entity, regionComp.region);
    for (Vector3i pos : regionComp.region) {
        blockRegionLookup.put(pos, entity);
    }
}
Also used : BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) Vector3i(org.terasology.math.geom.Vector3i) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 53 with ReceiveEvent

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

the class EntityAwareWorldProvider method onBlockRegionDeactivated.

@ReceiveEvent(components = { BlockRegionComponent.class })
public void onBlockRegionDeactivated(BeforeDeactivateComponent event, EntityRef entity) {
    Region3i oldRegion = blockRegions.get(entity);
    for (Vector3i pos : oldRegion) {
        blockRegionLookup.remove(pos);
    }
    blockRegions.remove(entity);
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Region3i(org.terasology.math.Region3i) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 54 with ReceiveEvent

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

the class EntityAwareWorldProvider method onActivateBlock.

@ReceiveEvent(components = { BlockComponent.class })
public void onActivateBlock(OnActivatedComponent event, EntityRef entity) {
    BlockComponent block = entity.getComponent(BlockComponent.class);
    EntityRef oldEntity = blockEntityLookup.put(new Vector3i(block.getPosition()), entity);
    // If this is a client, then an existing block entity may exist. Destroy it.
    if (oldEntity != null && !Objects.equal(oldEntity, entity)) {
        oldEntity.destroy();
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) Vector3i(org.terasology.math.geom.Vector3i) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 55 with ReceiveEvent

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

the class EntityAwareWorldProvider method onBlockRegionChanged.

@ReceiveEvent(components = { BlockRegionComponent.class })
public void onBlockRegionChanged(OnChangedComponent event, EntityRef entity) {
    Region3i oldRegion = blockRegions.get(entity);
    for (Vector3i pos : oldRegion) {
        blockRegionLookup.remove(pos);
    }
    BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
    blockRegions.put(entity, regionComp.region);
    for (Vector3i pos : regionComp.region) {
        blockRegionLookup.put(pos, entity);
    }
}
Also used : BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) Vector3i(org.terasology.math.geom.Vector3i) Region3i(org.terasology.math.Region3i) 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