Search in sources :

Example 26 with EntityBuilder

use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.

the class VisualCharacterSystem method onCreateDefaultVisualCharacter.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void onCreateDefaultVisualCharacter(CreateVisualCharacterEvent event, EntityRef characterEntity) {
    Prefab prefab = assetManager.getAsset("engine:defaultVisualCharacter", Prefab.class).get();
    EntityBuilder entityBuilder = event.getVisualCharacterBuilder();
    entityBuilder.addPrefab(prefab);
    event.consume();
}
Also used : EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 27 with EntityBuilder

use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.

the class BlockEntitySystem method commonDestroyed.

private void commonDestroyed(DoDestroyEvent event, EntityRef entity, Block block) {
    entity.send(new CreateBlockDropsEvent(event.getInstigator(), event.getDirectCause(), event.getDamageType()));
    BlockDamageModifierComponent blockDamageModifierComponent = event.getDamageType().getComponent(BlockDamageModifierComponent.class);
    // TODO: Configurable via block definition
    if (blockDamageModifierComponent == null || !blockDamageModifierComponent.skipPerBlockEffects) {
        // dust particle effect
        if (entity.hasComponent(LocationComponent.class) && block.isDebrisOnDestroy()) {
            // TODO: particle system stuff should be split out better - this is effectively a stealth dependency on
            // 'CoreAssets' from the engine
            EntityBuilder dustBuilder = entityManager.newBuilder("CoreAssets:dustEffect");
            if (dustBuilder.hasComponent(LocationComponent.class)) {
                dustBuilder.getComponent(LocationComponent.class).setWorldPosition(entity.getComponent(LocationComponent.class).getWorldPosition(new Vector3f()));
                dustBuilder.build();
            }
        }
        // sound to play for destroyed block
        BlockSounds sounds = block.getSounds();
        if (!sounds.getDestroySounds().isEmpty()) {
            StaticSound sound = random.nextItem(sounds.getDestroySounds());
            entity.send(new PlaySoundEvent(sound, 0.6f));
        }
    }
}
Also used : BlockSounds(org.terasology.engine.world.block.sounds.BlockSounds) StaticSound(org.terasology.engine.audio.StaticSound) Vector3f(org.joml.Vector3f) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) BlockDamageModifierComponent(org.terasology.engine.world.block.entity.damage.BlockDamageModifierComponent) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 28 with EntityBuilder

use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.

the class FirstPersonClientSystem method ensureClientSideEntityOnHeldItemMountPoint.

// ensures held item mount point entity exists, attaches it to the camera and sets its transform
@ReceiveEvent
public void ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent event, EntityRef camera, FirstPersonHeldItemMountPointComponent firstPersonHeldItemMountPointComponent) {
    if (!firstPersonHeldItemMountPointComponent.mountPointEntity.exists()) {
        EntityBuilder builder = entityManager.newBuilder("engine:FirstPersonHeldItemMountPoint");
        builder.setPersistent(false);
        firstPersonHeldItemMountPointComponent.mountPointEntity = builder.build();
        camera.saveComponent(firstPersonHeldItemMountPointComponent);
    }
    // link the mount point entity to the camera
    Location.removeChild(camera, firstPersonHeldItemMountPointComponent.mountPointEntity);
    Location.attachChild(camera, firstPersonHeldItemMountPointComponent.mountPointEntity, firstPersonHeldItemMountPointComponent.translate, new Quaternionf().rotationYXZ(TeraMath.DEG_TO_RAD * firstPersonHeldItemMountPointComponent.rotateDegrees.y, TeraMath.DEG_TO_RAD * firstPersonHeldItemMountPointComponent.rotateDegrees.x, TeraMath.DEG_TO_RAD * firstPersonHeldItemMountPointComponent.rotateDegrees.z), firstPersonHeldItemMountPointComponent.scale);
}
Also used : Quaternionf(org.joml.Quaternionf) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 29 with EntityBuilder

use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.

the class ThirdPersonRemoteClientSystem method ensureClientSideEntityOnHeldItemMountPoint.

/**
 * Ensures held item mount point entity exists, attaches it to the character and sets its transform.
 *
 * @param event the activation that triggered the need to consider changing a held item
 * @param character the character for which we need to consider the held item
 * @param remotePersonHeldItemMountPointComponent data for the mount point on the remote character
 */
@ReceiveEvent
public void ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent event, EntityRef character, RemotePersonHeldItemMountPointComponent remotePersonHeldItemMountPointComponent) {
    if (relatesToLocalPlayer(character)) {
        logger.debug("ensureClientSideEntityOnHeldItemMountPoint found its given character to relate to the local" + " player, ignoring: {}", character);
        return;
    }
    // In case we haven't dealt with a given remote player yet set up a non-persistent mount point
    if (!remotePersonHeldItemMountPointComponent.mountPointEntity.exists()) {
        EntityBuilder builder = entityManager.newBuilder("engine:RemotePersonHeldItemMountPoint");
        builder.setPersistent(false);
        remotePersonHeldItemMountPointComponent.mountPointEntity = builder.build();
        character.saveComponent(remotePersonHeldItemMountPointComponent);
    }
    // Link the mount point entity to the camera
    Location.removeChild(character, remotePersonHeldItemMountPointComponent.mountPointEntity);
    Location.attachChild(character, remotePersonHeldItemMountPointComponent.mountPointEntity, remotePersonHeldItemMountPointComponent.translate, new Quaternionf().rotationYXZ(Math.toRadians(remotePersonHeldItemMountPointComponent.rotateDegrees.y), Math.toRadians(remotePersonHeldItemMountPointComponent.rotateDegrees.x), Math.toRadians(remotePersonHeldItemMountPointComponent.rotateDegrees.z)), remotePersonHeldItemMountPointComponent.scale);
}
Also used : Quaternionf(org.joml.Quaternionf) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)29 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)12 NetworkComponent (org.terasology.engine.network.NetworkComponent)7 LocationComponent (org.terasology.engine.logic.location.LocationComponent)6 Vector3f (org.joml.Vector3f)5 Test (org.junit.jupiter.api.Test)5 Quaternionf (org.joml.Quaternionf)4 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)4 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)3 BlockComponent (org.terasology.engine.world.block.BlockComponent)2 Component (org.terasology.gestalt.entitysystem.component.Component)2 Vector3i (org.joml.Vector3i)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 StaticSound (org.terasology.engine.audio.StaticSound)1 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)1 Context (org.terasology.engine.context.Context)1 ContextImpl (org.terasology.engine.context.internal.ContextImpl)1 EntityManager (org.terasology.engine.entitySystem.entity.EntityManager)1