Jump to content

Recommended Posts

Posted

Hello guys,

 

I have a small problem. When I am rendering my block in inventory it's darker then when it's placed:

 

9i6E1vi.png

 

I tried to use tessellator.setBrightness(...); , but it was even darker no matter how big the number was. Can you tell me what range of numbers the brightness has? Or am I doing something else wrong?

 

Renderer class:

package morelights.renderers;

import org.lwjgl.opengl.GL11;

import morelights.lib.Pix;
import morelights.proxy.ClientProxy;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class ModernDecLampRenderer implements ISimpleBlockRenderingHandler {

@Override
public void renderInventoryBlock(Block block, int metadata, int modelID,
		RenderBlocks renderer) {
	Tessellator tes = Tessellator.instance;

    tes.startDrawingQuads();
    
    tes.addTranslation(-0.5F, -0.3F, -0.5F);
    //tes.setBrightness(16);

	int x = 0;
	int y = 0;
	int z = 0;

	Icon icon = block.getIcon(0, 0);

	double minU = icon.getMinU();
	double maxU = icon.getMaxU();
	double minV = icon.getMinV();
	double maxV = icon.getMaxV();
	double p = (maxU - minU) / 32;
	double pv = (maxV - minV) / 32;

	//STAND
	this.renderPosZStand(tes, x, y, z, minU, maxU, minV, maxV, p, pv);
	this.renderNegZStand(tes, x, y, z, minU, maxU, minV, maxV, p, pv);
	this.renderPosXStand(tes, x, y, z, minU, maxU, minV, maxV, p, pv);
	this.renderNegXStand(tes, x, y, z, minU, maxU, minV, maxV, p, pv);
	this.rednerTopStand(tes, x, y, z, minU, maxU, minV, maxV, p, pv);

	//STAND2
	this.renderPosZStand2(tes, x, y, z, minU, minV, p, pv);
	this.renderNegZStand2(tes, x, y, z, minU, minV, p, pv);
	this.renderPosXStand2(tes, x, y, z, minU, minV, p, pv);
	this.renderNegXStand2(tes, x, y, z, minU, minV, p, pv);

	//LIGHT
	this.renderPosZLight(tes, x, y, z, minU, minV, p, pv);
	this.renderNegZLight(tes, x, y, z, minU, minV, p, pv);
	this.renderPosXLight(tes, x, y, z, minU, minV, p, pv);
	this.renderNegXLight(tes, x, y, z, minU, minV, p, pv);
	this.renderTopLight(tes, x, y, z, minU, minV, p, pv);
	this.renderBottomLight(tes, x, y, z, minU, minV, p, pv);

	tes.addTranslation(0.5F, 0.3F, 0.5F);

    tes.draw();
}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {

	Tessellator tes = Tessellator.instance;
	int lightValue = block.getMixedBrightnessForBlock(world, x, y, z);
	tes.setBrightness(lightValue);
	tes.setColorOpaque_F(1.0F, 1.0F, 1.0F);

	Icon icon = block.getIcon(0, 0);

	double minU = icon.getMinU();
	double maxU = icon.getMaxU();
	double minV = icon.getMinV();
	double maxV = icon.getMaxV();
	double p = (maxU - minU) / 32;
	double pv = (maxV - minV) / 32;

	//STAND
	this.renderPosZStand(tes, x, y, z, minU, maxU, minV, maxV, p, pv);
	this.renderNegZStand(tes, x, y, z, minU, maxU, minV, maxV, p, pv);
	this.renderPosXStand(tes, x, y, z, minU, maxU, minV, maxV, p, pv);
	this.renderNegXStand(tes, x, y, z, minU, maxU, minV, maxV, p, pv);
	this.rednerTopStand(tes, x, y, z, minU, maxU, minV, maxV, p, pv);

	//STAND2
	this.renderPosZStand2(tes, x, y, z, minU, minV, p, pv);
	this.renderNegZStand2(tes, x, y, z, minU, minV, p, pv);
	this.renderPosXStand2(tes, x, y, z, minU, minV, p, pv);
	this.renderNegXStand2(tes, x, y, z, minU, minV, p, pv);

	//LIGHT
	this.renderPosZLight(tes, x, y, z, minU, minV, p, pv);
	this.renderNegZLight(tes, x, y, z, minU, minV, p, pv);
	this.renderPosXLight(tes, x, y, z, minU, minV, p, pv);
	this.renderNegXLight(tes, x, y, z, minU, minV, p, pv);
	this.renderTopLight(tes, x, y, z, minU, minV, p, pv);
	this.renderBottomLight(tes, x, y, z, minU, minV, p, pv);


	return true;
}

private void renderBottomLight(Tessellator tes, int x, int y, int z,
		double minU, double minV, double p, double pv) {
	double X = x + Pix.FOUR + (Pix.ONE/2);
	double Z = z + Pix.FOUR + (Pix.ONE/2);
	double Y = y + Pix.FIVE;
	minU += 21*p;
	minV += 16*pv;
	double maxU = minU + 7*p;
	double maxV = minV + 7*pv;
	tes.addVertexWithUV(X, Y, Z, minU, minV);
	tes.addVertexWithUV(X + Pix.SEVEN, Y, Z, maxU, minV);
	tes.addVertexWithUV(X + Pix.SEVEN, Y, Z + Pix.SEVEN, maxU, maxV);
	tes.addVertexWithUV(X, Y, Z + Pix.SEVEN, minU, maxV);
}

private void renderTopLight(Tessellator tes, int x, int y, int z,
		double minU, double minV, double p, double pv) {
	double X = x + Pix.FOUR + (Pix.ONE/2);
	double Z = z + Pix.FOUR + (Pix.ONE/2);
	double Y = y + Pix.TWELVE;
	minV += 16*pv;
	double maxU = minU + 7*p;
	double maxV = minV + 7*pv;
	tes.addVertexWithUV(X, Y, Z + Pix.SEVEN, minU, maxV);
	tes.addVertexWithUV(X + Pix.SEVEN, Y, Z + Pix.SEVEN, maxU, maxV);
	tes.addVertexWithUV(X + Pix.SEVEN, Y, Z, maxU, minV);
	tes.addVertexWithUV(X, Y, Z, minU, minV);
}

private void renderNegXLight(Tessellator tes, int x, int y, int z,
		double minU, double minV, double p, double pv) {
	double X = x + Pix.ELEVEN + (Pix.ONE/2);
	double Y = y + Pix.FIVE;
	double Z = z + Pix.ELEVEN + (Pix.ONE/2);
	minU += 14*p;
	minV += 17*pv;
	double maxU = minU + 7*p;
	double maxV = minV + 7*pv;
	tes.addVertexWithUV(X, Y, Z - Pix.SEVEN, maxU, minV);
	tes.addVertexWithUV(X, Y + Pix.SEVEN, Z - Pix.SEVEN, maxU, maxV);
	tes.addVertexWithUV(X, Y + Pix.SEVEN, Z, minU, maxV);
	tes.addVertexWithUV(X, Y, Z, minU, minV);
}

private void renderPosXLight(Tessellator tes, int x, int y, int z,
		double minU, double minV, double p, double pv) {
	double X = x + Pix.FOUR + (Pix.ONE/2);
	double Y = y + Pix.FIVE;
	double Z = z + Pix.ELEVEN + (Pix.ONE/2);
	minU += 7*p;
	minV += 17*pv;
	double maxU = minU + 7*p;
	double maxV = minV + 7*pv;
	tes.addVertexWithUV(X, Y, Z, minU, minV);
	tes.addVertexWithUV(X, Y + Pix.SEVEN, Z, minU, maxV);
	tes.addVertexWithUV(X, Y + Pix.SEVEN, Z - Pix.SEVEN, maxU, maxV);
	tes.addVertexWithUV(X, Y, Z - Pix.SEVEN, maxU, minV);
}

private void renderNegZLight(Tessellator tes, int x, int y, int z,
		double minU, double minV, double p, double pv) {
	double X = x + Pix.FOUR + (Pix.ONE/2);
	double Y = y + Pix.FIVE;
	double Z = z + Pix.ELEVEN + (Pix.ONE/2);
	minU += 14*p;
	minV += 10*pv;
	double maxU = minU + 7*p;
	double maxV = minV + 7*pv;
	tes.addVertexWithUV(X + Pix.SEVEN, Y, Z, maxU, minV);
	tes.addVertexWithUV(X + Pix.SEVEN, Y + Pix.SEVEN, Z, maxU, maxV);
	tes.addVertexWithUV(X, Y + Pix.SEVEN, Z, minU, maxV);
	tes.addVertexWithUV(X, Y, Z, minU, minV);
}

private void renderPosZLight(Tessellator tes, int x, int y, int z,
		double minU, double minV, double p, double pv) {
	double X = x + Pix.FOUR + (Pix.ONE/2);
	double Y = y + Pix.FIVE;
	double Z = z + Pix.FOUR + (Pix.ONE/2);
	minU += 7*p;
	minV += 10*pv;
	double maxU = minU + 7*p;
	double maxV = minV + 7*pv;
	tes.addVertexWithUV(X, Y, Z, minU, minV);
	tes.addVertexWithUV(X, Y + Pix.SEVEN, Z, minU, maxV);
	tes.addVertexWithUV(X + Pix.SEVEN, Y + Pix.SEVEN, Z, maxU, maxV);
	tes.addVertexWithUV(X + Pix.SEVEN, Y, Z, maxU, minV);
}

private void renderNegXStand2(Tessellator tes, int x, int y, int z,
		double minU, double minV, double p, double pv) {
	double X = x + Pix.TEN;
	double Y = y + Pix.TWO;
	double Z = z + Pix.TEN;
	minU += 20*p;
	minV += 2*pv;
	double maxU = minU + 4*p;
	double maxV = minV + 4*pv;
	tes.addVertexWithUV(X, Y, Z - Pix.FOUR, maxU, minV);
	tes.addVertexWithUV(X, Y + Pix.FOUR, Z - Pix.FOUR, maxU, maxV);
	tes.addVertexWithUV(X, Y + Pix.FOUR, Z, minU, maxV);
	tes.addVertexWithUV(X, Y, Z, minU, minV);
}

private void renderPosXStand2(Tessellator tes, int x, int y, int z,
		double minU, double minV, double p, double pv) {
	double X = x + Pix.SIX;
	double Y = y + Pix.TWO;
	double Z = z + Pix.TEN;
	minU += 12*p;
	minV += 2*pv;
	double maxU = minU + 4*p;
	double maxV = minV + 4*pv;
	tes.addVertexWithUV(X, Y, Z, minU, minV);
	tes.addVertexWithUV(X, Y + Pix.FOUR, Z, minU, maxV);
	tes.addVertexWithUV(X, Y + Pix.FOUR, Z - Pix.FOUR, maxU, maxV);
	tes.addVertexWithUV(X, Y, Z - Pix.FOUR, maxU, minV);
}

private void renderNegZStand2(Tessellator tes, int x, int y, int z,
		double minU, double minV, double p, double pv) {
	double X = x + Pix.SIX;
	double Y = y + Pix.TWO;
	double Z = z + Pix.TEN;
	minU += 16*p;
	minV += 2*pv;
	tes.addVertexWithUV(X + Pix.FOUR, Y, Z, minU + 4*p, minV);
	tes.addVertexWithUV(X + Pix.FOUR, Y + Pix.FOUR, Z, minU + 4*p, minV + 4*pv);
	tes.addVertexWithUV(X, Y + Pix.FOUR, Z, minU, minV + 4*pv);
	tes.addVertexWithUV(X, Y, Z, minU, minV);
}

private void renderPosZStand2(Tessellator tes, int x, int y, int z,
		double minU, double minV, double p, double pv) {
	double X = x + Pix.SIX;
	double Y = y + Pix.TWO;
	double Z = z + Pix.SIX;
	minU += 8*p;
	minV += 2*pv;
	tes.addVertexWithUV(X, Y, Z, minU, minV);
	tes.addVertexWithUV(X, Y + Pix.FOUR, Z, minU, minV + 4*pv);
	tes.addVertexWithUV(X + Pix.FOUR, Y + Pix.FOUR, Z, minU + 4*p, minV + 4*pv);
	tes.addVertexWithUV(X + Pix.FOUR, Y, Z, minU + 4*p, minV);
}

private void rednerTopStand(Tessellator tes, int X, int Y, int Z,
		double minU, double maxU, double minV, double maxV, double p, double pv) {
	double x = X + Pix.FOUR;
	double z = Z + Pix.FOUR;
	double y = Y + Pix.TWO;
	minV += 2*pv; 
	tes.addVertexWithUV(x, y, z + Pix.EIGHT, minU + 8*p, minV);
	tes.addVertexWithUV(x + Pix.EIGHT, y, z + Pix.EIGHT, minU, minV);
	tes.addVertexWithUV(x + Pix.EIGHT, y, z, minU, minV + 8*pv);
	tes.addVertexWithUV(x, y, z, minU + 8*p, minV + 8*pv);
}

private void renderNegXStand(Tessellator tes, int X, int y, int Z, double minU,
		double maxU, double minV, double maxV, double p, double pv) 
{
	double x = X + Pix.FOUR;
	double z = Z + Pix.TWELVE;
	minU += 24*p;
	tes.addVertexWithUV(x, y, z, minU, minV + 2*pv);
	tes.addVertexWithUV(x, y + Pix.TWO, z, minU, minV);
	tes.addVertexWithUV(x, y + Pix.TWO, z - Pix.EIGHT, minU + 8*p, minV);
	tes.addVertexWithUV(x, y, z - Pix.EIGHT, minU + 8*p, minV + 2*pv);
}

private void renderPosXStand(Tessellator tes, int X, int y, int Z, double minU,
		double maxU, double minV, double maxV, double p, double pv) 
{
	double x = X + Pix.TWELVE;
	double z = Z + Pix.TWELVE;
	minU += 8*p;
	tes.addVertexWithUV(x, y, z - Pix.EIGHT, minU + 8*p, minV + 2*pv);
	tes.addVertexWithUV(x, y + Pix.TWO, z - Pix.EIGHT, minU + 8*p, minV);
	tes.addVertexWithUV(x, y + Pix.TWO, z, minU, minV);
	tes.addVertexWithUV(x, y, z, minU, minV + 2*pv);
}

private void renderNegZStand(Tessellator tes, int x, int y, int z, double minU,
		double maxU, double minV, double maxV, double p, double pv) 
{
	double offX = x + Pix.FOUR;
	double offZ = z + Pix.TWELVE;
	tes.addVertexWithUV(offX + Pix.EIGHT, y, offZ, minU + 8*p, minV +2*pv);
	tes.addVertexWithUV(offX + Pix.EIGHT, y + Pix.TWO, offZ, minU + 8*p, minV);
	tes.addVertexWithUV(offX, y + Pix.TWO, offZ, minU, minV);
	tes.addVertexWithUV(offX, y, offZ, minU, minV + 2*pv);
}

private void renderPosZStand(Tessellator tes, int x, int y, int z, double minU, double maxU, double minV, double maxV, double p, double pv)
{
	double offX = x + Pix.FOUR;
	double offZ = z + Pix.FOUR;
	minU += 16*p;
	tes.addVertexWithUV(offX, y, offZ, minU, minV + 2*pv);
	tes.addVertexWithUV(offX, y + Pix.TWO, offZ, minU, minV);
	tes.addVertexWithUV(offX + Pix.EIGHT, y + Pix.TWO, offZ, minU + 8*p, minV);
	tes.addVertexWithUV(offX + Pix.EIGHT, y, offZ, minU + 8*p, minV +2*pv);
}

@Override
public boolean shouldRender3DInInventory() {
	return true;
}

@Override
public int getRenderId() {
	return ClientProxy.ModernDecLampType;
}

}

