net.minecraftforge.client.model.pipeline.LightUtil Java Examples

The following examples show how to use net.minecraftforge.client.model.pipeline.LightUtil. 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: RenderUtils.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Reimplement vanilla item so we can draw pearl stacks with opacity support.
 * + FIX THE OPACITY RENDERING.
 */
private static void renderQuads(BufferBuilder renderer, List<BakedQuad> quads, int color, ItemStack stack) {
	color &= 0xFF000000;
	boolean flag = !stack.isEmpty();
	int i = 0;

	for (int j = quads.size(); i < j; ++i) {
		BakedQuad bakedquad = quads.get(i);
		int k = color | 0xFFFFFF;

		if (flag && bakedquad.hasTintIndex()) {
			k = Minecraft.getMinecraft().getItemColors().colorMultiplier(stack, bakedquad.getTintIndex());

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

			k &= 0xFFFFFF;
			k |= color;
		}

		LightUtil.renderQuadColor(renderer, bakedquad, k);
	}
}
 
Example #2
Source File: AbstractBakedPropertiesModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected boolean checkDepth(BakedQuad quad, Vector3 hit, Direction hitFace) {
    int[] quadData = quad.getVertexData();
    CachedFormat format = CachedFormat.lookup(DefaultVertexFormats.BLOCK);

    Vector3 posVec = new Vector3();
    float[] pos = new float[4];
    for (int v = 0; v < 4; v++) {
        LightUtil.unpack(quadData, pos, format.format, v, format.positionIndex);
        posVec.add(pos[0], pos[1], pos[2]);
    }
    posVec.divide(4);

    double diff = 0;
    switch (hitFace.getAxis()) {
        case X:
            diff = Math.abs(hit.x - posVec.x);
            break;
        case Y:
            diff = Math.abs(hit.y - posVec.y);
            break;
        case Z:
            diff = Math.abs(hit.z - posVec.z);
            break;
    }
    return !(diff > 0.01);
}
 
Example #3
Source File: Quad.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Bakes this Quad to a BakedQuad.
 *
 * @return The BakedQuad.
 */
public BakedQuad bake() {
    if (format.format != DefaultVertexFormats.BLOCK) {
        throw new IllegalStateException("Unable to bake this quad to the specified format. " + format.format);
    }
    int[] packedData = new int[format.format.getSize()];
    for (int v = 0; v < 4; v++) {
        for (int e = 0; e < format.elementCount; e++) {
            LightUtil.pack(vertices[v].raw[e], packedData, format.format, v, e);
        }
    }
    return new BakedQuad(packedData, tintIndex, orientation, sprite, diffuseLighting);
}
 
Example #4
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 #5
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 #6
Source File: VertexDataUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static float[][] unpackElements(int[] packed, VertexFormat format, VertexFormatElement element) {
    float[][] data = new float[4][4];
    int e = getElement(format, element);
    for (int v = 0; v < 4; v++) {
        LightUtil.unpack(packed, data[v], format, v, e);
    }
    return data;
}
 
Example #7
Source File: BuildersWandRenderer.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void renderQuads(final IBlockState state, final BlockPos pos, final BufferBuilder buffer, final List<BakedQuad> quads, final int alpha)
{
    final int size = quads.size();

    for (int i = 0; i < size; i++)
    {
        final BakedQuad quad = quads.get(i);
        final int color = quad.getTintIndex() == -1 ? alpha | 0xffffff : this.getTint(state, pos, alpha, quad.getTintIndex());
        LightUtil.renderQuadColor(buffer, quad, color);
    }
}
 
Example #8
Source File: WorldSceneRenderer.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Renders scene on given coordinates with given width and height, and RGB background color
 * Note that this will ignore any transformations applied currently to projection/view matrix,
 * so specified coordinates are scaled MC gui coordinates.
 * It will return matrices of projection and view in previous state after rendering
 */
public void render(int x, int y, int width, int height, int backgroundColor) {
    Vec2f mousePosition = setupCamera(x, y, width, height, backgroundColor);
    if (renderCallback != null) {
        renderCallback.preRenderScene(this);
    }
    Minecraft minecraft = Minecraft.getMinecraft();
    minecraft.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    BlockRendererDispatcher dispatcher = minecraft.getBlockRendererDispatcher();
    BlockRenderLayer oldRenderLayer = MinecraftForgeClient.getRenderLayer();
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferBuilder = tessellator.getBuffer();

    bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    for (BlockPos pos : renderedBlocks) {
        if (renderFilter != null && !renderFilter.test(pos))
            continue; //do not render if position is skipped
        IBlockState blockState = world.getBlockState(pos);
        for(BlockRenderLayer renderLayer : BlockRenderLayer.values()) {
            if (!blockState.getBlock().canRenderInLayer(blockState, renderLayer)) continue;
            ForgeHooksClient.setRenderLayer(renderLayer);
            dispatcher.renderBlock(blockState, pos, world, bufferBuilder);
        }
    }
    tessellator.draw();
    ForgeHooksClient.setRenderLayer(oldRenderLayer);

    if (mousePosition != null) {
        this.lastHitBlock = handleMouseHit(mousePosition);
    } else {
        this.lastHitBlock = null;
    }

    if (lastHitBlock != null) {
        GlStateManager.disableTexture2D();
        CCRenderState renderState = CCRenderState.instance();
        renderState.startDrawing(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR, tessellator.getBuffer());
        ColourMultiplier multiplier = new ColourMultiplier(0);
        renderState.setPipeline(new Translation(lastHitBlock), multiplier);
        BlockFace blockFace = new BlockFace();
        renderState.setModel(blockFace);
        for (EnumFacing renderSide : EnumFacing.VALUES) {
            float diffuse = LightUtil.diffuseLight(renderSide);
            int color = (int) (255 * diffuse);
            multiplier.colour = RenderUtil.packColor(color, color, color, 100);
            blockFace.loadCuboidFace(Cuboid6.full, renderSide.getIndex());
            renderState.render();
        }
        renderState.draw();
        GlStateManager.enableTexture2D();
    }

    resetCamera();
}
 
Example #9
Source File: RenderInfestedLeaves.java    From ExNihiloAdscensio with MIT License 4 votes vote down vote up
@Override
public void renderTileEntityAt(TileInfestedLeaves tile, double x, double y, double z, float partialTicks, int destroyStage)
{
    if(tile != null)
    {
        long seed = tile.getWorld().rand.nextLong();
        int color = tile.getColor();
        
        IBlockState leafBlock = tile.getLeafBlock();
        IBakedModel leafModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(leafBlock);
        
        if(leafModel == null)
        {
            leafModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(Blocks.LEAVES.getDefaultState());
        }
        
        List<BakedQuad> leafQuads = Lists.newArrayList();
        
        for(EnumFacing side : EnumFacing.VALUES)
        {
            if(leafBlock.shouldSideBeRendered(tile.getWorld(), tile.getPos(), side))
            {
                leafQuads.addAll(leafModel.getQuads(leafBlock, side, seed));
            }
        }
        
        Tessellator tessellator = Tessellator.getInstance();
        VertexBuffer buffer = tessellator.getBuffer();
        
        bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        
        GlStateManager.pushMatrix();
        GlStateManager.translate(x, y, z);
        RenderHelper.disableStandardItemLighting();
        
        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
        
        for(BakedQuad quad : leafQuads)
        {
            LightUtil.renderQuadColor(buffer, quad, color);
        }
        
        tessellator.draw();
        
        RenderHelper.enableStandardItemLighting();
        GlStateManager.popMatrix();
    }
}