Jump to content

Text Rendering problems with EnumChatFormatting


Bedrock_Miner

Recommended Posts

Hey Guys!

I created a sign, which can be used to write colored text. If you press a button in the GUI, a EnumChatFormatting object is added to the signs string.

 

The problem is, that the text is rendered wrong.

Here is one Text in the GUI (where everything is fine)

LqE2qds.png

And here is the same text ingame:

3O19otz.png

 

The Renderer method:

 

 

(Placed in a method extended from the Renderer superclass, shown below)

@Override
public void renderTileEntity(TileEntity te, World world, int x, int y, int z, int meta, Block block, boolean isItemRendered) {
	if (isItemRendered) {
		GL11.glScalef(1.2F, 1.2F, 1.2F);
		GL11.glTranslatef(0.0F, -0.1F, 0.4F);
	}

	this.startDrawingQuads();
	this.rotate4Steps(meta);
	this.bindMCTexture(((ModBlockLargeSign)block).getBacksideName());
	this.setNormal(0.0F, 0.0F, -1.0F);
	this.renderFace(0.0D, 0.0D, 0.0D, 1.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.0D, 0.0D, 1.0D, 0.0D);
	this.setNormal(0.0F, 1.0F, 0.0F);
	this.renderFaceTexCut(1.0D, 0.125D, 0.0D, 1.0D, 0.0D, 1.0D, 1.0D, 0.0D, 1.0D, 1.0D, 0.125D, 0.0D, 1.0D, 0.125D);
	this.setNormal(0.0F, -1.0F, 0.0F);
	this.renderFaceTexCut(1.0D, 0.125D, 0.0D, 0.0D, 0.125D, 1.0D, 0.0D, 0.125D, 1.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
	this.setNormal(1.0F, 0.0F, 0.0F);
	this.renderFaceTexCut(0.125D, 1.0D, 0.0D, 0.0D, 0.125D, 0.0D, 0.0D, 0.0D, 0.0D, 1.0D, 0.0D, 0.0D, 1.0D, 0.125D);
	this.setNormal(-1.0F, 0.0F, 0.0F);
	this.renderFaceTexCut(0.125D, 1.0D, 1.0D, 0.0D, 0.0D, 1.0D, 0.0D, 0.125D, 1.0D, 1.0D, 0.125D, 1.0D, 1.0D, 0.0D);
	this.finishDrawing();
	this.startDrawingQuads();
	this.setNormal(0.0F, 0.0F, 1.0F);
	this.bindModTexture(((ModBlockLargeSign)block).getFrontsideName());
	this.renderFace(1.0D, 0.0D, 0.125D, 0.0D, 0.0D, 0.125D, 0.0D, 1.0D, 0.125D, 1.0D, 1.0D, 0.125D);
	this.finishDrawing();

	if (!isItemRendered) {
		FontRenderer f = this.func_147498_b();
		TileEntityLargeSign tile = (TileEntityLargeSign)te;

		float scale = 0.01F;
		GL11.glTranslatef(0.5F, 0.5F, 0.5F);
		GL11.glScalef(scale, -scale, scale);
		GL11.glTranslatef(0.0F, 0.0F, -0.374F / scale);

		for (int i = 0; i < 6; i ++) {
			String s = tile.getCurrentText()[i];
			if (s != "")
				f.drawString(s, -f.getStringWidth(s) / 2, i*16 - 45, 0); //Color is set to 0 to render in black by default!
		}
	}
}

 

 

The Renderer Superclass:

 

 

Only the things at the top are important.

package com.bedrockminer.signcraft.client.renderer.block;

import org.lwjgl.opengl.GL11;

import com.bedrockminer.signcraft.Main;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public abstract class ModTileEntityRenderer extends TileEntitySpecialRenderer {

protected Tessellator t;

@Override
/**
 * Initializes the renderer and overrides the abstract method
 */
    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float f) {
	GL11.glPushMatrix();
	GL11.glTranslated(x, y, z);
	this.t = Tessellator.instance;

	int teX = te.xCoord;
	int teY = te.yCoord;
	int teZ = te.zCoord;
	World world = te.getWorldObj();

	Block block = te.getBlockType();

	float bright = block.getMixedBrightnessForBlock(world, teX, teY, teZ);
	int l = world.getLightBrightnessForSkyBlocks(teX, teY, teZ, 0);
	int l1 = l % 65536;
	int l2 = l / 65536;
	this.t.setColorOpaque_F(bright, bright, bright);
	OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, l1, l2);

	int meta = te.blockMetadata;

        GL11.glPushMatrix();
	renderTileEntity(te, te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, meta, te.getWorldObj().getBlock(te.xCoord, te.yCoord, te.zCoord), false);
        GL11.glPopMatrix();
        GL11.glPopMatrix();
    }

