Jump to content

[1.14][SOLVED] Can't change TileEntity name color


Recommended Posts

Posted (edited)

I'm trying to change the displayed name color of a tile entity. By default the game renders it in dark gray, as you can see in the image, but i want it to be white. Since in the ```GameRenderer.drawNameplate``` method appearently you can't pass the color as argument, i've tried to override the internal method in the tile entity code instead, by doing this
 

package com.antiblaze.entities.renderers;

        import com.antiblaze.entities.tileentity.AntiBedrockTileEntity;
import com.antiblaze.settings.Settings;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

/**
 * AntiBedrock TileEntity Renderer
 */
@OnlyIn(Dist.CLIENT)
public class AntiBedrockTileEntityRenderer extends TileEntityRenderer<AntiBedrockTileEntity> {

    /**
     * Render the Tile Entity
     * @param tileEntityIn AntiBedrock Tile Entity
     * @param x TileEntity X Position
     * @param y TileEntity Y Position
     * @param z TileEntity Z Position
     * @param partialTicks TileEntity Partial Ticks
     * @param destroyStage TileEntity Destroy Stages
     */
    public void render(AntiBedrockTileEntity tileEntityIn, double x, double y, double z, float partialTicks, int destroyStage) {
        if(tileEntityIn.getDonator() != null) {
            ActiveRenderInfo activerenderinfo = this.rendererDispatcher.renderInfo;
            double d0 = tileEntityIn.getDistanceSq(activerenderinfo.getProjectedView().x, activerenderinfo.getProjectedView().y, activerenderinfo.getProjectedView().z);
            if (!(d0 > (double)(Settings.BEDROCK_NAME_RANGE.get() * Settings.BEDROCK_NAME_RANGE.get()))) {
                float f = activerenderinfo.getYaw();
                float f1 = activerenderinfo.getPitch();
                drawNameplate(this.getFontRenderer(), tileEntityIn.getDonator(), (float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F, 0, f, f1, false, 0xFFFFFF);
            }
        }
    }

    public static void drawNameplate(FontRenderer fontRendererIn, String str, float x, float y, float z, int verticalShift, float viewerYaw, float viewerPitch, boolean isSneaking, int color) {
        GlStateManager.pushMatrix();
        GlStateManager.translatef(x, y, z);
        GlStateManager.normal3f(0.0F, 1.0F, 0.0F);
        GlStateManager.rotatef(-viewerYaw, 0.0F, 1.0F, 0.0F);
        GlStateManager.rotatef(viewerPitch, 1.0F, 0.0F, 0.0F);
        GlStateManager.scalef(-0.025F, -0.025F, 0.025F);
        GlStateManager.disableLighting();
        GlStateManager.depthMask(false);
        if (!isSneaking) {
            GlStateManager.disableDepthTest();
        }

        GlStateManager.enableBlend();
        GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
        int i = fontRendererIn.getStringWidth(str) / 2;
        GlStateManager.disableTexture();
        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder bufferbuilder = tessellator.getBuffer();
        bufferbuilder.begin(7, DefaultVertexFormats.POSITION_COLOR);
        float f = Minecraft.getInstance().gameSettings.func_216840_a(0.25F);
        bufferbuilder.pos((double)(-i - 1), (double)(-1 + verticalShift), 0.0D).color(0.0F, 0.0F, 0.0F, f).endVertex();
        bufferbuilder.pos((double)(-i - 1), (double)(8 + verticalShift), 0.0D).color(0.0F, 0.0F, 0.0F, f).endVertex();
        bufferbuilder.pos((double)(i + 1), (double)(8 + verticalShift), 0.0D).color(0.0F, 0.0F, 0.0F, f).endVertex();
        bufferbuilder.pos((double)(i + 1), (double)(-1 + verticalShift), 0.0D).color(0.0F, 0.0F, 0.0F, f).endVertex();
        tessellator.draw();
        GlStateManager.enableTexture();
        if (!isSneaking) {
            fontRendererIn.drawString(str, (float)(-fontRendererIn.getStringWidth(str) / 2), (float)verticalShift, color);
            GlStateManager.enableDepthTest();
        }

        GlStateManager.depthMask(true);
        fontRendererIn.drawString(str, (float)(-fontRendererIn.getStringWidth(str) / 2), (float)verticalShift, isSneaking ? color : -1);
        GlStateManager.enableLighting();
        GlStateManager.disableBlend();
        GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.popMatrix();
    }
}

 

But the nameplate still draws as before

 

https://imgur.com/t778Q0F

 

So how can i change this color to be whatever color i want?

EDIT: Solved by implementing the INameable interface in the tile entity

Edited by JimiIT92
Solved

Don't blame me if i always ask for your help. I just want to learn to be better :)

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.