Jump to content

[1.8] setAlwaysRenderNameTag, always and other questions


big_red_frog

Recommended Posts

Hi All,

 

After digging around with dataWatcher, I found that most info I wanted was already in there, or could be leveraged for my purposes. I can leverage my new working dataWatcher usage later, but for now I am looking at the nameTag functionality.

 

Specifically I want to render string information above my extended entities.

 

So I can use setAlwaysRenderNameTag( true ) and setCustomNameTag( myString )

 

But unfortunately it only seems to trigger the text string render, when they are pointed at, how do I make the text always render ( at least from a certain range )

 

Secondly, I was hoping for multi line text. I couldn't get away with '\n' it renders as an inline 'lf' character. Any known ways to achieve this?

 

Thanks for the timely help this community always offers up.

 

 

Link to comment
Share on other sites

So in answer to some of my question, I managed to make sense of this thread.

 

http://www.minecraftforge.net/forum/index.php/topic,28027.0.html

 

So I had to add to my entity code

 

    @Override
    @SideOnly(Side.CLIENT)
    public boolean getAlwaysRenderNameTagForRender()
    {
        return getAlwaysRenderNameTag();
    }

 

Anyone know why this function from EntityLivingBase otherwise returns false?

 

Seems odd not to actually use the AlwaysRender parameter as implemented.

 

Still wondering how I can go multiline... :P

Link to comment
Share on other sites

ugh.

 

My cunning plan is falling apart.

 

I use the event CameraSetup to trap when the camera is being configured and change the event yaw and pitch, so I can happily position the camera without teleporting my player viewer. This is something I see people advising against on here regularly ( teleporting to change viewpoint ).

 

OnCameraSetupEvent( CameraSetup event)
...
	event.pitch = firstRobotEntity.entity.cameraVec.pitch;
	event.yaw   = firstRobotEntity.entity.cameraVec.yaw;

 

However, it is clear that the renderer for the nameTag uses the player pitch and yaw rather than the camera pitch and yaw to decide on render plane, so if you are actually looking behind the player you can't see the name tag due to normals, or if your player is looking off at 45 degrees, the nameTag's are very twisted :-(

Link to comment
Share on other sites

Confirmed that the nameTag follows the player entity orientation for render plane :-(

 

So I have had to reintroduce forcing the player rotation to get reliable nameTag rendering.

 

Worse the yaw value for the player entity is 180 degrees offset to the camera yaw.

 

// this is for the player
	event.entity.rotationYaw = ( lookVec.yaw + 180 ) % 360;
	event.entity.rotationPitch = lookVec.pitch; 

// this is for the camera
	event.pitch = lookVec.pitch;
	event.yaw = lookVec.yaw;

 

Meanwhile I have working code. If anyone knows how to get multiline text here, then please flag, though I suspect I need to work out how to override the entire render function :-( Not somewhere I have so far dug, but needs must.

 

 

 

 

Link to comment
Share on other sites

Ended up overriding RenderLivingLabel(...)

 

Could of used drawSplitString(...) from FontRenderer, but I didn't want to use a fixed field width so did something slightly different as below.

 

   /**
     * Modified Renders an entity's name above its head
     */
    @Override
    protected void renderLivingLabel(Entity entity, String nameTag, double entX, double entY, double entZ, int maxDist)
    {
        double d3 = entity.getDistanceSqToEntity(this.renderManager.livingPlayer);
       
        if (d3 <= (double)(maxDist * maxDist))
        {      	
            List<String> strings = Arrays.asList(nameTag.split("\n"));
            Collections.reverse(strings);
            double offsetY = entity.height + 0.5;
            
            for ( String line : strings )
            {
//            	System.out.print( "render:" + line + ":\n");
            	renderText( line, entX, entY + offsetY, entZ );
            	offsetY += 0.3;
            }
        }
    }
    
    private void renderText( String text, double x, double y, double z )
    {
        int result = 0;
    	FontRenderer fontrenderer = this.getFontRendererFromRenderManager();
        float f = 1.6F;
        float f1 = 0.016666668F * f;
        GlStateManager.pushMatrix();
        
        GlStateManager.translate((float)x, (float)y, (float)z);
        GL11.glNormal3f(0.0F, 1.0F, 0.0F);
        GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
        GlStateManager.rotate(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
        GlStateManager.scale(-f1, -f1, f1);
        GlStateManager.disableLighting();
        GlStateManager.depthMask(false);
        GlStateManager.disableDepth();
        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
        Tessellator tessellator = Tessellator.getInstance();
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();

        GlStateManager.disableTexture2D();
        worldrenderer.startDrawingQuads();
        int j = fontrenderer.getStringWidth(text) / 2;
        worldrenderer.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.25F);
        worldrenderer.addVertex((double)(-j - 1), -1.0, 0.0D);
        worldrenderer.addVertex((double)(-j - 1),  8.0, 0.0D);
        worldrenderer.addVertex((double)(j + 1),  8.0, 0.0D);
        worldrenderer.addVertex((double)(j + 1), -1.0, 0.0D);
        tessellator.draw();
        GlStateManager.enableTexture2D();
        fontrenderer.drawString(text, -fontrenderer.getStringWidth(text) / 2, 0, 553648127);
        GlStateManager.enableDepth();
        GlStateManager.depthMask(true);
        fontrenderer.drawString(text, -fontrenderer.getStringWidth(text) / 2, 0, -1);
        GlStateManager.enableLighting();
        GlStateManager.disableBlend();
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.popMatrix();   	
    }

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

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • BD303 merupakan salah satu situs slot mudah scatter paling populer dan digemari oleh kalangan slot online di tahun 2024 mainkan sekarang dengan kesempatan yang mudah menang jackpot jutaan rupiah.
  • Topics

×
×
  • Create New...

Important Information

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