Git Product home page Git Product logo

Comments (6)

samolego avatar samolego commented on August 23, 2024

Well, if I tell the real reason, I was actually not even aware of that formatting. We learn things every day ;) ...

from healthcare.

James103 avatar James103 commented on August 23, 2024

The following is the full body of the function that I have modified to get what I wanted out of the displays:

    public MutableText getHealthbarText(float health, float maxHealth) {
        if(health < 0.0F) {
            health = 0.0F;
        }
        if(maxHealth <= 0.0F) {
            maxHealth = 1.0F;
        }
        if(health > maxHealth) {
            maxHealth = health;
        }

        String first, second;
        if(this.healthbarStyle.equals(HealthbarStyle.SKYBLOCK)) {
            // String.format("%.2f", health) for rounding
            first = String.format("%.2f", health);
            second = String.valueOf((int) Math.ceil(maxHealth));

            // We return it here because of custom formatting
            return new LiteralText(first)
                    .formatted(health > maxHealth / 2 ? Formatting.GREEN : Formatting.YELLOW)
                    .append(new LiteralText("/")
                        .formatted(Formatting.WHITE))
                    .append(new LiteralText(second)
                        .formatted(Formatting.GREEN))
                    .append(new LiteralText(String.valueOf((char) 10084)) // ❤
                            .formatted(Formatting.RED));
        } else if(this.healthbarStyle.equals(HealthbarStyle.NUMBER)) {
            // Number
            // String.format("%.2f", health) for rounding
            first = String.format("%.2f", health);
            second = "/" + String.format("%.2f", maxHealth);
        } else if(this.healthbarStyle.equals(HealthbarStyle.PERCENTAGE)) {
            first = String.format("%.2f", health * 100.0F / maxHealth).concat("%");
            second = "";
        } else {
            int heartCount, fullHearts;
            char full, empty;
            if(this.healthbarStyle.equals(HealthbarStyle.LINES)) {
                heartCount = maxHealth < 20 ? (int) Math.ceil(maxHealth) : 20;

                empty = '|';
                full = '|';
            } else { // Hearts
                // We ceil the number to not show 0 hearts if entity has like 0.2f health
                int length = this.healthbarStyle == HealthbarStyle.CUSTOM ? customLength : 10;
                heartCount = maxHealth < length ? (int) Math.ceil(maxHealth) : length;

                full = (char) (this.healthbarStyle.equals(HealthbarStyle.HEARTS) ? 9829 : this.customFullChar); // ♥ or custom
                empty = (char) (this.healthbarStyle.equals(HealthbarStyle.HEARTS) ? 9825 : this.customEmptyChar); // ♡ or custom
            }

            // Hearts that should be colored red
            fullHearts = (int) Math.ceil(health * heartCount / maxHealth);

            first = new String(new char[fullHearts]).replace('\0', full);
            second = new String(new char[heartCount - fullHearts]).replace('\0', empty);
        }

        return new LiteralText(first)
                .formatted(Formatting.RED) /*health > maxHealth / 3 ? (health > maxHealth * 1.5F ? Formatting.YELLOW : Formatting.GOLD) : */
                .append(new LiteralText(second).formatted(Formatting.GRAY));
    }

from healthcare.

James103 avatar James103 commented on August 23, 2024

Closing as fixed (implemented) in 6689a04.

from healthcare.

samolego avatar samolego commented on August 23, 2024

Yes, release is on the way :). Thanks!

from healthcare.

James103 avatar James103 commented on August 23, 2024

The commit managed to generate an error of the following form:

Upload failed! Status: 400 Error: invalid_input Reason: Error with multipart data: A version with that version_number already exists

See: https://github.com/samolego/HealthCare/runs/2704820180

In other words, have you bumped the version yet?

from healthcare.

samolego avatar samolego commented on August 23, 2024

ohno, forgot to add the file to git :|

from healthcare.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.