Search in sources :

Example 1 with Vector2f

use of net.minecraft.util.math.vector.Vector2f 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 Vector2f

use of net.minecraft.util.math.vector.Vector2f in project AgriCraft by AgriCraft.

the class TileEntitySeedAnalyzer method getObserverOrientation.

@Override
public Vector2f getObserverOrientation() {
    if (this.observerOrientation == null) {
        BlockState state = this.getBlockState();
        Direction dir = BlockSeedAnalyzer.ORIENTATION.fetch(state);
        // The analyzer looking glass is tilted 22.5 degrees, therefore we have to pitch down 67.5 degrees
        this.observerOrientation = new Vector2f(67.5F, dir.getOpposite().getHorizontalAngle());
    }
    return this.observerOrientation;
}
Also used : BlockState(net.minecraft.block.BlockState) Vector2f(net.minecraft.util.math.vector.Vector2f) Direction(net.minecraft.util.Direction)

Aggregations

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