Jump to content

[1.20]How to use Tesselator for line drawing


RerturnZero

Recommended Posts

I intend to generate a hollow square with dimensions of 2x2 at the player's feet, providing a visual range indicator for the player.

However, it is not working in the game. The code is shown below.

private Tesselator tesselator = new Tesselator();
    private boolean isBuildLine = true; 
    @SubscribeEvent
    public void drawRectangle(TickEvent.PlayerTickEvent event) {
        LocalPlayer player = Minecraft.getInstance().player;
        LevelRenderer levelRenderer = Minecraft.getInstance().levelRenderer;
        if (player != null && isBuildLine) {
            isBuildLine = false;
            BufferBuilder builder = tesselator.getBuilder();
            builder.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR);

            // Calculated position
            double playerX = player.getX();
            double playerY = player.getY();
            double playerZ = player.getZ();
            double footY = playerY - player.getEyeHeight();

            builder.vertex(playerX - 1, footY, playerZ - 1).color(216, 59, 1, 0).endVertex();
            builder.vertex(playerX + 1, footY, playerZ - 1).color(216, 59, 1, 0).endVertex();

            builder.vertex(playerX + 1, footY, playerZ - 1).color(216, 59, 1, 0).endVertex();
            builder.vertex(playerX + 1, footY, playerZ + 1).color(216, 59, 1, 0).endVertex();

            builder.vertex(playerX + 1, footY, playerZ + 1).color(216, 59, 1, 0).endVertex();
            builder.vertex(playerX - 1, footY, playerZ + 1).color(216, 59, 1, 0).endVertex();

            builder.vertex(playerX - 1, footY, playerZ + 1).color(216, 59, 1, 0).endVertex();
            builder.vertex(playerX - 1, footY, playerZ - 1).color(216, 59, 1, 0).endVertex();


            tesselator.end();
            isBuildLine = true;
        }
    }


 

Edited by RerturnZero
Link to comment
Share on other sites

  • RerturnZero changed the title to [1.20]How to use Tesselator for line drawing
  • 4 months later...

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.



×
×
  • Create New...

Important Information

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