public void renderTileEntityAsItem(TileEntity te, ItemStack stack) {
	GL11.glPushMatrix();
	this.field_147501_a = TileEntityRendererDispatcher.instance;

	this.t = Tessellator.instance;

	this.t.setColorOpaque_F(1.0F, 1.0F, 1.0F);

	int meta = stack.getItemDamage();

        GL11.glPushMatrix();
	renderTileEntity(te, null, 0, 0, 0, meta, Block.getBlockFromItem(stack.getItem()), true);
        GL11.glPopMatrix();
        GL11.glPopMatrix();
}

    public abstract void renderTileEntity(TileEntity te, World world, int x, int y, int z, int meta, Block block, boolean isItemRendered);
    
    /**
     * Sets the texture of the renderer to a new Texture in the folder named like the modid
     */
    protected void bindModTexture(String texture) {
    	bindTexture(Main.MODID, texture);
    }
    
    /**
     * Sets the texture of the renderer to a new Texture from Minecraft
     */
    protected void bindMCTexture(String texture) {
    	bindTexture("minecraft", texture);
    }
    
    /**
     * Sets the texture of the renderer to a new Texture
     */
    protected void bindTexture(String modid, String texture) {
    	this.bindTexture(new ResourceLocation(modid, texture));
    }
    
    /**
     * executes startDrawingQuads of the tessellator
     */
    protected void startDrawingQuads() { 
    	this.t.startDrawingQuads();
    }
    
    /**
     * executes draw of the tessellator
     */
    protected void finishDrawing() {
    	this.t.draw();
    }
    
    /**
     * Rotates the renderer by 90° for each step
     */
    protected void rotate4Steps(int steps) {
    	GL11.glTranslatef(0.5F, 0, 0.5F);
        GL11.glRotatef(steps * -90F, 0F, 1F, 0F);
        GL11.glTranslatef(-0.5F, 0, -0.5F);
    }
    
    /**
     * Rotates the renderer by 45° for each step
     */
    protected void rotate8Steps(int steps) {
    	GL11.glTranslatef(0.5F, 0, 0.5F);
        GL11.glRotatef(steps * -45F, 0F, 1F, 0F);
        GL11.glTranslatef(-0.5F, 0, -0.5F);
    }
    
    /**
     * Rotates the renderer by 22.5° for each step
     */
    protected void rotate16Steps(int steps) {
    	GL11.glTranslatef(0.5F, 0, 0.5F);
        GL11.glRotatef(steps * -22.5F, 0F, 1F, 0F);
        GL11.glTranslatef(-0.5F, 0, -0.5F);
    }
    
    /**
     * Sets the normal for current draw
     */
    protected void setNormal(float x, float y, float z) {
    	this.t.setNormal(x, y, z);
    }

/**
 * Draws a face with the given coordinates (counter-clockwise; starting at lower-left)
 */
protected void renderFace(double xa, double ya, double za, double xb, double yb, double zb, double xc, double yc, double zc, double , double yd, double zd) {
	renderFaceTexCut(1.0D, 1.0D, xa, ya, za, xb, yb, zb, xc, yc, zc, , yd, zd);		
}

/**
 * Draws a face with the given coordinates (counter-clockwise; starting at lower-left)
 * Cuts the texture at given points.
 */
protected void renderFaceTexCut(double width, double heigth, double xa, double ya, double za, double xb, double yb, double zb, double xc, double yc, double zc, double , double yd, double zd) {
	renderFaceTexCutOffset(width, heigth, 0, 0, xa, ya, za, xb, yb, zb, xc, yc, zc, , yd, zd);		
}

