Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Hud page #281

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Update Hud page #281

wants to merge 3 commits into from

Conversation

kevinthegreat1
Copy link
Contributor

No description provided.

@kevinthegreat1 kevinthegreat1 requested a review from a team as a code owner February 12, 2025 14:29
Copy link

netlify bot commented Feb 12, 2025

Deploy Preview for nimble-elf-d9d491 ready!

Name Link
🔨 Latest commit 13f88ab
🔍 Latest deploy log https://app.netlify.com/sites/nimble-elf-d9d491/deploys/67acc2e14f619f000857a918
😎 Deploy Preview https://deploy-preview-281--nimble-elf-d9d491.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@its-miroma its-miroma added correction Something isn't right on a page stage:verification This should be verified labels Feb 12, 2025
Copy link
Member

@modmuss50 modmuss50 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nit picks, the new api is a little more complex for people to understand so I think we need to explain it a bit more to compensate.


The `HudRenderCallback` event - provided by Fabric API - is called every frame, and is used to render things to the HUD.
::: warning
Previously, Fabric provided `HudRenderCallback` to render to the hud. Due to changes to hud rendering, this event became extremely limited and is deprecated since Fabric API 0.116. Usage is strongly discouraged. Deprecated events may be removed in the future.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Previously, Fabric provided `HudRenderCallback` to render to the hud. Due to changes to hud rendering, this event became extremely limited and is deprecated since Fabric API 0.116. Usage is strongly discouraged. Deprecated events may be removed in the future.
Previously, Fabric provided `HudRenderCallback` to render to the hud. Due to changes to hud rendering, this event became extremely limited and is deprecated since Fabric API 0.116. Usage is strongly discouraged.

I dont think you need to mention this, we tend to only remove deprecated APIs when they break becuase of a Mojang change, I expect the old event will be around for a good while longer.


You should check out the [Draw Context](./draw-context) page to learn more about the draw context.
To start, we need to register a listener to `HudLayerRegistrationCallback` which registers your layers. Each layer takes a `DrawContext` and a `RenderTickCounter` instance as parameters. See the `HudLayerRegistrationCallback` and related Javadocs for more details on how to use the API.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each layer takes a DrawContext and a RenderTickCounter instance as parameters.

This doesnt really tell the full picture, maybe its worth expanding a bit on this and saying that a layer is a IdentifiedLayer that takes a Layer, that is often a lamabda that takes those 2 params?


public class HudRenderingEntrypoint implements ClientModInitializer {
@Override
public void onInitializeClient() {
// :::1
HudRenderCallback.EVENT.register((context, renderTickCounter) -> {
// Attach our rendering code to before the chat hud layer. Our layer will render right before the chat. The API will take care of z spacing and automatically add 200 after every layer.
HudLayerRegistrationCallback.EVENT.register(layeredDrawer -> layeredDrawer.attachLayerBefore(IdentifiedLayer.CHAT, Identifier.of(FabricDocsReference.MOD_ID, "hud-example-layer"), (context, tickCounter) -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Id maybe split this into multiple lines, and possibly move the layer code out into a method.

E.g

public static final Identifier HUD_LAYER = Identifier.of(FabricDocsReference.MOD_ID, "hud-example-layer");
HudLayerRegistrationCallback.EVENT.register(layeredDrawer -> {
  layeredDrawer.attachLayerBefore(IdentifiedLayer.CHAT, HUD_LAYER, this::render);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
correction Something isn't right on a page stage:verification This should be verified
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants