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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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