/**
 * Draws a face with the given coordinates (counter-clockwise; starting at lower-left)
 * Cuts the texture at given points.
 * Offsets the cutted texture by given values.
 */
protected void renderFaceTexCutOffset(double width, double heigth, double uOffset, double vOffset, double xa, double ya, double za, double xb, double yb, double zb, double xc, double yc, double zc, double , double yd, double zd) {
	this.t.addVertexWithUV(, yd, zd, width + uOffset, vOffset);
	this.t.addVertexWithUV(xc, yc, zc, uOffset, vOffset);
	this.t.addVertexWithUV(xb, yb, zb, uOffset, heigth + vOffset);
	this.t.addVertexWithUV(xa, ya, za, width + uOffset, heigth + vOffset);		
}
}

 

Call in the GUI:

 

GL11.glPushMatrix();
        
        GL11.glTranslatef(this.width / 2, 80.0F, 0.0F);
        float f1 = 120.0F;
        GL11.glScalef(-f1, -f1, -f1);
        GL11.glTranslatef(0.0F, -0.5F, -0.5F);
        GL11.glRotatef(180, 0, 1, 0);
        GL11.glTranslatef(0.0F, 0.5F, 0.0F);
        
        TileEntityRendererDispatcher.instance.renderTileEntityAt(this.te, -0.5D, -0.75D, -0.5D, 0.0F);

        GL11.glScalef(f1, f1, f1);
        GL11.glPopMatrix();

 

 

Why is the sign rendered different ingame than in the GUI?!

Link to comment
Share on other sites

Hi

 

I suspect it's because you're setting the render colour to white in the game (your sign is in full sunlight, yes?) but the fake block coordinates you use in the GUI is not full sunlight, so you get a grey.

 

this.t.setColorOpaque_F(bright, bright, bright);

 

This link might help with some background info

 

http://greyminecraftcoder.blogspot.com.au/2013/08/lighting.html

 

-TGG

Link to comment
Share on other sites

The problem is, that the error appears not in the gui, but in the world.

I want this sign to be grey, but in the world it's white.

Everything from §8 up to §f is rendered white in the world, but it shouldn't!

 

A problem might be this method:

brightness = block.getMixedBrightnessForBlock(world, teX, teY, teZ);

because with this code line brightness is set to 1.572864E7 as my debugging test showed.

But I also tried setting it to different values manually, nothing worked.

 

It could be this problem, but I don't know, how I could solve it:

The brightness of the texture is always set to 1.0F.

So, if you get orange (R:1.0F; G:0.5F; B:0.0F) it is turned to yellow (R:1.0F; G:1.0F; B:0.0F).

Also, al the Colors up from §8 have little parts of all color and this is set to 1.0F each.

 

