Posted March 27, 201411 yr 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) And here is the same text ingame: 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?! http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
March 27, 201411 yr 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
March 28, 201411 yr Author 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 http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
March 30, 201411 yr Author I looked into TileEntitySignRenderer till i finally found out that I forgot to set the normal. But I really can't understand, why this has such big effect http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
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.