Example usage for net.minecraftforge.client.model.pipeline LightUtil mapFormats

List of usage examples for net.minecraftforge.client.model.pipeline LightUtil mapFormats

Introduction

In this page you can find the example usage for net.minecraftforge.client.model.pipeline LightUtil mapFormats.

Prototype

public static int[] mapFormats(VertexFormat from, VertexFormat to) 

Source Link

Usage

From source file:blusunrize.immersiveengineering.client.models.SmartLightingQuad.java

@Override
public void pipe(IVertexConsumer consumer) {
    IBlockAccess world = null;/*from  w  w  w .  jav a2s.c om*/
    BlockInfo info = null;
    if (consumer instanceof VertexLighterFlat) {
        try {
            info = (BlockInfo) blockInfo.get(consumer);
            world = info.getWorld();
            if (world instanceof ChunkCache)
                world = ((ChunkCache) world).world;
            consumer = (IVertexConsumer) parent.get(consumer);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    consumer.setQuadOrientation(this.getFace());
    if (this.hasTintIndex())
        consumer.setQuadTint(this.getTintIndex());
    float[] data = new float[4];
    VertexFormat format = consumer.getVertexFormat();
    int count = format.getElementCount();
    int[] eMap = LightUtil.mapFormats(format, DefaultVertexFormats.ITEM);
    int itemCount = DefaultVertexFormats.ITEM.getElementCount();
    eMap[eMap.length - 1] = 2;
    for (int v = 0; v < 4; v++)
        for (int e = 0; e < count; e++)
            if (eMap[e] != itemCount) {
                if (format.getElement(e).getUsage() == EnumUsage.UV
                        && format.getElement(e).getType() == EnumType.SHORT)//lightmap is UV with 2 shorts
                {
                    int brightness;
                    if (!ignoreLight && world != null && !(world instanceof ChunkCache)) {
                        BlockPos here = blockPos.add(relativePos[v][0], relativePos[v][1], relativePos[v][2]);
                        brightness = world.getCombinedLight(here, 0);
                    } else
                        brightness = staticBrightness;
                    data[0] = ((float) ((brightness >> 0x04) & 0xF) * 0x20) / 0xFFFF;
                    data[1] = ((float) ((brightness >> 0x14) & 0xF) * 0x20) / 0xFFFF;
                } else
                    LightUtil.unpack(this.getVertexData(), data, DefaultVertexFormats.ITEM, v, eMap[e]);
                consumer.put(e, data);
            } else
                consumer.put(e, 0);
}