Search in sources :

Example 1 with CasingType

use of com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity.CasingType in project Create by Creators-of-Create.

the class BeltModel method getQuads.

@Override
public List<BakedQuad> getQuads(BlockState state, Direction side, Random rand, IModelData extraData) {
    List<BakedQuad> quads = super.getQuads(state, side, rand, extraData);
    if (!extraData.hasProperty(CASING_PROPERTY))
        return quads;
    CasingType type = extraData.getData(CASING_PROPERTY);
    if (type == CasingType.NONE || type == CasingType.BRASS)
        return quads;
    quads = new ArrayList<>(quads);
    SpriteShiftEntry spriteShift = AllSpriteShifts.ANDESIDE_BELT_CASING;
    VertexFormat format = DefaultVertexFormat.BLOCK;
    for (int i = 0; i < quads.size(); i++) {
        BakedQuad quad = quads.get(i);
        if (spriteShift == null)
            continue;
        if (quad.getSprite() != spriteShift.getOriginal())
            continue;
        TextureAtlasSprite original = quad.getSprite();
        TextureAtlasSprite target = spriteShift.getTarget();
        BakedQuad newQuad = QuadHelper.clone(quad);
        int[] vertexData = newQuad.getVertices();
        for (int vertex = 0; vertex < vertexData.length; vertex += format.getIntegerSize()) {
            int uvOffset = 16 / 4;
            int uIndex = vertex + uvOffset;
            int vIndex = vertex + uvOffset + 1;
            float u = Float.intBitsToFloat(vertexData[uIndex]);
            float v = Float.intBitsToFloat(vertexData[vIndex]);
            vertexData[uIndex] = Float.floatToRawIntBits(target.getU(SuperByteBuffer.getUnInterpolatedU(original, u)));
            vertexData[vIndex] = Float.floatToRawIntBits(target.getV(SuperByteBuffer.getUnInterpolatedV(original, v)));
        }
        quads.set(i, newQuad);
    }
    return quads;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) CasingType(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity.CasingType) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) DefaultVertexFormat(com.mojang.blaze3d.vertex.DefaultVertexFormat) VertexFormat(com.mojang.blaze3d.vertex.VertexFormat) SpriteShiftEntry(com.simibubi.create.foundation.block.render.SpriteShiftEntry)

Aggregations

DefaultVertexFormat (com.mojang.blaze3d.vertex.DefaultVertexFormat)1 VertexFormat (com.mojang.blaze3d.vertex.VertexFormat)1 CasingType (com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity.CasingType)1 SpriteShiftEntry (com.simibubi.create.foundation.block.render.SpriteShiftEntry)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1