Search in sources :

Example 76 with ReceiveEvent

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()));
}
Also used : Vector3ic(org.joml.Vector3ic) OnChangedBlock(org.terasology.engine.world.OnChangedBlock) Block(org.terasology.engine.world.block.Block) Chunk(org.terasology.engine.world.chunks.Chunk) ByteBuffer(java.nio.ByteBuffer) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 77 with ReceiveEvent

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()));
}
Also used : Vector3ic(org.joml.Vector3ic) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 78 with ReceiveEvent

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);
    }
}
Also used : Vector3f(org.joml.Vector3f) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 79 with ReceiveEvent

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);
}
Also used : Bone(org.terasology.engine.rendering.assets.skeletalmesh.Bone) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 80 with ReceiveEvent

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);
    }
}
Also used : Vector3i(org.joml.Vector3i) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)83 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)27 Vector3f (org.joml.Vector3f)18 LocationComponent (org.terasology.engine.logic.location.LocationComponent)12 Vector3i (org.joml.Vector3i)10 StaticSound (org.terasology.engine.audio.StaticSound)10 Vector3ic (org.joml.Vector3ic)9 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)9 ClientComponent (org.terasology.engine.network.ClientComponent)8 Quaternionf (org.joml.Quaternionf)6 BlockComponent (org.terasology.engine.world.block.BlockComponent)6 OnItemUseEvent (org.terasology.engine.logic.characters.events.OnItemUseEvent)5 Block (org.terasology.engine.world.block.Block)5 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)4 BlockRegion (org.terasology.engine.world.block.BlockRegion)4 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)3 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)3 Component (org.terasology.gestalt.entitysystem.component.Component)3 Method (java.lang.reflect.Method)2 Vector3fc (org.joml.Vector3fc)2