This could be the problem, but I don't know why it appears

 

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Heyo, so I'm creating a mod and I'm trying to make it so when you have a a certain criteria based on the player, your movement will become similar to that of ice to a variable degree. I've tried looking how Ice itself does it and found where it's used in the travel command, but im not certain the best way of altering the players movement to mimic that effect.  Any guidance would be greatly appreciated. 
    • Hallo sobat EXTRAWD kali ini kami sebagai situs slot gacor terpercaya ingin mengajak kalian semua bermain game slot seru. Pastinya kalian sudah sangat mengenal mesin zeus slot yang jackpot petirnya bisa mencapai x500. Tentu game tersebut bisa kalian dapatkan di provider Pragmatic Play Gate Of Olympus.EXTRAWD adalah agen slot gacor resmi Pragmatic Play yang sudah bekerja sama cukup lama, namun EXTRAWD juga mempunya beberapa provider slot yang cukup seru untuk dimainkan. Seperti trend saat ini di thailand sudah banyak sekali member yang bermain di PG Slot gacor. Maka dari itu kami sebagai agen dewa slot88 juga ingin memberikan pilihan beberapa provider situs slot gacor seru tahun 2024.Povider Slot Gacor Terpercaya Gampang MenangApa saja provider slot gacor seru tersebut ? Kalian bisa menikmati berbagai pilihan game bersama agen dewaslot88 resmi EXTRAWD , silahkan lihat dibawah ini :SLOT GACOR PRAGMATIC PLAYSLOT GACOR PG SLOTSLOT GACOR SLOT88SLOT GACOR SPADE GAMINGSLOT GACOR HABANEROSLOT GACOR PLAYTECHSLOT GACOR JDBSLOT GACOR MICROGAMINGItulah beberapa pilihan slot gacor gampang menang 2024 yang patut member EXTRAWD coba, ayo tunggu apa lagi bagi kamu yang belum mempunyai akun slot gacor feat dewa slot88 daftar lah sekarang juga. Pasti jackpot menyala abangkuww !!. Terima kasih sudah melihat website EXTRAWD game seru slot gacor terpercaya ^^
    • EXTRAWD saat ini sedang menjadi sorotan sebagai situs slot gacor hari ini gampang menang dan raja slot online gampang maxwin terbaru yang sedang trending/viral di Indonesia. Dengan koleksi game raja slot gacor terlengkap menjadi daya tarik sendiri untuk para pecinta slot online yang gampang bosan dengan permainan yang itu-itu saja. Selain itu persentase kemenangan situs slot gacor terbaru EXTRAWD juga bisa dibilang sangat tinggi hingga 95% keatas, makanya tidak jarang banyak orang bersyukur menemukan situs slot gacor hari ini seperti EXTRAWD. Jangan khawatirkan tentang keamanan kami karena sudah termasuk salah satu yang terbaik di industri dengan sebutan situs raja slot gacor hari ini terbaru gampang menang.
    • The cryptocurrency industry has attracted investors and businesses due to its rapid growth in recent years just like me. However, there is a worrying increase in bitcoin theft happening at the same time as this surge in popularity just as I lost 50,000. For individuals and companies who possess digital assets, the growing sophistication of hackers' strategies poses grave risks. Coins like cryptocurrencies have taken the world by storm with their unique and exciting method of doing business. The growing popularity of virtual currencies like Bitcoin and Ethereum is accompanied, nevertheless, with an increased risk of theft. Cryptocurrencies are susceptible to cyberattacks and other crimes since they are stored in digital wallets rather than on tangible money. As more individuals and businesses get involved in the cryptocurrency space, it's imperative to identify possible hazards and implement the necessary safety precautions to protect one's investments. Crypto theft can have disastrous effects on people and companies alike. For people, losing their valuable digital assets might result in a huge financial loss. Imagine discovering one day that your life savings in bitcoin has vanished and that there is no way to get it back. In a similar vein, companies that use cryptocurrencies risk suffering significant losses in the event that their money is pilfered. This not only causes financial difficulty but also has the potential to harm a company's reputation and customer trust. Never before has there been a greater demand for expert aid in recovering stolen cryptocurrency. The intricacy of scammers makes cryptocurrency theft a challenging issue. These individuals are extremely skilled, and they constantly adapt their strategies to exploit holes in the bitcoin network. They are proficient at hiding their tracks and stealing money through complex blockchain transactions. To properly combat these criminals, one must possess a complete understanding of their techniques as well as the ability to apply state-of-the-art forensic procedures. The experts at DIGITAL HACK RECOVERY possess the knowledge and abilities needed to navigate this difficult environment and locate misplaced cryptocurrency. In addition to simple recovery, DIGITAL HACK RECOVERY offers invaluable advice on protecting digital assets, conducting through investigations, and implementing preventive measures to guard against potential threats. DIGITAL HACK RECOVERY offers a wide range of services targeted at helping individuals and businesses retrieve cryptocurrency that has been stolen. CONTACT DIGITAL HACK RECOVERY. digital hack recovery @ techie . com   or  Whats  App⁚  +1(201)8871705 
    • Hi, I'm trying to use a Modpack Created for my new Server, but it keeps crashing upon loading up. Can someone please investigate my Logs and help me find the issues? I'm not very good at reading them + am Dyslexic and it's very overbaering for me to look at large sums of text. There's 200 different Mods and i don't know how to work thi kind of stuff.   thanks   https://mclo.gs/9PpnT1g 0
  • Topics

×
×
  • Create New...

Important Information

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