If someone helps you, click that thank you button ;)

 

EasyTessellator library: http://www.minecraftforge.net/forum/index.php/topic,14705.0.html

Posted

Hi

 

Rendering in inventory doesn't use block brightness settings, it uses "normals" instead.  See RenderBlocks.renderBlockAsItem

eg

                tessellator.startDrawingQuads();
                tessellator.setNormal(0.0F, -1.0F, 0.0F);
                this.renderFaceYNeg(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 0));
                tessellator.draw();
                tessellator.startDrawingQuads();
                tessellator.setNormal(0.0F, 1.0F, 0.0F);
                this.renderFaceYPos(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 1));
                tessellator.draw();
                tessellator.startDrawingQuads();
                tessellator.setNormal(0.0F, 0.0F, -1.0F);
                this.renderFaceZNeg(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 2));
                tessellator.draw();
                tessellator.startDrawingQuads();
                tessellator.setNormal(0.0F, 0.0F, 1.0F);
                this.renderFaceZPos(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 3));
                tessellator.draw();
                tessellator.startDrawingQuads();
                tessellator.setNormal(-1.0F, 0.0F, 0.0F);
                this.renderFaceXNeg(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 4));
                tessellator.draw();
                tessellator.startDrawingQuads();
                tessellator.setNormal(1.0F, 0.0F, 0.0F);
                this.renderFaceXPos(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 5));
                tessellator.draw();

