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
merged 3 commits into from Feb 4, 2018

Conversation

Projects
None yet
2 participants
@XuZhen86
Contributor

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

Fix incomplete support of starvation damage
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)) {

This comment has been minimized.

@mastercoms

mastercoms Feb 1, 2018

Member

Use a switch statement.

This comment has been minimized.

@XuZhen86

XuZhen86 Feb 1, 2018

Contributor

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

This comment has been minimized.

@mastercoms

mastercoms Feb 1, 2018

Member

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

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

This comment has been minimized.

@mastercoms

mastercoms Feb 1, 2018

Member

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

This comment has been minimized.

@XuZhen86

XuZhen86 Feb 1, 2018

Contributor

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.
        }
        }

This comment has been minimized.

@mastercoms

mastercoms Feb 1, 2018

Member

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

ci/circleci: build Your tests passed on CircleCI!
Details
license/cla Contributor License Agreement is signed.
Details

@mastercoms mastercoms changed the title from Fix incomplete support of starvation damage to Implement difficulties for starvation damage Feb 4, 2018

XuZhen86 added a commit to Glowminers/Glowstone that referenced this pull request Feb 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment