use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class VoxelWorldSystem method onNewChunk.
/**
* new chunks that are loaded need to update pass the data to bullet
*
* @param chunkAvailable the chunk
* @param worldEntity world entity
*/
@ReceiveEvent(components = WorldComponent.class)
public void onNewChunk(OnChunkLoaded chunkAvailable, EntityRef worldEntity) {
Vector3ic chunkPos = chunkAvailable.getChunkPos();
Chunk chunk = chunkProvider.getChunk(chunkPos);
ByteBuffer buffer = ByteBuffer.allocateDirect(2 * (Chunks.SIZE_X * Chunks.SIZE_Y * Chunks.SIZE_Z));
buffer.order(ByteOrder.nativeOrder());
for (int z = 0; z < Chunks.SIZE_Z; z++) {
for (int x = 0; x < Chunks.SIZE_X; x++) {
for (int y = 0; y < Chunks.SIZE_Y; y++) {
Block block = chunk.getBlock(x, y, z);
colliders.forEach(k -> k.registerBlock(block));
buffer.putShort(block.getId());
}
}
}
buffer.rewind();
colliders.forEach(k -> k.loadChunk(chunk, buffer.duplicate().asShortBuffer()));
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class VoxelWorldSystem method onBlockChange.
@ReceiveEvent(components = BlockComponent.class)
public void onBlockChange(OnChangedBlock event, EntityRef entity) {
Vector3ic p = event.getBlockPosition();
colliders.forEach(k -> k.setBlock(p.x(), p.y(), p.z(), event.getNewType()));
}
use of org.terasology.engine.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.engine.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 boneEntity = entityManager.create(loc);
skeleton.boneEntities.put(bone.getName(), boneEntity);
}
}
for (Bone bone : skeleton.mesh.getBones()) {
EntityRef boneEntity = skeleton.boneEntities.get(bone.getName());
EntityRef parent = (bone.getParent() != null) ? skeleton.boneEntities.get(bone.getParent().getName()) : entity;
Location.attachChild(parent, boneEntity);
}
for (Bone bone : skeleton.mesh.getBones()) {
EntityRef boneEntity = skeleton.boneEntities.get(bone.getName());
LocationComponent loc = boneEntity.getComponent(LocationComponent.class);
loc.setLocalPosition(bone.getLocalPosition());
loc.setLocalRotation(bone.getLocalRotation());
loc.setLocalScale(bone.getLocalScale().x);
boneEntity.saveComponent(loc);
if (bone.getParent() == null) {
skeleton.rootBone = boneEntity;
}
}
entity.saveComponent(skeleton);
}
use of org.terasology.engine.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);
}
}
Aggregations