Java Code Examples for net.minecraft.client.renderer.BufferBuilder#addVertexData()

The following examples show how to use net.minecraft.client.renderer.BufferBuilder#addVertexData() . 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: BlockModelRendererSchematic.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void renderQuadsSmooth(IBlockAccess blockAccessIn, IBlockState stateIn, BlockPos posIn, BufferBuilder buffer, List<BakedQuad> list, float[] quadBounds, BitSet bitSet, AmbientOcclusionFace aoFace)
{
    Vec3d vec3d = stateIn.getOffset(blockAccessIn, posIn);
    double x = (double)posIn.getX() + vec3d.x;
    double y = (double)posIn.getY() + vec3d.y;
    double z = (double)posIn.getZ() + vec3d.z;
    int i = 0;

    for (int j = list.size(); i < j; ++i)
    {
        BakedQuad bakedquad = list.get(i);
        this.fillQuadBounds(stateIn, bakedquad.getVertexData(), bakedquad.getFace(), quadBounds, bitSet);
        aoFace.updateVertexBrightness(blockAccessIn, stateIn, posIn, bakedquad.getFace(), quadBounds, bitSet);
        buffer.addVertexData(bakedquad.getVertexData());
        buffer.putBrightness4(aoFace.vertexBrightness[0], aoFace.vertexBrightness[1], aoFace.vertexBrightness[2], aoFace.vertexBrightness[3]);

        if (bakedquad.hasTintIndex())
        {
            int k = this.blockColors.colorMultiplier(stateIn, blockAccessIn, posIn, bakedquad.getTintIndex());

            if (EntityRenderer.anaglyphEnable)
            {
                k = TextureUtil.anaglyphColor(k);
            }

            float f = (float)(k >> 16 & 255) / 255.0F;
            float f1 = (float)(k >> 8 & 255) / 255.0F;
            float f2 = (float)(k & 255) / 255.0F;
            buffer.putColorMultiplier(aoFace.vertexColorMultiplier[0] * f, aoFace.vertexColorMultiplier[0] * f1, aoFace.vertexColorMultiplier[0] * f2, 4);
            buffer.putColorMultiplier(aoFace.vertexColorMultiplier[1] * f, aoFace.vertexColorMultiplier[1] * f1, aoFace.vertexColorMultiplier[1] * f2, 3);
            buffer.putColorMultiplier(aoFace.vertexColorMultiplier[2] * f, aoFace.vertexColorMultiplier[2] * f1, aoFace.vertexColorMultiplier[2] * f2, 2);
            buffer.putColorMultiplier(aoFace.vertexColorMultiplier[3] * f, aoFace.vertexColorMultiplier[3] * f1, aoFace.vertexColorMultiplier[3] * f2, 1);
        }
        else
        {
            buffer.putColorMultiplier(aoFace.vertexColorMultiplier[0], aoFace.vertexColorMultiplier[0], aoFace.vertexColorMultiplier[0], 4);
            buffer.putColorMultiplier(aoFace.vertexColorMultiplier[1], aoFace.vertexColorMultiplier[1], aoFace.vertexColorMultiplier[1], 3);
            buffer.putColorMultiplier(aoFace.vertexColorMultiplier[2], aoFace.vertexColorMultiplier[2], aoFace.vertexColorMultiplier[2], 2);
            buffer.putColorMultiplier(aoFace.vertexColorMultiplier[3], aoFace.vertexColorMultiplier[3], aoFace.vertexColorMultiplier[3], 1);
        }

        buffer.putPosition(x, y, z);
    }
}
 
Example 2
Source File: BlockModelRendererSchematic.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void renderQuadsFlat(IBlockAccess blockAccessIn, IBlockState stateIn, BlockPos posIn, int brightnessIn, boolean ownBrightness, BufferBuilder buffer, List<BakedQuad> list, BitSet bitSet)
{
    Vec3d vec3d = stateIn.getOffset(blockAccessIn, posIn);
    double d0 = (double)posIn.getX() + vec3d.x;
    double d1 = (double)posIn.getY() + vec3d.y;
    double d2 = (double)posIn.getZ() + vec3d.z;
    int i = 0;

    for (int j = list.size(); i < j; ++i)
    {
        BakedQuad bakedquad = list.get(i);

        if (ownBrightness)
        {
            this.fillQuadBounds(stateIn, bakedquad.getVertexData(), bakedquad.getFace(), (float[])null, bitSet);
            BlockPos blockpos = bitSet.get(0) ? posIn.offset(bakedquad.getFace()) : posIn;
            brightnessIn = stateIn.getPackedLightmapCoords(blockAccessIn, blockpos);
        }

        buffer.addVertexData(bakedquad.getVertexData());
        buffer.putBrightness4(brightnessIn, brightnessIn, brightnessIn, brightnessIn);

        if (bakedquad.hasTintIndex())
        {
            int k = this.blockColors.colorMultiplier(stateIn, blockAccessIn, posIn, bakedquad.getTintIndex());

            if (EntityRenderer.anaglyphEnable)
            {
                k = TextureUtil.anaglyphColor(k);
            }

            float f = (float)(k >> 16 & 255) / 255.0F;
            float f1 = (float)(k >> 8 & 255) / 255.0F;
            float f2 = (float)(k & 255) / 255.0F;
            buffer.putColorMultiplier(f, f1, f2, 4);
            buffer.putColorMultiplier(f, f1, f2, 3);
            buffer.putColorMultiplier(f, f1, f2, 2);
            buffer.putColorMultiplier(f, f1, f2, 1);
        }

        buffer.putPosition(d0, d1, d2);
    }
}
 
Example 3
Source File: StructureManager.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Will not draw the structure if it is not already baked. Resource reloading will re-bake if required.
 *
 * @param alpha    The transparency of the rendered structure.
 * @param location The ResourceLocation of the structure to look up.
 */
@SideOnly(Side.CLIENT)
public void draw(ResourceLocation location, float alpha) {
	HashMap<Integer, int[]> cache = vboCache.get(location);

	if (cache == null || cache.isEmpty()) {
		bake(location);
		return;
	}

	GlStateManager.pushMatrix();
	GlStateManager.enableBlend();
	GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GlStateManager.enablePolygonOffset();
	GlStateManager.doPolygonOffset(1f, -0.05f);
	//	GlStateManager.disableDepth();

	int alphaFunc = GL11.glGetInteger(GL11.GL_ALPHA_TEST_FUNC);
	float alphaRef = GL11.glGetFloat(GL11.GL_ALPHA_TEST_REF);
	GlStateManager.alphaFunc(GL11.GL_ALWAYS, 1);

	Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

	Tessellator tes = Tessellator.getInstance();
	BufferBuilder buffer = tes.getBuffer();

	for (int layerID : cache.keySet()) {

		buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
		buffer.addVertexData(cache.get(layerID));

		for (int i = 0; i < buffer.getVertexCount(); i++) {
			buffer.putColorRGBA(buffer.getColorIndex(i), 255, 255, 255, (int) (alpha * 255));
		}

		tes.draw();
	}

	GlStateManager.alphaFunc(alphaFunc, alphaRef);
	//	GlStateManager.enableDepth();
	GlStateManager.disablePolygonOffset();
	GlStateManager.color(1F, 1F, 1F, 1F);
	GlStateManager.popMatrix();
}