Fabric API

Fabric API

112M Downloads

Render string from 3d world space to screen view

Pseudow opened this issue ยท 2 comments

commented

Hi I am currently trying to render a String in the world position to the player's view. I have done that for now:

@Override
    public void onHudRender(DrawContext drawContext, float tickDelta) {
        this.loadEntity();

        if(this.entity == null || this.player == null)
            return;

        final Vec3d entityPosition = new Vec3d(8.5, -60, -5);
        final Vec3d cameraPosition = MinecraftClient.getInstance().cameraEntity.getPos();
        final Vec3d matrixPosition = entityPosition.subtract(cameraPosition);
        final MatrixStack matrixStack = drawContext.getMatrices();

        matrixStack.push();
        matrixStack.translate(matrixPosition.getX(),
                matrixPosition.getY(), matrixPosition.getZ());
        
        drawContext.drawText(MinecraftClient.getInstance().textRenderer, "Test", 0, 1, 0xffff80, true);

        matrixStack.pop();
    }

but it seems that translating the player local view world isn't following some proportions
2023-06-10_17 53 02

commented

This question is better suited for the official Discord.

commented

๐Ÿ‘‹ We use the issue tracker exclusively for final bug reports and feature requests. However, this issue appears to be better suited for either a discussion thread, or a message on our discord server. Please post your request on one of these, and the conversation can continue there.