Search in sources :

Example 1 with VertexTransformer

use of net.minecraftforge.client.model.pipeline.VertexTransformer in project BluePower by Qmunity.

the class BPMicroblockModel method transform.

private static BakedQuad transform(BakedQuad sizeQuad, TextureAtlasSprite sprite, Direction dir, Block block) {
    BakedQuadBuilder builder = new BakedQuadBuilder();
    final IVertexConsumer consumer = new VertexTransformer(builder) {

        @Override
        public void put(int element, float... data) {
            VertexFormatElement e = this.getVertexFormat().getElements().get(element);
            if (e.getUsage() == VertexFormatElement.Usage.UV && e.getIndex() == 0) {
                Vector2f vec = new Vector2f(data[0], data[1]);
                float u = (vec.x - sizeQuad.getSprite().getU0()) / (sizeQuad.getSprite().getU1() - sizeQuad.getSprite().getU0()) * 16;
                float v = (vec.y - sizeQuad.getSprite().getV0()) / (sizeQuad.getSprite().getV1() - sizeQuad.getSprite().getV0()) * 16;
                builder.put(element, sprite.getU(u), sprite.getV(v));
            } else if (e.getUsage() == VertexFormatElement.Usage.COLOR) {
                int color;
                try {
                    color = Minecraft.getInstance().getBlockColors().getColor(block.defaultBlockState(), null, null, sizeQuad.getTintIndex());
                } catch (Exception ex) {
                    try {
                        color = Minecraft.getInstance().getBlockColors().getColor(block.defaultBlockState(), null, BlockPos.ZERO, sizeQuad.getTintIndex());
                    } catch (Exception ex2) {
                        color = 0;
                    }
                }
                int redMask = 0xFF0000, greenMask = 0xFF00, blueMask = 0xFF;
                int r = (color & redMask) >> 16;
                int g = (color & greenMask) >> 8;
                int b = (color & blueMask);
                parent.put(element, r / 255F, g / 255F, b / 255F, 1);
            } else {
                parent.put(element, data);
            }
        }
    };
    LightUtil.putBakedQuad(consumer, sizeQuad);
    return builder.build();
}
Also used : IVertexConsumer(net.minecraftforge.client.model.pipeline.IVertexConsumer) VertexTransformer(net.minecraftforge.client.model.pipeline.VertexTransformer) Vector2f(net.minecraft.util.math.vector.Vector2f) VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement) BakedQuadBuilder(net.minecraftforge.client.model.pipeline.BakedQuadBuilder)

Example 2 with VertexTransformer

use of net.minecraftforge.client.model.pipeline.VertexTransformer in project BluePower by Qmunity.

the class BPMultipartModel method transform.

private static BakedQuad transform(BakedQuad quad, Pair<Integer, Integer> colorPair, Boolean fullBright) {
    BakedQuadBuilder builder = new BakedQuadBuilder();
    final IVertexConsumer consumer = new VertexTransformer(builder) {

        @Override
        public void put(int element, float... data) {
            VertexFormatElement e = this.getVertexFormat().getElements().get(element);
            if (e.getUsage() == VertexFormatElement.Usage.COLOR) {
                int color = quad.getTintIndex() == 2 ? colorPair.getSecond() : colorPair.getFirst();
                int redMask = 0xFF0000, greenMask = 0xFF00, blueMask = 0xFF;
                int r = (color & redMask) >> 16;
                int g = (color & greenMask) >> 8;
                int b = (color & blueMask);
                parent.put(element, r / 255F, g / 255F, b / 255F, 1);
            } else {
                parent.put(element, data);
            }
        }
    };
    LightUtil.putBakedQuad(consumer, quad);
    BakedQuad finalQuad = builder.build();
    if (fullBright)
        LightUtil.setLightData(finalQuad, 240);
    return finalQuad;
}
Also used : BakedQuad(net.minecraft.client.renderer.model.BakedQuad) IVertexConsumer(net.minecraftforge.client.model.pipeline.IVertexConsumer) VertexTransformer(net.minecraftforge.client.model.pipeline.VertexTransformer) VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement) BakedQuadBuilder(net.minecraftforge.client.model.pipeline.BakedQuadBuilder)

Aggregations

VertexFormatElement (net.minecraft.client.renderer.vertex.VertexFormatElement)2 BakedQuadBuilder (net.minecraftforge.client.model.pipeline.BakedQuadBuilder)2 IVertexConsumer (net.minecraftforge.client.model.pipeline.IVertexConsumer)2 VertexTransformer (net.minecraftforge.client.model.pipeline.VertexTransformer)2 BakedQuad (net.minecraft.client.renderer.model.BakedQuad)1 Vector2f (net.minecraft.util.math.vector.Vector2f)1