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

HealthTags improvements #801

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

ThisTestUser
Copy link
Contributor

@ThisTestUser ThisTestUser commented Mar 17, 2023

-Added an option to display health up to 2 decimal places. This may be useful in some cases.
-Player health colors are now based upon their actual maximum health.
-Added a nametag for display healthtags for mobs. The renderTag() is based upon Minecraft's code to render nametags in renderLabelIfPresent(). I use this method to display item nametags as well as the mob owner (#608).

Note: The hasMobHealthTags() method currently has no use, but if I make a pull request for MobOwner in the future, it will help prevent the tags from colliding with each other.

@Alexander01998 Alexander01998 added type:enhancement New feature or request area:settings Improves the settings of existing features. category:render labels Mar 19, 2023
@Cyclopropinon
Copy link

does it also display max health?

@ThisTestUser
Copy link
Contributor Author

For mobs, always. For players, it is selectable with a checkbox.

@ThisTestUser ThisTestUser mentioned this pull request Jul 1, 2023
@github-actions
Copy link

This pull request has been open for a while with no recent activity. If you're still working on this or waiting for a review, please add a comment or commit within the next 7 days to keep it open. Otherwise, the pull request will be automatically closed to free up time for other tasks.

Pull requests should be closed if:

  • They have been superseded by another pull request
  • They are out of scope or don't align with the project
  • They have become obsolete due to other changes
  • They have bugs or conflicts that won't be resolved

@coderabbitai
Copy link

coderabbitai bot commented Oct 22, 2023

Walkthrough

The recent changes involve enhancements to the HealthTagsHack class in a Minecraft client mod, improving the rendering of health information above entities. The modifications include formatting health values, adjusting rendering based on entity properties, and adding configuration settings for display precision and conditions. Additionally, support classes like RenderUtils and mixins have been updated to handle new rendering logic and settings. A new RoundingPrecisionSetting class has been introduced to manage numerical precision for health values.

Changes

File Path Change Summary
.../hacks/HealthTagsHack.java
.../util/RenderUtils.java
Enhanced rendering of health tags above mobs with new formatting and settings; updated tag rendering logic, including scale, visibility, and distance-based behavior.
.../mixin/EntityRendererMixin.java Modified method to cast text to MutableText for health addition.
.../settings/RoundingPrecisionSetting.java Introduced a new class for managing rounding precision of decimal numbers.
.../settings/SliderSetting.java Added a ROUNDING_PRECISION constant and updated value display behavior.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Commits Files that changed from the base of the PR and between b1076bd and cda75f9.
Files selected for processing (2)
  • src/main/java/net/wurstclient/hacks/HealthTagsHack.java (1 hunks)
  • src/main/java/net/wurstclient/util/RenderUtils.java (2 hunks)
Additional comments (Suppressed): 7
src/main/java/net/wurstclient/hacks/HealthTagsHack.java (7)
  • 28-30: The HealthTagsHack class now implements the RenderListener interface. This change allows the class to listen and respond to render events. Ensure that the onRender() method is correctly implemented to handle these events.

  • 31-50: New settings have been added to the HealthTagsHack class. These settings allow for more customization of the health tags, such as displaying them for mobs, at unlimited range, showing maximum health for players, and rounding health values. These settings are added to the hack in the constructor.

  • 53-63: The onEnable() and onDisable() methods have been overridden to add and remove the HealthTagsHack class as a RenderListener when the hack is enabled and disabled, respectively. This is a good practice as it ensures that the class only listens to render events when the hack is enabled.

  • 65-84: The onRender() method has been overridden to render the health tags. It checks if the mobs setting is enabled, and if so, it iterates over all entities in the world. If an entity is a MobEntity, it calculates the health and maximum health (either rounded or not, based on the round setting), creates a text tag with these values, and uses the RenderUtils.renderTag() method to render the tag above the entity. The range at which the tags are rendered can be unlimited, based on the unlimitedRange setting. This method is well-structured and makes good use of the new settings.

  • 86-99: The addHealth() method has been updated to accommodate the new settings. It now calculates the health and maximum health (either rounded or not, based on the round setting), and appends these values to the nametag. If the max setting is enabled, it appends both the health and maximum health; otherwise, it only appends the health. The health values are colored based on the getColor() method.

  • 101-113: The getColor() method has been updated to take the health and maximum health as parameters, and it now returns a color based on the percentage of health remaining, rather than fixed thresholds. This is a more flexible approach and allows for more accurate color representation of health.

  • 115-118: A new method hasMobHealthTags() has been added to check if the hack is enabled and if the mobs setting is checked. This method can be useful in other parts of the code to check if mob health tags should be displayed.

