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

Implement difficulties for starvation damage #835

Merged

Conversation

@XuZhen86
Copy link
Contributor

@XuZhen86 XuZhen86 commented Feb 1, 2018

This pull request tries to fix the bug that starvation damage was not calculated based on world difficulty.

Observed behavior:
Starvation damage is the same across all difficulty level.

Expected behavior:

When the hunger bar is at 0, the player's health will deplete at a rate of 1 every 4 seconds (this makes sleeping impossible). On Easy difficulty, the player's health stops dropping at 10, on Normal it stops at 1, and on Hard it keeps draining until either the player eats something or starves to death. Hunger

The hunger bar never depletes and players cannot eat anything except golden apples and chorus fruits, unless the player has switched to Peaceful when their hunger bar was below the maximum. Additionally, If the hunger bar is below the maximum, it quickly regenerates. Difficulty

1. Fix starvation damage was not calculated based on world difficulty.
if (foodLevel == 0 && getHealth() > 1 && ticksLived % 80 == 0) {
damage(1, DamageCause.STARVATION);
// Process food level and starvation based on difficulty.
if (world.getDifficulty().equals(Difficulty.PEACEFUL)) {
Copy link
Member

@mastercoms mastercoms Feb 1, 2018

Use a switch statement.

Copy link
Contributor Author

@XuZhen86 XuZhen86 Feb 1, 2018

In the default part of the switch, should I leave it blank or put something?

Copy link
Member

@mastercoms mastercoms Feb 1, 2018

Yes, just add a comment that says // do nothing or something similar.

break;
}
default: {
// Do nothing when there're other game difficulties.
Copy link
Member

@mastercoms mastercoms Feb 1, 2018

I would prefer if you didn't use a contraction here.

Copy link
Contributor Author

@XuZhen86 XuZhen86 Feb 1, 2018

You mean like this?

        // Process food level and starvation based on difficulty.
        switch (world.getDifficulty()) {
        case PEACEFUL: {
            if (foodLevel < 20 && ticksLived % 20 == 0) {
                foodLevel++;
            }
            break;
        }
        case EASY: {
            if (foodLevel == 0 && getHealth() > 10 && ticksLived % 80 == 0) {
                damage(1, DamageCause.STARVATION);
            }
            break;
        }
        case NORMAL: {
            if (foodLevel == 0 && getHealth() > 1 && ticksLived % 80 == 0) {
                damage(1, DamageCause.STARVATION);
            }
            break;
        }
        case HARD: {
            if (foodLevel == 0 && ticksLived % 80 == 0) {
                damage(1, DamageCause.STARVATION);
            }
            break;
        }
        default: {
            // Do nothing when there're other game difficulties.
        }
        }

Copy link
Member

@mastercoms mastercoms Feb 1, 2018

No I meant just use there are instead of there're

@mastercoms mastercoms merged commit 8707480 into GlowstoneMC:dev Feb 4, 2018
2 checks passed
@mastercoms mastercoms changed the title Fix incomplete support of starvation damage Implement difficulties for starvation damage Feb 4, 2018
XuZhen86 added a commit to Glowminers/Glowstone that referenced this issue Feb 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants