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

    • 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.