see also this link at the end of the page

http://greyminecraftcoder.blogspot.com.au/2013/09/custom-item-rendering-using.html

 

-TGG

 

-TGG

 

 

Posted

There's also Tessellator#setBrightness(int)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Hi

 

Rendering in inventory doesn't use block brightness settings, it uses "normals" instead.  See RenderBlocks.renderBlockAsItem

eg

                tessellator.startDrawingQuads();
                tessellator.setNormal(0.0F, -1.0F, 0.0F);
                this.renderFaceYNeg(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 0));
                tessellator.draw();
                tessellator.startDrawingQuads();
                tessellator.setNormal(0.0F, 1.0F, 0.0F);
                this.renderFaceYPos(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 1));
                tessellator.draw();
                tessellator.startDrawingQuads();
                tessellator.setNormal(0.0F, 0.0F, -1.0F);
                this.renderFaceZNeg(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 2));
                tessellator.draw();
                tessellator.startDrawingQuads();
                tessellator.setNormal(0.0F, 0.0F, 1.0F);
                this.renderFaceZPos(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 3));
                tessellator.draw();
                tessellator.startDrawingQuads();
                tessellator.setNormal(-1.0F, 0.0F, 0.0F);
                this.renderFaceXNeg(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 4));
                tessellator.draw();
                tessellator.startDrawingQuads();
                tessellator.setNormal(1.0F, 0.0F, 0.0F);
                this.renderFaceXPos(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 5));
                tessellator.draw();

see also this link at the end of the page

http://greyminecraftcoder.blogspot.com.au/2013/09/custom-item-rendering-using.html

 

-TGG

 

-TGG

 

Thanks that worked! :)

If someone helps you, click that thank you button ;)

 

EasyTessellator library: http://www.minecraftforge.net/forum/index.php/topic,14705.0.html

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.