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);
}
}
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);
}
}
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);
}
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();
}
}
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);
}
}
Aggregations