Java Code Examples for net.minecraft.client.renderer.vertex.VertexFormat#getElements()

The following examples show how to use net.minecraft.client.renderer.vertex.VertexFormat#getElements() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VertexDataUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Gets the position for the element 'position' in the elements list for use in LightUtil.pack/unpack for a given format.
 *
 * @param format The format.
 * @return The element position, -1 if it does not exist.
 */
public static int getPositionElement(VertexFormat format) {
    List<VertexFormatElement> elements = format.getElements();
    for (int e = 0; e < elements.size(); e++) {
        if (elements.get(e).isPositionElement()) {
            return e;
        }
    }
    return -1;
}
 
Example 2
Source File: VertexDataUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Gets the position for the element 'normal' in the elements list for use in LightUtil.pack/unpack for a given format.
 *
 * @param format The format.
 * @return The element position, -1 if it does not exist.
 */
public static int getNormalElement(VertexFormat format) {
    List<VertexFormatElement> elements = format.getElements();
    for (int e = 0; e < elements.size(); e++) {
        if (elements.get(e).getUsage() == Usage.NORMAL) {
            return e;
        }
    }
    return -1;
}
 
Example 3
Source File: VertexDataUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Gets the position for the element 'uv' in the elements list for use in LightUtil.pack/unpack for a given format.
 *
 * @param format The format.
 * @return The element position, -1 if it does not exist.
 */
public static int getUVElement(VertexFormat format) {
    List<VertexFormatElement> elements = format.getElements();
    for (int e = 0; e < elements.size(); e++) {
        if (elements.get(e).getUsage() == Usage.UV && elements.get(e).getIndex() == 0) {
            return e;
        }
    }
    return -1;
}
 
Example 4
Source File: VertexDataUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Gets the position for the element provided in the elements list for use in LightUtil.pack/unpack for a given format.
 *
 * @param format  The format.
 * @param element THe element to get.
 * @return The element position, -1 if it does not exist.
 */
public static int getElement(VertexFormat format, VertexFormatElement element) {
    List<VertexFormatElement> elements = format.getElements();
    for (int e = 0; e < elements.size(); e++) {
        if (elements.get(e).equals(element)) {
            return e;
        }
    }
    return -1;
}
 
Example 5
Source File: VertexDataUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void fullyPackQuads(int[] packedData, float[][][] unpackedData, VertexFormat format) {
    List<VertexFormatElement> elements = format.getElements();
    for (int e = 0; e < elements.size(); e++) {
        for (int v = 0; v < 4; v++) {
            LightUtil.pack(unpackedData[v][e], packedData, format, v, e);
        }
    }
}
 
Example 6
Source File: VertexDataUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void fullyUnPackQuads(int[] packedData, float[][][] unpackedData, VertexFormat format) {
    List<VertexFormatElement> elements = format.getElements();
    for (int e = 0; e < elements.size(); e++) {
        for (int v = 0; v < 4; v++) {
            LightUtil.unpack(packedData, unpackedData[v][e], format, v, e);
        }
    }
}
 
Example 7
Source File: CachedFormat.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Caches the vertex format element indexes for efficiency.
 *
 * @param format The format.
 */
public CachedFormat(VertexFormat format) {
    this.format = format;
    List<VertexFormatElement> elements = format.getElements();
    elementCount = elements.size();
    for (int i = 0; i < elementCount; i++) {
        VertexFormatElement element = elements.get(i);
        switch (element.getUsage()) {
            case POSITION:
                if (hasPosition) {
                    throw new IllegalStateException("Found 2 position elements..");
                }
                hasPosition = true;
                positionIndex = i;
                break;
            case NORMAL:
                if (hasNormal) {
                    throw new IllegalStateException("Found 2 normal elements..");
                }
                hasNormal = true;
                normalIndex = i;
                break;
            case COLOR:
                if (hasColor) {
                    throw new IllegalStateException("Found 2 color elements..");
                }
                hasColor = true;
                colorIndex = i;
                break;
            case UV:
                switch (element.getIndex()) {
                    case 0:
                        if (hasUV) {
                            throw new IllegalStateException("Found 2 UV elements..");
                        }
                        hasUV = true;
                        uvIndex = i;
                        break;
                    case 1:
                        if (hasOverlay) {
                            throw new IllegalStateException("Found 2 Overlay elements..");
                        }
                        hasOverlay = true;
                        overlayIndex = i;
                        break;
                    case 2:
                        if (hasLightMap) {
                            throw new IllegalStateException("Found 2 LightMap elements..");
                        }
                        hasLightMap = true;
                        lightMapIndex = i;
                        break;
                }
                break;
        }
    }
}