src/main/java/net/wurstclient/util/RenderUtils.java Outdated Show resolved Hide resolved
Copy link

This pull request has been open for a while with no recent activity. If you're still working on this or waiting for a review, please add a comment or commit within the next 7 days to keep it open. Otherwise, the pull request will be automatically closed to free up time for other tasks.

Pull requests should be closed if:

  • They have been superseded by another pull request
  • They are out of scope or don't align with the project
  • They have become obsolete due to other changes
  • They have bugs or conflicts that won't be resolved

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between cda75f9 and c1d374b.
Files selected for processing (2)
  • src/main/java/net/wurstclient/hacks/HealthTagsHack.java (1 hunks)
  • src/main/java/net/wurstclient/util/RenderUtils.java (2 hunks)
Additional comments: 10
src/main/java/net/wurstclient/hacks/HealthTagsHack.java (8)
  • 10-26: The addition of new import statements aligns with the new features and methods described in the summary. Ensure that these imports are used within the file and are not unnecessarily increasing the compilation time or memory footprint.

  • 29-29: The HealthTagsHack class now implements RenderListener. This change is consistent with the summary stating that event handling methods for rendering have been added.

  • 31-43: The new settings added to the HealthTagsHack class are consistent with the PR objectives to allow more control over the display of health tags. Ensure that these settings are properly integrated into the UI and saved/loaded as part of the user's preferences.

  • 55-64: The onEnable and onDisable methods correctly manage the addition and removal of this class as a RenderListener. This is necessary for the proper functioning of the event-driven rendering logic.

  • 68-95: The onRender method has been modified to render health tags above mobs. The logic checks if the mobs setting is enabled and uses the RenderUtils.renderTag method to draw the tags. Ensure that the rendering respects the game's performance and does not introduce any visual glitches or lag.

  • 98-115: The addHealth method has been updated to format health information and append it to the entity's name tag. The use of DecimalFormat and the round setting to control the display format is consistent with the PR objectives. Ensure that the health information is displayed correctly and is readable in the game's UI.

  • 118-129: The getColor method's logic for determining the color of health tags based on the health percentage is straightforward and follows a clear pattern. This should make it easy for players to quickly assess health levels.

  • 132-135: The hasMobHealthTags method provides a way to check if mob health tags are enabled. This could be useful for avoiding tag collisions in the future, as mentioned in the PR objectives.

src/main/java/net/wurstclient/util/RenderUtils.java (2)
  • 17-35: The changes in import statements reflect the new functionality added to the RenderUtils class. Removed imports suggest a refactoring or removal of methods that used them. Ensure that the removed imports do not affect other methods in the class.

  • 897-942: The new renderTag method is added to handle rendering tags for entities. It includes logic for calculating the distance to the camera and scaling the tag based on that distance. The method also respects the NameTagsHack settings, which is consistent with the PR objectives. Ensure that the method is called in the right context and that the tags are rendered correctly in the game.

