Search in sources :

Example 1 with LightComponent

use of org.terasology.engine.rendering.logic.LightComponent in project Terasology by MovingBlocks.

the class ItemCommonSystem method addOrUpdateBlockMeshComponent.

public static void addOrUpdateBlockMeshComponent(BlockItemComponent blockItemComponent, MutableComponentContainer entity) {
    if (blockItemComponent != null) {
        MeshComponent meshComponent = null;
        if (entity.hasComponent(MeshComponent.class)) {
            meshComponent = entity.getComponent(MeshComponent.class);
        } else {
            meshComponent = new MeshComponent();
        }
        BlockFamily blockFamily = blockItemComponent.blockFamily;
        if (blockFamily == null) {
            return;
        }
        meshComponent.mesh = blockFamily.getArchetypeBlock().getMeshGenerator().getStandaloneMesh();
        meshComponent.material = Assets.getMaterial("engine:terrain").get();
        meshComponent.translucent = blockFamily.getArchetypeBlock().isTranslucent();
        float luminance = blockFamily.getArchetypeBlock().getLuminance() / 15f;
        meshComponent.selfLuminance = luminance;
        if (luminance > 0 && !entity.hasComponent(LightComponent.class)) {
            LightComponent lightComponent = entity.addComponent(new LightComponent());
            // scale the light back if it is a less bright block
            lightComponent.lightAttenuationRange *= luminance;
        }
        entity.addOrSaveComponent(meshComponent);
    }
}
Also used : MeshComponent(org.terasology.engine.rendering.logic.MeshComponent) LightComponent(org.terasology.engine.rendering.logic.LightComponent) BlockFamily(org.terasology.engine.world.block.family.BlockFamily)

Aggregations

LightComponent (org.terasology.engine.rendering.logic.LightComponent)1 MeshComponent (org.terasology.engine.rendering.logic.MeshComponent)1 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)1