Also reverts the non-standard 75 block range back to 64.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c1d374b and 5a9db98.
Files selected for processing (2)
  • src/main/java/net/wurstclient/hacks/HealthTagsHack.java (1 hunks)
  • src/main/java/net/wurstclient/util/RenderUtils.java (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/main/java/net/wurstclient/hacks/HealthTagsHack.java
  • src/main/java/net/wurstclient/util/RenderUtils.java

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5a9db98 and 684692f.
Files selected for processing (4)
  • src/main/java/net/wurstclient/hacks/HealthTagsHack.java (1 hunks)
  • src/main/java/net/wurstclient/mixin/EntityRendererMixin.java (2 hunks)
  • src/main/java/net/wurstclient/settings/RoundingPrecisionSetting.java (1 hunks)
  • src/main/java/net/wurstclient/settings/SliderSetting.java (1 hunks)
Additional comments: 4
src/main/java/net/wurstclient/hacks/HealthTagsHack.java (2)
  • 28-121: The implementation of the HealthTagsHack class with the new settings and RenderListener interface is correct. The onRender method properly checks the mobs setting before rendering tags. The addHealth method uses the precision setting to format health values. The getColor method now calculates color based on health percentage. Ensure that the precision setting is properly initialized and that its value is within the expected range to prevent any runtime exceptions.

  • 118-121: The hasMobHealthTags method is a straightforward check that combines the enabled state of the hack with the mobs setting. This method is correctly implemented and follows best practices.

src/main/java/net/wurstclient/mixin/EntityRendererMixin.java (1)
  • 45-48: The change to cast text to MutableText in the onRenderLabelIfPresent method is correct and necessary for the addHealth method to work with mutable text. This change aligns with the modifications in the HealthTagsHack class.
src/main/java/net/wurstclient/settings/SliderSetting.java (1)
  • 326-327: The addition of the ROUNDING_PRECISION constant in the SliderSetting class is correct and follows the established pattern for ValueDisplay constants. This constant will allow for a display behavior that shows the number of decimal places based on the slider's value.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 684692f and 8c90791.
Files selected for processing (1)
  • src/main/java/net/wurstclient/settings/RoundingPrecisionSetting.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/main/java/net/wurstclient/settings/RoundingPrecisionSetting.java

I'd prefer to add it back later when/if that other PR is merged.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8c90791 and 5cb8d27.
Files selected for processing (2)
  • src/main/java/net/wurstclient/hacks/HealthTagsHack.java (1 hunks)
  • src/main/java/net/wurstclient/util/RenderUtils.java (2 hunks)
Additional comments: 7
src/main/java/net/wurstclient/hacks/HealthTagsHack.java (6)
  • 10-25: Added multiple imports to support the new features and changes in the HealthTagsHack class. Ensure that all these imports are used within the class and there are no unused imports, which can lead to unnecessary dependencies.

  • 28-40: The class now implements RenderListener and has added settings for displaying health tags on mobs, showing maximum health, and setting rounding precision. Verify that the default values for these settings align with the intended functionality and user experience.

  • 51-60: The onEnable and onDisable methods correctly manage the addition and removal of this class as a RenderListener. This is a good practice to ensure that the class only listens for render events when it is enabled, which can help with performance.

  • 63-83: The onRender method now includes logic to render health tags for mob entities. Ensure that the rendering logic is optimized and does not cause performance issues, especially when there are many entities on screen. Also, verify that the color and scale of the tags are appropriate and consistent with the game's UI standards.

  • 85-101: The addHealth method now uses float values for health and max health, with updated formatting and color logic. Ensure that the rounding precision setting is working as expected and that the color logic accurately reflects the health status according to the game's design. Additionally, verify that the method handles entities without a custom name correctly, appending a space only when necessary.

  • 104-115: The getColor method has been updated to determine the color formatting based on the entity's current health relative to its max health. Verify that the thresholds for color changes (25%, 50%, 75%) are consistent with the game's design and that the colors used (DARK_RED, GOLD, YELLOW, GREEN) provide clear and intuitive visual cues for the player.

src/main/java/net/wurstclient/util/RenderUtils.java (1)
  • 896-941: The new renderTag method should be checked for:
  • Correct usage of the matrixStack and proper push/pop encapsulation to avoid affecting the matrix stack elsewhere.
  • Proper handling of the partialTicks for smooth rendering.
  • Correct calculation of scale based on distance, ensuring it doesn't get too large or too small.
  • Appropriate use of TextRenderer and TextLayerType for drawing text with background and see-through layers.
  • Ensuring that the magic number 15728880 used for light is appropriate or if it should be replaced with a named constant for clarity.
  • Confirming that the visibility check (dist > 4096) aligns with the game's rendering distance settings and nameTags.isUnlimitedRange() logic.
Verification successful

The search for the magic number 15728880 within the src/main/java/net/wurstclient/util/ directory confirms that this number is used exclusively in the renderTag method of the RenderUtils.java file. It appears twice, once for each text layer type: NORMAL and SEE_THROUGH. Since there are no other occurrences or named constants for this value, it suggests that this number is specific to the rendering context within this method.

Given that the number is used in a specific rendering context and is not referenced elsewhere, it may be acceptable to use it as a literal if it represents a standard value for lighting in Minecraft's rendering system. However, if this value has a broader significance or is subject to change, it would be best practice to define it as a named constant for clarity and maintainability.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the magic number for light is standard or if it should be replaced with a named constant.
rg --type java '15728880' src/main/java/net/wurstclient/util/

Length of output: 255

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5cb8d27 and ed1cb1f.
Files selected for processing (1)
  • src/main/java/net/wurstclient/settings/RoundingPrecisionSetting.java (1 hunks)
Additional comments: 3
src/main/java/net/wurstclient/settings/RoundingPrecisionSetting.java (3)
  • 21-29: The addition of a check to ensure min is non-negative in the constructor is a good safeguard against potential ArrayIndexOutOfBoundsException.

  • 34-47: The getFormat method correctly initializes DecimalFormat instances on demand using lazy initialization, and the constructor's bounds check for min ensures that array access is safe.

  • 50-53: The format method is straightforward and correctly delegates to getFormat for formatting the value.

Copy link

github-actions bot commented Mar 4, 2024

This pull request has been open for a while with no recent activity. If you're still working on this or waiting for a review, please add a comment or commit within the next 7 days to keep it open. Otherwise, the pull request will be automatically closed to free up time for other tasks.

Pull requests should be closed if:

  • They have been superseded by another pull request
  • They are out of scope or don't align with the project
  • They have become obsolete due to other changes
  • They have bugs or conflicts that won't be resolved

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ed1cb1f and 31022d1.
Files selected for processing (1)
  • src/main/java/net/wurstclient/hacks/HealthTagsHack.java (1 hunks)
Additional comments: 1
src/main/java/net/wurstclient/hacks/HealthTagsHack.java (1)
  • 85-101: The addHealth method introduces decimal precision and color-based health representation, fulfilling the PR objectives. The use of the precision setting to format health values and the conditional logic for displaying maximum health are well-implemented. However, ensure that the getColor method, which determines the color based on health, is robust against edge cases, such as when maxHealth is zero, to prevent division by zero errors or misleading color representations.

Ensure the getColor method handles edge cases, such as zero maxHealth, appropriately.

Comment on lines +64 to +83
public void onRender(MatrixStack matrixStack, float partialTicks)
{
if(!mobs.isChecked())
return;

VertexConsumerProvider.Immediate immediate = VertexConsumerProvider
.immediate(Tessellator.getInstance().getBuffer());

for(Entity e : MC.world.getEntities())
{
if(!(e instanceof MobEntity entity))
continue;

Text text = addHealth(entity, Text.literal(""));
RenderUtils.renderTag(matrixStack, text, entity, immediate,
0xffffff, !entity.hasCustomName() ? 0.5 : 1, partialTicks);
}

immediate.draw();
}
Copy link

Choose a reason for hiding this comment

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

The onRender method effectively renders health tags for mobs when the mobs setting is enabled. This implementation aligns with the PR objectives and leverages Minecraft's rendering system efficiently. However, there's a potential performance concern with iterating over all entities in the world (MC.world.getEntities()) every render tick. Consider filtering entities more efficiently, possibly by maintaining a list of entities within a certain distance from the player, to reduce the computational overhead.

Consider optimizing the entity iteration process to improve performance, especially in worlds with a large number of entities.

@Alexander01998 Alexander01998 added the status:never-stale Prevents stalebot from marking this item as stale. label Apr 4, 2024
Alexander01998 added a commit that referenced this pull request Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:settings Improves the settings of existing features. category:render status:never-stale Prevents stalebot from marking this item as stale. type:enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants